Skip to content

Commit d956d68

Browse files
committed
feat: integrate subgraph URL management in user store and update query execution across preview tables
1 parent ceef12b commit d956d68

File tree

8 files changed

+49
-9
lines changed

8 files changed

+49
-9
lines changed

src/graphql/execute.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import type { TypedDocumentString } from './graphql'
22

33
export async function execute<TResult, TVariables>(
44
query: TypedDocumentString<TResult, TVariables>,
5+
subgraphUrl: string,
56
...[variables]: TVariables extends Record<string, never> ? [] : [TVariables]
67
) {
7-
const subgraphUrl = import.meta.env.VITE_POCO_SUBGRAPH_URL;
8-
98
const response = await fetch(subgraphUrl, {
109
method: 'POST',
1110
headers: {

src/hooks/useSyncAccountWithUserStore.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1+
import { SUPPORTED_CHAINS } from '@/config';
12
import { useEffect } from 'react';
23
import { useAccount } from 'wagmi';
34
import useUserStore from '@/stores/useUser.store';
45

56
export function useSyncAccountWithUserStore() {
67
const { connector, status, address, chain, isConnected } = useAccount();
7-
const { setConnector, setIsConnected, setAddress, setChainId } =
8-
useUserStore();
8+
const {
9+
setConnector,
10+
setIsConnected,
11+
setAddress,
12+
setChainId,
13+
setSubgraphUrl,
14+
} = useUserStore();
915

1016
useEffect(() => {
1117
// Update userStore
1218
setConnector(connector);
1319
setIsConnected(isConnected);
1420
setAddress(address);
1521
setChainId(chain?.id);
22+
const currentChain = SUPPORTED_CHAINS.find((c) => c.id === chain?.id);
23+
if (currentChain) {
24+
setSubgraphUrl(currentChain?.subgraphUrl);
25+
}
1626
}, [
1727
connector,
1828
status,
@@ -23,5 +33,6 @@ export function useSyncAccountWithUserStore() {
2333
setIsConnected,
2434
setAddress,
2535
setChainId,
36+
setSubgraphUrl,
2637
]);
2738
}

src/modules/apps/AppsPreviewTable.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@ 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 { subgraphUrl } = useUserStore();
2325
const apps = useQuery({
2426
queryKey: ['apps_preview'],
2527
queryFn: () =>
26-
execute(appsQuery, { length: PREVIEW_TABLE_LENGTH, skip: 0 }),
28+
execute(appsQuery, subgraphUrl, {
29+
length: PREVIEW_TABLE_LENGTH,
30+
skip: 0,
31+
}),
2732
refetchInterval: PREVIEW_TABLE_REFETCH_INTERVAL,
2833
});
2934

src/modules/datasets/DatasetsPreviewTable.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@ 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 { subgraphUrl } = useUserStore();
2325
const datasets = useQuery({
2426
queryKey: ['datasets_preview'],
2527
queryFn: () =>
26-
execute(datasetsQuery, { length: PREVIEW_TABLE_LENGTH, skip: 0 }),
28+
execute(datasetsQuery, subgraphUrl, {
29+
length: PREVIEW_TABLE_LENGTH,
30+
skip: 0,
31+
}),
2732
refetchInterval: PREVIEW_TABLE_REFETCH_INTERVAL,
2833
});
2934

src/modules/deals/DealsPreviewTable.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +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 { SuccessCell } from './SuccessCell';
2122
import { dealsQuery } from './dealsQuery';
2223

2324
export function DealsPreviewTable({ className }: { className?: string }) {
25+
const { subgraphUrl } = useUserStore();
2426
const deals = useQuery({
2527
queryKey: ['deals_preview'],
2628
queryFn: () =>
27-
execute(dealsQuery, { length: PREVIEW_TABLE_LENGTH, skip: 0 }),
29+
execute(dealsQuery, subgraphUrl, {
30+
length: PREVIEW_TABLE_LENGTH,
31+
skip: 0,
32+
}),
2833
refetchInterval: PREVIEW_TABLE_REFETCH_INTERVAL,
2934
});
3035

src/modules/tasks/TasksPreviewTable.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@ 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 { subgraphUrl } = useUserStore();
2325
const tasks = useQuery({
2426
queryKey: ['tasks_preview'],
2527
queryFn: () =>
26-
execute(taskQuery, { length: PREVIEW_TABLE_LENGTH, skip: 0 }),
28+
execute(taskQuery, subgraphUrl, {
29+
length: PREVIEW_TABLE_LENGTH,
30+
skip: 0,
31+
}),
2732
refetchInterval: PREVIEW_TABLE_REFETCH_INTERVAL,
2833
});
2934

src/modules/workerpools/workerpoolsPreviewTable.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@ 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 { subgraphUrl } = useUserStore();
2325
const workerpools = useQuery({
2426
queryKey: ['workerpools_preview'],
2527
queryFn: () =>
26-
execute(workerpoolsQuery, { length: PREVIEW_TABLE_LENGTH, skip: 0 }),
28+
execute(workerpoolsQuery, subgraphUrl, {
29+
length: PREVIEW_TABLE_LENGTH,
30+
skip: 0,
31+
}),
2732
refetchInterval: PREVIEW_TABLE_REFETCH_INTERVAL,
2833
});
2934

src/stores/useUser.store.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SUPPORTED_CHAINS } from '@/config';
12
import { Address } from '@/types';
23
import type { Connector } from 'wagmi';
34
import { create } from 'zustand';
@@ -13,6 +14,8 @@ type UserState = {
1314
setAddress: (param: Address | undefined) => void;
1415
chainId: number | undefined;
1516
setChainId: (param: number | undefined) => void;
17+
subgraphUrl: string;
18+
setSubgraphUrl: (param: string) => void;
1619
};
1720

1821
const useUserStore = create<UserState>((set) => ({
@@ -30,6 +33,8 @@ const useUserStore = create<UserState>((set) => ({
3033
setChainId: (chainId: number | undefined) => {
3134
set({ chainId: chainId });
3235
},
36+
subgraphUrl: SUPPORTED_CHAINS[0].subgraphUrl,
37+
setSubgraphUrl: (subgraphUrl: string) => set({ subgraphUrl }),
3338
}));
3439

3540
export default useUserStore;

0 commit comments

Comments
 (0)