Skip to content

Commit df9e6e5

Browse files
committed
feat: update execute function to handle unsupported chains and refactor query calls in preview tables
1 parent b3a23ab commit df9e6e5

File tree

6 files changed

+36
-7
lines changed

6 files changed

+36
-7
lines changed

src/graphql/execute.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
import { SUPPORTED_CHAINS } from '@/config';
12
import type { TypedDocumentString } from './graphql'
2-
3+
34
export async function execute<TResult, TVariables>(
5+
chainId: number | undefined,
46
query: TypedDocumentString<TResult, TVariables>,
57
...[variables]: TVariables extends Record<string, never> ? [] : [TVariables]
68
) {
7-
const subgraphUrl = import.meta.env.VITE_POCO_SUBGRAPH_URL;
9+
const chain = SUPPORTED_CHAINS.find((c) => c.id === chainId);
10+
11+
if (!chain) {
12+
throw new Error(`Unsupported chain with id ${chainId}`);
13+
}
14+
15+
const subgraphUrl = chain.subgraphUrl;
816

917
const response = await fetch(subgraphUrl, {
1018
method: 'POST',

src/modules/apps/AppsPreviewTable.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ import {
1515
TableHeader,
1616
TableRow,
1717
} from '@/components/ui/table';
18+
import useUserStore from '@/stores/useUser.store';
1819
import { formatElapsedTime } from '@/utils/formatElapsedTime';
1920
import { truncateAddress } from '@/utils/truncateAddress';
2021
import { appsQuery } from './appsQuery';
2122

2223
export function AppsPreviewTable({ className }: { className?: string }) {
24+
const { chainId } = useUserStore();
25+
2326
const apps = useQuery({
2427
queryKey: ['apps_preview'],
2528
queryFn: () =>
26-
execute(appsQuery, { length: PREVIEW_TABLE_LENGTH, skip: 0 }),
29+
execute(chainId, appsQuery, { length: PREVIEW_TABLE_LENGTH, skip: 0 }),
2730
refetchInterval: PREVIEW_TABLE_REFETCH_INTERVAL,
2831
});
2932

src/modules/datasets/DatasetsPreviewTable.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ import {
1515
TableHeader,
1616
TableRow,
1717
} from '@/components/ui/table';
18+
import useUserStore from '@/stores/useUser.store';
1819
import { formatElapsedTime } from '@/utils/formatElapsedTime';
1920
import { truncateAddress } from '@/utils/truncateAddress';
2021
import { datasetsQuery } from './datasetsQuery';
2122

2223
export function DatasetsPreviewTable({ className }: { className?: string }) {
24+
const { chainId } = useUserStore();
25+
2326
const datasets = useQuery({
2427
queryKey: ['datasets_preview'],
2528
queryFn: () =>
26-
execute(datasetsQuery, { length: PREVIEW_TABLE_LENGTH, skip: 0 }),
29+
execute(chainId, datasetsQuery, {
30+
length: PREVIEW_TABLE_LENGTH,
31+
skip: 0,
32+
}),
2733
refetchInterval: PREVIEW_TABLE_REFETCH_INTERVAL,
2834
});
2935

src/modules/deals/DealsPreviewTable.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ import {
1515
TableHeader,
1616
TableRow,
1717
} from '@/components/ui/table';
18+
import useUserStore from '@/stores/useUser.store';
1819
import { formatElapsedTime } from '@/utils/formatElapsedTime';
1920
import { truncateAddress } from '@/utils/truncateAddress';
2021
import { SuccessCell } from './SuccessCell';
2122
import { dealsQuery } from './dealsQuery';
2223

2324
export function DealsPreviewTable({ className }: { className?: string }) {
25+
const { chainId } = useUserStore();
26+
2427
const deals = useQuery({
2528
queryKey: ['deals_preview'],
2629
queryFn: () =>
27-
execute(dealsQuery, { length: PREVIEW_TABLE_LENGTH, skip: 0 }),
30+
execute(chainId, dealsQuery, { length: PREVIEW_TABLE_LENGTH, skip: 0 }),
2831
refetchInterval: PREVIEW_TABLE_REFETCH_INTERVAL,
2932
});
3033

src/modules/tasks/TasksPreviewTable.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ import {
1515
TableHeader,
1616
TableRow,
1717
} from '@/components/ui/table';
18+
import useUserStore from '@/stores/useUser.store';
1819
import { truncateAddress } from '@/utils/truncateAddress';
1920
import StatusCell from './StatusCell';
2021
import { taskQuery } from './tasksQuery';
2122

2223
export function TasksPreviewTable({ className }: { className?: string }) {
24+
const { chainId } = useUserStore();
25+
2326
const tasks = useQuery({
2427
queryKey: ['tasks_preview'],
2528
queryFn: () =>
26-
execute(taskQuery, { length: PREVIEW_TABLE_LENGTH, skip: 0 }),
29+
execute(chainId, taskQuery, { length: PREVIEW_TABLE_LENGTH, skip: 0 }),
2730
refetchInterval: PREVIEW_TABLE_REFETCH_INTERVAL,
2831
});
2932

src/modules/workerpools/workerpoolsPreviewTable.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ import {
1515
TableHeader,
1616
TableRow,
1717
} from '@/components/ui/table';
18+
import useUserStore from '@/stores/useUser.store';
1819
import { formatElapsedTime } from '@/utils/formatElapsedTime';
1920
import { truncateAddress } from '@/utils/truncateAddress';
2021
import { workerpoolsQuery } from './workerpoolsQuery';
2122

2223
export function WorkerpoolsPreviewTable({ className }: { className?: string }) {
24+
const { chainId } = useUserStore();
25+
2326
const workerpools = useQuery({
2427
queryKey: ['workerpools_preview'],
2528
queryFn: () =>
26-
execute(workerpoolsQuery, { length: PREVIEW_TABLE_LENGTH, skip: 0 }),
29+
execute(chainId, workerpoolsQuery, {
30+
length: PREVIEW_TABLE_LENGTH,
31+
skip: 0,
32+
}),
2733
refetchInterval: PREVIEW_TABLE_REFETCH_INTERVAL,
2834
});
2935

0 commit comments

Comments
 (0)