Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Commit 40d3969

Browse files
authored
chore: query supported chains from chainsaw (#2620)
1 parent 6a95392 commit 40d3969

File tree

2 files changed

+22
-41
lines changed

2 files changed

+22
-41
lines changed

src/contract-ui/tabs/analytics/page.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import { BarChart } from "components/analytics/bar-chart";
2222
import { ChartContainer } from "components/analytics/chart-container";
2323
import {
2424
AnalyticsQueryParams,
25-
SUPPORTED_ANALYTICS_CHAINS,
2625
TotalQueryResult,
26+
useAnalyticsSupportedChains,
2727
useEventsAnalytics,
2828
useFunctionsAnalytics,
2929
useLogsAnalytics,
@@ -242,6 +242,8 @@ export const AnalyticsChart: React.FC<AnalyticsChartProps> = ({
242242
showXAxis,
243243
showYAxis,
244244
}) => {
245+
const supportedChainsQuery = useAnalyticsSupportedChains();
246+
245247
const analyticsQuery = useAnalytics({
246248
contractAddress,
247249
chainId,
@@ -258,10 +260,12 @@ export const AnalyticsChart: React.FC<AnalyticsChartProps> = ({
258260
}, [analyticsQuery.data]);
259261

260262
if (data.length <= 1) {
263+
const supportedChains = supportedChainsQuery.data ?? [];
264+
261265
return (
262266
<Alert status="info" borderRadius="md" mb={4}>
263267
<AlertIcon />
264-
{SUPPORTED_ANALYTICS_CHAINS.includes(chainId) ? (
268+
{supportedChains.includes(chainId) ? (
265269
<AlertDescription>No recent activity.</AlertDescription>
266270
) : (
267271
<AlertDescription>

src/data/analytics/hooks.ts

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
1-
import { THIRDWEB_ANALYTICS_API_HOSTNAME } from "./constants";
21
import { useQuery } from "@tanstack/react-query";
3-
import {
4-
Arbitrum,
5-
ArbitrumGoerli,
6-
Avalanche,
7-
AvalancheFuji,
8-
Base,
9-
BaseGoerli,
10-
BinanceTestnet,
11-
Ethereum,
12-
Fantom,
13-
Goerli,
14-
Mumbai,
15-
Optimism,
16-
Polygon,
17-
PolygonZkevmTestnet,
18-
ScrollAlphaTestnet,
19-
Sepolia,
20-
} from "@thirdweb-dev/chains";
2+
import { THIRDWEB_ANALYTICS_API_HOSTNAME } from "./constants";
213

224
export type AnalyticsQueryParams = {
235
chainId: number;
@@ -27,26 +9,6 @@ export type AnalyticsQueryParams = {
279
interval?: "minute" | "hour" | "day" | "week" | "month";
2810
};
2911

30-
// TODO: Keep updated with actual ClickHouse data
31-
export const SUPPORTED_ANALYTICS_CHAINS: number[] = [
32-
Ethereum.chainId,
33-
Goerli.chainId,
34-
Optimism.chainId,
35-
BinanceTestnet.chainId,
36-
Polygon.chainId,
37-
Fantom.chainId,
38-
PolygonZkevmTestnet.chainId,
39-
Base.chainId,
40-
Arbitrum.chainId,
41-
AvalancheFuji.chainId,
42-
Avalanche.chainId,
43-
Mumbai.chainId,
44-
BaseGoerli.chainId,
45-
ArbitrumGoerli.chainId,
46-
ScrollAlphaTestnet.chainId,
47-
Sepolia.chainId,
48-
];
49-
5012
async function makeQuery(
5113
path: string,
5214
query: Record<string, string | number | undefined>,
@@ -404,3 +366,18 @@ export function useTotalWalletsAnalytics(params: AnalyticsQueryParams) {
404366
enabled: !!params.contractAddress && !!params.chainId,
405367
});
406368
}
369+
370+
export function useAnalyticsSupportedChains() {
371+
return useQuery(
372+
["analytics-supported-chains"] as const,
373+
async (): Promise<number[]> => {
374+
const res = await makeQuery("/api/v1/supported-chains", {});
375+
if (!res.ok) {
376+
throw new Error(`Unexpected status ${res.status}`);
377+
}
378+
379+
const { results } = await res.json();
380+
return results;
381+
},
382+
);
383+
}

0 commit comments

Comments
 (0)