From 74663bec7436e5abc5d77fc722ea019478a162fa Mon Sep 17 00:00:00 2001 From: 0age <37939117+0age@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:09:08 -0800 Subject: [PATCH] fix balances --- frontend/src/components/BalanceDisplay.tsx | 4 +- frontend/src/hooks/useResourceLocks.ts | 64 ++++++++++------------ 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/frontend/src/components/BalanceDisplay.tsx b/frontend/src/components/BalanceDisplay.tsx index e88b86c..c0bf664 100644 --- a/frontend/src/components/BalanceDisplay.tsx +++ b/frontend/src/components/BalanceDisplay.tsx @@ -125,7 +125,9 @@ export function BalanceDisplay(): JSX.Element | null { {balances.map((balance) => { // Find matching resource lock from indexer data const resourceLock = resourceLocksData?.resourceLocks.items.find( - (item) => item.resourceLock.lockId === balance.lockId + (item) => + item.resourceLock.lockId === balance.lockId && + item.chainId === balance.chainId ); const now = Math.floor(Date.now() / 1000); diff --git a/frontend/src/hooks/useResourceLocks.ts b/frontend/src/hooks/useResourceLocks.ts index 3e22925..8873b0d 100644 --- a/frontend/src/hooks/useResourceLocks.ts +++ b/frontend/src/hooks/useResourceLocks.ts @@ -1,14 +1,12 @@ -import { useAccount } from 'wagmi' -import { useGraphQLQuery } from './useGraphQL' +import { useAccount } from 'wagmi'; +import { useGraphQLQuery } from './useGraphQL'; const RESOURCE_LOCKS_QUERY = ` query GetResourceLocks( - $address: String!, - $chainId: BigInt! + $address: String! ) { account(address: $address) { resourceLocks( - where: {chainId: $chainId} orderBy: "balance" orderDirection: "DESC" ) { @@ -34,71 +32,67 @@ const RESOURCE_LOCKS_QUERY = ` } } } -` +`; interface Token { - tokenAddress: string - name: string - symbol: string - decimals: number + tokenAddress: string; + name: string; + symbol: string; + decimals: number; } interface ResourceLock { - lockId: string + lockId: string; allocator: { - account: string - } - token: Token - resetPeriod: number - isMultichain: boolean - totalSupply: string + account: string; + }; + token: Token; + resetPeriod: number; + isMultichain: boolean; + totalSupply: string; } interface ResourceLockBalance { - chainId: string - resourceLock: ResourceLock - balance: string + chainId: string; + resourceLock: ResourceLock; + balance: string; } interface ResourceLockConnection { - items: ResourceLockBalance[] + items: ResourceLockBalance[]; } interface Account { - resourceLocks: ResourceLockConnection + resourceLocks: ResourceLockConnection; } interface ResourceLocksResponse { - account: Account | null + account: Account | null; } interface UseResourceLocksResult { - data: Account - isLoading: boolean - error: Error | null + data: Account; + isLoading: boolean; + error: Error | null; } export function useResourceLocks(): UseResourceLocksResult { - const { address, chain } = useAccount() - - // Convert chain ID to numeric string for GraphQL BigInt - const chainId = (chain?.id ?? 1).toString() + const { address } = useAccount(); const { data, isLoading, error } = useGraphQLQuery( - ['resourceLocks', address ?? '', chainId], + ['resourceLocks', address ?? ''], RESOURCE_LOCKS_QUERY, - { + { address: address?.toLowerCase() ?? '', - chainId: chainId, }, { enabled: !!address, } - ) + ); return { data: data?.account ?? { resourceLocks: { items: [] } }, isLoading, error, - } + }; }