From 958ac1e33056f4e407271acc463cf3f099a8824d Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 17 Nov 2024 18:22:53 -0500 Subject: [PATCH] simplified args in indexer call --- packages/kit/src/hooks/data.ts | 47 +++---------------- packages/wallet/src/hooks/data.ts | 10 ++-- .../src/views/CollectibleDetails/index.tsx | 1 - .../src/views/CollectionDetails/index.tsx | 11 +++-- 4 files changed, 21 insertions(+), 48 deletions(-) diff --git a/packages/kit/src/hooks/data.ts b/packages/kit/src/hooks/data.ts index c012215b..efdba2bd 100644 --- a/packages/kit/src/hooks/data.ts +++ b/packages/kit/src/hooks/data.ts @@ -67,32 +67,17 @@ export const getTokenBalances = async (indexerClient: SequenceIndexer, args: Get } export const getTokenBalancesSummary = async (indexerClient: SequenceIndexer, args: GetTokenBalancesSummaryArgs) => { - const res = await indexerClient.getTokenBalancesSummary({ - filter: args.filter, - omitMetadata: args.omitMetadata, - page: args.page - }) - + const res = await indexerClient.getTokenBalancesSummary(args) return res?.balances || [] } export const getTokenBalancesDetails = async (indexerClient: SequenceIndexer, args: GetTokenBalancesDetailsArgs) => { - const res = await indexerClient.getTokenBalancesDetails({ - filter: args.filter, - omitMetadata: args.omitMetadata, - page: args.page - }) - + const res = await indexerClient.getTokenBalancesDetails(args) return res?.balances || [] } export const getTokenBalancesByContract = async (indexerClient: SequenceIndexer, args: GetTokenBalancesByContractArgs) => { - const res = await indexerClient.getTokenBalancesByContract({ - filter: args.filter, - omitMetadata: args.omitMetadata, - page: args.page - }) - + const res = await indexerClient.getTokenBalancesByContract(args) return res?.balances || [] } @@ -105,14 +90,7 @@ export const getBalances = async (indexerClient: SequenceIndexer, chainId: numbe const balances = ( await Promise.allSettled([ getNativeTokenBalance(indexerClient, chainId, args.filter.accountAddresses[0]), - getTokenBalancesSummary(indexerClient, { - filter: { - accountAddresses: args.filter.accountAddresses, - contractStatus: args.filter.contractStatus, - contractWhitelist: args.filter.contractWhitelist, - contractBlacklist: args.filter.contractBlacklist - } - }) + getTokenBalancesSummary(indexerClient, args) ]) ) .map(res => (res.status === 'fulfilled' ? res.value : [])) @@ -196,24 +174,13 @@ export const useCollectibleBalance = (args: UseCollectibleBalanceArgs) => { } export const getCollectionBalance = async (indexerClient: SequenceIndexer, args: UseCollectionBalanceArgs) => { - const res = await indexerClient.getTokenBalancesDetails({ - filter: { - accountAddresses: [args.accountAddress], - contractStatus: args.verifiedOnly ? ContractVerificationStatus.VERIFIED : ContractVerificationStatus.ALL, - contractWhitelist: [args.contractAddress], - contractBlacklist: [] - } - }) + const res = await indexerClient.getTokenBalancesDetails(args) return res?.balances || [] } -interface UseCollectionBalanceArgs { +interface UseCollectionBalanceArgs extends GetTokenBalancesDetailsArgs { chainId: number - accountAddress: string - contractAddress: string - includeMetadata?: boolean - verifiedOnly?: boolean } export const useCollectionBalance = (args: UseCollectionBalanceArgs) => { @@ -224,7 +191,7 @@ export const useCollectionBalance = (args: UseCollectionBalanceArgs) => { queryFn: () => getCollectionBalance(indexerClient, args), retry: true, staleTime: time.oneSecond * 30, - enabled: !!args.chainId && !!args.accountAddress && !!args.contractAddress + enabled: !!args.chainId && !!args.filter.accountAddresses[0] && !!args.filter.contractWhitelist[0] }) } diff --git a/packages/wallet/src/hooks/data.ts b/packages/wallet/src/hooks/data.ts index dab8e00b..899e6dd1 100644 --- a/packages/wallet/src/hooks/data.ts +++ b/packages/wallet/src/hooks/data.ts @@ -154,10 +154,14 @@ export const getBalancesAssetsSummary = async ( } const balance = await getCollectionBalance(indexerClient, { - accountAddress, + filter: { + accountAddresses: [accountAddress], + contractStatus: ContractVerificationStatus.ALL, + contractWhitelist: [collectionBalance.contractAddress], + contractBlacklist: [] + }, chainId: collectionBalance.chainId, - contractAddress: collectionBalance.contractAddress, - includeMetadata: false + omitMetadata: false }) return balance diff --git a/packages/wallet/src/views/CollectibleDetails/index.tsx b/packages/wallet/src/views/CollectibleDetails/index.tsx index 8893d990..422e818b 100644 --- a/packages/wallet/src/views/CollectibleDetails/index.tsx +++ b/packages/wallet/src/views/CollectibleDetails/index.tsx @@ -7,7 +7,6 @@ import { ContractVerificationStatus } from '@0xsequence/kit' import { ethers } from 'ethers' -import React from 'react' import { useAccount } from 'wagmi' import { HEADER_HEIGHT } from '../../constants' diff --git a/packages/wallet/src/views/CollectionDetails/index.tsx b/packages/wallet/src/views/CollectionDetails/index.tsx index 511d942c..cc2650fc 100644 --- a/packages/wallet/src/views/CollectionDetails/index.tsx +++ b/packages/wallet/src/views/CollectionDetails/index.tsx @@ -1,8 +1,7 @@ import { Box, Image, Text, TokenImage, vars } from '@0xsequence/design-system' import { TokenBalance } from '@0xsequence/indexer' -import { useCollectionBalance } from '@0xsequence/kit' +import { useCollectionBalance, ContractVerificationStatus } from '@0xsequence/kit' import { ethers } from 'ethers' -import React from 'react' import { useAccount } from 'wagmi' import { useNavigation } from '../../hooks' @@ -21,8 +20,12 @@ export const CollectionDetails = ({ chainId, contractAddress }: CollectionDetail const { address: accountAddress } = useAccount() const { data: collectionBalanceData, isPending: isPendingCollectionBalance } = useCollectionBalance({ chainId, - accountAddress: accountAddress || '', - contractAddress + filter: { + accountAddresses: accountAddress ? [accountAddress] : [], + contractStatus: ContractVerificationStatus.ALL, + contractWhitelist: [contractAddress], + contractBlacklist: [] + } }) const contractInfo = collectionBalanceData?.[0]?.contractInfo