Skip to content

Commit 67f28ba

Browse files
authored
Merge pull request #27 from Quantus-Network/feat/website-rebrand
Website rebrand part 2
2 parents f19b6ff + 3552b40 commit 67f28ba

59 files changed

Lines changed: 8835 additions & 6642 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

website/src/api/client.ts

Lines changed: 33 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import NodeCounterService from "./node-counter-service";
21
import type {
3-
NodeCounterListener,
2+
NodeRpcListener,
43
NodeData,
5-
NodeCounterOptions,
6-
NodeCounterState,
7-
} from "./node-counter-service";
4+
NodeRpcOptions,
5+
NodeRpcState,
6+
} from "./node-rpc-service";
87
import env from "@/config";
8+
import NodeRpcService from "./node-rpc-service";
9+
import type { EthereumAddressData } from "@/interfaces/EthereumSecurity";
910

1011
// Types for API responses
1112
interface ChainStatsData {
@@ -68,111 +69,22 @@ export interface RaidLeaderboardEntrant {
6869
last_activity: string;
6970
}
7071

71-
interface LeaderboardOptions {
72-
page?: number;
73-
pageSize?: number;
74-
filterByReferralCode?: string;
75-
}
76-
77-
export interface LeaderboardResponse {
78-
data: LeaderboardEntrant[];
79-
meta: {
80-
page: number;
81-
page_size: number;
82-
total_items: number;
83-
total_pages: number;
84-
};
85-
}
86-
87-
export interface RaidLeaderboardResponse {
88-
data: RaidLeaderboardEntrant[];
89-
meta: {
90-
page: number;
91-
page_size: number;
92-
total_items: number;
93-
total_pages: number;
94-
};
95-
}
96-
9772
type ApiResponse<T = any> = Promise<Response>;
9873

9974
const createApiClient = () => {
100-
const nodeCounter = new NodeCounterService();
75+
const nodeRpc = new NodeRpcService();
10176

10277
const methods = {
103-
fetchRaidLeaderboard: (
104-
options: LeaderboardOptions,
105-
): ApiResponse<RaidLeaderboardResponse> => {
106-
const firstRaid = 1;
107-
let url = `${env.TASK_MASTER_URL}/raid-quests/leaderboards/${firstRaid}`;
108-
109-
let queryParams = [];
110-
if (options.page) queryParams.push(`page=${options.page}`);
111-
if (options.pageSize) queryParams.push(`page_size=${options.pageSize}`);
112-
if (options.filterByReferralCode)
113-
queryParams.push(`referral_code=${options.filterByReferralCode}`);
114-
115-
if (queryParams.length != 0) url = url + "?" + queryParams.join("&");
116-
117-
return fetch(url, {
118-
headers: {
119-
"Content-Type": "application/json",
120-
},
121-
});
122-
},
123-
fetchLeaderboard: (
124-
options: LeaderboardOptions,
125-
): ApiResponse<LeaderboardResponse> => {
126-
let url = `${env.TASK_MASTER_URL}/addresses/leaderboard`;
127-
128-
let queryParams = [];
129-
if (options.page) queryParams.push(`page=${options.page}`);
130-
if (options.pageSize) queryParams.push(`page_size=${options.pageSize}`);
131-
if (options.filterByReferralCode)
132-
queryParams.push(`referral_code=${options.filterByReferralCode}`);
133-
134-
if (queryParams.length != 0) url = url + "?" + queryParams.join("&");
135-
136-
return fetch(url, {
137-
headers: {
138-
"Content-Type": "application/json",
139-
},
140-
});
141-
},
142-
14378
/**
144-
* Fetch blockchain statistics including transaction and account counts
79+
* Get Ethereum security analysis
14580
*/
146-
chainStats: (): ApiResponse<GraphQLResponse<ChainStatsData>> => {
147-
const query = `
148-
query GetStatus {
149-
allTransactions: eventsConnection(
150-
orderBy: id_ASC,
151-
where: {
152-
OR: {
153-
type_in: [TRANSFER, REVERSIBLE_TRANSFER]
154-
}
155-
}
156-
) {
157-
totalCount
158-
}
159-
allAccounts: accountsConnection(
160-
orderBy: id_ASC
161-
) {
162-
totalCount
163-
}
164-
}
165-
`;
166-
167-
return fetch(env.GRAPHQL_URL, {
168-
headers: {
169-
"Content-Type": "application/json",
170-
},
171-
method: "POST",
172-
body: JSON.stringify({
173-
query,
174-
}),
175-
});
81+
getEthereumSecurityAnalysis: async (
82+
addressOrEnsName: string,
83+
): Promise<EthereumAddressData | null> => {
84+
const data = await fetch(
85+
`${env.TASK_MASTER_URL}/risk-checker/${addressOrEnsName}`,
86+
);
87+
return (await data.json())?.data as EthereumAddressData | null;
17688
},
17789

17890
/**
@@ -213,78 +125,53 @@ const createApiClient = () => {
213125
});
214126
},
215127

216-
/**
217-
* Helper method to handle GraphQL responses with proper error checking
218-
*/
219-
async handleGraphQLResponse<T>(response: Response): Promise<T> {
220-
if (!response.ok) {
221-
throw new Error(`HTTP error! status: ${response.status}`);
222-
}
223-
224-
const data: GraphQLResponse<T> = await response.json();
225-
226-
if (data.errors && data.errors.length > 0) {
227-
throw new Error(`GraphQL error: ${data.errors[0].message}`);
228-
}
229-
230-
if (!data.data) {
231-
throw new Error("No data returned from GraphQL query");
232-
}
233-
234-
return data.data;
235-
},
236-
237-
/**
238-
* Convenience method to get chain stats with automatic error handling
239-
*/
240-
async getChainStats(): Promise<ChainStatsData> {
241-
const response = await methods.chainStats();
242-
return methods.handleGraphQLResponse<ChainStatsData>(response);
243-
},
244-
245128
/**
246129
* Node Counter Methods
247130
*/
248-
nodeCounter: {
131+
nodeRpc: {
249132
/**
250-
* Subscribe to node count updates
133+
* Subscribe to node RPC updates
251134
* @param listener Callback function that receives state updates
252135
* @returns Unsubscribe function
253136
*/
254-
subscribe: (listener: NodeCounterListener) =>
255-
nodeCounter.subscribe(listener),
137+
subscribe: (listener: NodeRpcListener) => nodeRpc.subscribe(listener),
256138

257139
/**
258140
* Get current node counter state
259141
*/
260-
getState: () => nodeCounter.getState(),
142+
getState: () => nodeRpc.getState(),
261143

262144
/**
263145
* Start the WebSocket connection to track nodes
264146
*/
265-
connect: () => nodeCounter.connect(),
147+
connect: () => nodeRpc.connect(),
266148

267149
/**
268150
* Disconnect from the node tracking WebSocket
269151
*/
270-
disconnect: () => nodeCounter.disconnect(),
152+
disconnect: () => nodeRpc.disconnect(),
271153

272154
/**
273155
* Check if currently connected
274156
*/
275-
isConnected: () => nodeCounter.isConnected(),
157+
isConnected: () => nodeRpc.isConnected(),
276158

277159
/**
278160
* Get just the current node count (convenience method)
279161
*/
280-
getCount: () => nodeCounter.getState().count,
162+
getCount: () => nodeRpc.getState().count,
163+
164+
/**
165+
* Get the current block height
166+
*/
167+
getBlockHeight: () => nodeRpc.getState().blockHeight,
281168

282169
/**
283170
* Get current connection status
284171
*/
285172
getStatus: () => ({
286-
status: nodeCounter.getState().status,
287-
message: nodeCounter.getState().statusMessage,
173+
status: nodeRpc.getState().status,
174+
message: nodeRpc.getState().statusMessage,
288175
}),
289176
},
290177
};
@@ -302,7 +189,7 @@ export type {
302189
ContactData,
303190
SubscribeData,
304191
NodeData,
305-
NodeCounterState,
306-
NodeCounterOptions,
307-
NodeCounterListener,
192+
NodeRpcState,
193+
NodeRpcOptions,
194+
NodeRpcListener,
308195
};

0 commit comments

Comments
 (0)