Skip to content

Commit

Permalink
fix balances
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Dec 7, 2024
1 parent 316af4e commit 74663be
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
4 changes: 3 additions & 1 deletion frontend/src/components/BalanceDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
64 changes: 29 additions & 35 deletions frontend/src/hooks/useResourceLocks.ts
Original file line number Diff line number Diff line change
@@ -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"
) {
Expand All @@ -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<ResourceLocksResponse>(
['resourceLocks', address ?? '', chainId],
['resourceLocks', address ?? ''],
RESOURCE_LOCKS_QUERY,
{
{
address: address?.toLowerCase() ?? '',
chainId: chainId,
},
{
enabled: !!address,
}
)
);

return {
data: data?.account ?? { resourceLocks: { items: [] } },
isLoading,
error,
}
};
}

0 comments on commit 74663be

Please sign in to comment.