Skip to content

Commit

Permalink
[STYLE] Fetch current epoch from BE, not contract (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
aziolek authored Oct 31, 2024
2 parents 80ec951 + 3be32e2 commit e4ceceb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
10 changes: 10 additions & 0 deletions client/src/api/calls/epochs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import env from 'env';
import apiService from 'services/apiService';

export type Response = {
currentEpoch: number;
};

export async function apiGetCurrentEpoch(): Promise<Response> {
return apiService.get(`${env.serverEndpoint}epochs/current`).then(({ data }) => data);
}
16 changes: 4 additions & 12 deletions client/src/hooks/queries/useCurrentEpoch.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import { UseQueryOptions, UseQueryResult, useQuery } from '@tanstack/react-query';
import { usePublicClient } from 'wagmi';

import { apiGetCurrentEpoch, Response } from 'api/calls/epochs';
import { QUERY_KEYS } from 'api/queryKeys';
import networkConfig from 'constants/networkConfig';
import { readContractEpochs } from 'hooks/contracts/readContracts';

export default function useCurrentEpoch(
options?: Omit<UseQueryOptions<BigInt, unknown, number, any>, 'queryKey'>,
options?: Omit<UseQueryOptions<Response, unknown, number, any>, 'queryKey'>,
): UseQueryResult<number, unknown> {
const publicClient = usePublicClient({ chainId: networkConfig.id });

return useQuery({
queryFn: () =>
readContractEpochs({
functionName: 'getCurrentEpoch',
publicClient,
}),
queryFn: () => apiGetCurrentEpoch(),
queryKey: QUERY_KEYS.currentEpoch,
select: res => Number(res),
select: ({ currentEpoch }) => currentEpoch,
staleTime: Infinity,
...options,
});
Expand Down

0 comments on commit e4ceceb

Please sign in to comment.