Skip to content

Commit

Permalink
exposed hooks and replaced internal calls to new hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlee348 committed Jan 14, 2025
1 parent f4c4d69 commit 064c9bd
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 19 deletions.
4 changes: 2 additions & 2 deletions packages/checkout/src/views/PaymentSelection/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box, Button, Divider, Text } from '@0xsequence/design-system'
import {
useBalances,
useBalancesSummary,
useContractInfo,
useSwapPrices,
useSwapQuote,
Expand Down Expand Up @@ -93,7 +93,7 @@ export const PaymentSelectionContent = () => {
}
})

const { data: currencyBalanceData, isLoading: currencyBalanceIsLoading } = useBalances({
const { data: currencyBalanceData, isLoading: currencyBalanceIsLoading } = useBalancesSummary({
chainIds: [chainId],
filter: {
accountAddresses: userAddress ? [userAddress] : [],
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/components/TxnDetails/TxnDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ethers } from 'ethers'
import React, { useEffect, useState } from 'react'
import { useConfig } from 'wagmi'

import { useTokenMetadata, useBalances } from '../../hooks/data'
import { useTokenMetadata, useBalancesSummary } from '../../hooks/data'
import { useAPIClient } from '../../hooks/useAPIClient'
import { compareAddress, capitalize } from '../../utils/helpers'
import { getNativeTokenInfoByChainId } from '../../utils/tokens'
Expand Down Expand Up @@ -94,7 +94,7 @@ const TransferItemInfo = ({ address, transferProps, chainId }: TransferItemInfoP
const isNFT = transferProps.contractType === ContractType.ERC1155 || transferProps.contractType === ContractType.ERC721
const nativeTokenInfo = getNativeTokenInfoByChainId(chainId, chains)

const { data: balances = [] } = useBalances({
const { data: balances = [] } = useBalancesSummary({
chainIds: [chainId],
filter: {
accountAddresses: [address],
Expand Down
25 changes: 24 additions & 1 deletion packages/kit/src/hooks/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export const useCoinBalanceSummary = (args: UseCoinBalanceSummaryArgs) => {
const indexerClient = useIndexerClient(args.chainId)

return useQuery({
queryKey: ['coinBalance', args],
queryKey: ['coinBalanceSummary', args],
queryFn: async () => {
if (compareAddress(args?.filter.contractWhitelist[0] || '', zeroAddress)) {
const res = await getNativeTokenBalance(indexerClient, args.chainId, args.filter.accountAddresses[0] || '')
Expand Down Expand Up @@ -251,6 +251,29 @@ export const useCollectibleBalance = (args: UseCollectibleBalanceArgs) => {
})
}

interface UseCollectibleBalanceDetailsArgs extends GetTokenBalancesDetailsArgs {
chainId: number
tokenId: string
}

export const useCollectibleBalanceDetails = (args: UseCollectibleBalanceDetailsArgs) => {
const indexerClient = useIndexerClient(args.chainId)

return useQuery({
queryKey: ['collectibleBalanceDetails', args],
queryFn: async () => {
const res = await indexerClient.getTokenBalancesDetails(args)

const balance = res.balances.find(balance => balance.tokenID === args.tokenId)

return balance
},
retry: true,
staleTime: time.oneSecond * 30,
enabled: !!args.chainId && !!args.filter.accountAddresses[0] && !!args.filter.contractWhitelist[0] && !!args.tokenId
})
}

/** @deprecated Use getCollectionBalanceDetails instead */
export const getCollectionBalance = async (indexerClient: SequenceIndexer, args: UseCollectionBalanceArgs) => {
const res = await indexerClient.getTokenBalances({
Expand Down
4 changes: 4 additions & 0 deletions packages/kit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,19 @@ export {
getCoinPrices,
getTransactionHistory,
useBalances,
useBalancesSummary,
useExchangeRate,
getTokenBalances,
getTokenBalancesSummary,
getTokenBalancesDetails,
getTokenBalancesByContract,
useCoinBalance,
useCoinBalanceSummary,
useCoinPrices,
useCollectionBalance,
useCollectionBalanceDetails,
useCollectibleBalance,
useCollectibleBalanceDetails,
useCollectiblePrices,
useTokenMetadata,
useContractInfo,
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/src/views/CoinDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
useExchangeRate,
useCoinPrices,
useTransactionHistory,
useCoinBalance,
useCoinBalanceSummary,
ContractVerificationStatus
} from '@0xsequence/kit'
import { ethers } from 'ethers'
Expand Down Expand Up @@ -45,7 +45,7 @@ export const CoinDetails = ({ contractAddress, chainId }: CoinDetailsProps) => {

const transactionHistory = flattenPaginatedTransactionHistory(dataTransactionHistory)

const { data: dataCoinBalance, isPending: isPendingCoinBalance } = useCoinBalance({
const { data: dataCoinBalance, isPending: isPendingCoinBalance } = useCoinBalanceSummary({
filter: {
accountAddresses: [accountAddress || ''],
contractStatus: hideUnlistedTokens ? ContractVerificationStatus.VERIFIED : ContractVerificationStatus.ALL,
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/src/views/CollectibleDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
useExchangeRate,
useTransactionHistory,
useCollectiblePrices,
useCollectibleBalance,
useCollectibleBalanceDetails,
ContractVerificationStatus
} from '@0xsequence/kit'
import { ethers } from 'ethers'
Expand Down Expand Up @@ -44,7 +44,7 @@ export const CollectibleDetails = ({ contractAddress, chainId, tokenId }: Collec

const transactionHistory = flattenPaginatedTransactionHistory(dataTransactionHistory)

const { data: dataCollectibleBalance, isPending: isPendingCollectibleBalance } = useCollectibleBalance({
const { data: dataCollectibleBalance, isPending: isPendingCollectibleBalance } = useCollectibleBalanceDetails({
filter: {
accountAddresses: accountAddress ? [accountAddress] : [],
contractStatus: ContractVerificationStatus.ALL,
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/src/views/CollectionDetails/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Box, Image, Text, TokenImage, vars } from '@0xsequence/design-system'
import { TokenBalance } from '@0xsequence/indexer'
import { useCollectionBalance, ContractVerificationStatus } from '@0xsequence/kit'
import { useCollectionBalanceDetails, ContractVerificationStatus } from '@0xsequence/kit'
import { ethers } from 'ethers'
import { useAccount } from 'wagmi'

Expand All @@ -18,7 +18,7 @@ interface CollectionDetailsProps {
export const CollectionDetails = ({ chainId, contractAddress }: CollectionDetailsProps) => {
const { setNavigation } = useNavigation()
const { address: accountAddress } = useAccount()
const { data: collectionBalanceData, isPending: isPendingCollectionBalance } = useCollectionBalance({
const { data: collectionBalanceData, isPending: isPendingCollectionBalance } = useCollectionBalanceDetails({
chainId,
filter: {
accountAddresses: accountAddress ? [accountAddress] : [],
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/src/views/Search/SearchWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
getNativeTokenInfoByChainId,
useExchangeRate,
useCoinPrices,
useBalances,
useBalancesSummary,
ContractVerificationStatus
} from '@0xsequence/kit'
import { ethers } from 'ethers'
Expand All @@ -23,7 +23,7 @@ export const SearchWallet = () => {
const [search, setSearch] = useState('')
const { address: accountAddress } = useAccount()

const { data: tokenBalancesData, isPending: isPendingTokenBalances } = useBalances({
const { data: tokenBalancesData, isPending: isPendingTokenBalances } = useBalancesSummary({
chainIds: selectedNetworks,
filter: {
accountAddresses: accountAddress ? [accountAddress] : [],
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/src/views/Search/SearchWalletViewAll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
getNativeTokenInfoByChainId,
useExchangeRate,
useCoinPrices,
useBalances,
useBalancesSummary,
ContractVerificationStatus
} from '@0xsequence/kit'
import { ethers } from 'ethers'
Expand Down Expand Up @@ -32,7 +32,7 @@ export const SearchWalletViewAll = ({ defaultTab }: SearchWalletViewAllProps) =>

const { address: accountAddress } = useAccount()

const { data: tokenBalancesData, isPending: isPendingTokenBalances } = useBalances({
const { data: tokenBalancesData, isPending: isPendingTokenBalances } = useBalancesSummary({
chainIds: selectedNetworks,
filter: {
accountAddresses: accountAddress ? [accountAddress] : [],
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/src/views/SendCoin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
ExtendedConnector,
useExchangeRate,
useCoinPrices,
useBalances,
useBalancesSummary,
useCheckWaasFeeOptions,
useWaasFeeOptions
} from '@0xsequence/kit'
Expand Down Expand Up @@ -69,7 +69,7 @@ export const SendCoin = ({ chainId, contractAddress }: SendCoinProps) => {
const checkFeeOptions = useCheckWaasFeeOptions()
const [pendingFeeOption, confirmFeeOption, rejectFeeOption] = useWaasFeeOptions()

const { data: balances = [], isPending: isPendingBalances } = useBalances({
const { data: balances = [], isPending: isPendingBalances } = useBalancesSummary({
chainIds: [chainId],
filter: {
accountAddresses: [accountAddress],
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/src/views/SendCollectible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
getNativeTokenInfoByChainId,
useAnalyticsContext,
ExtendedConnector,
useCollectibleBalance,
useCollectibleBalanceDetails,
useCheckWaasFeeOptions,
useWaasFeeOptions
} from '@0xsequence/kit'
Expand Down Expand Up @@ -70,7 +70,7 @@ export const SendCollectible = ({ chainId, contractAddress, tokenId }: SendColle
const checkFeeOptions = useCheckWaasFeeOptions()
const [pendingFeeOption, confirmFeeOption, rejectFeeOption] = useWaasFeeOptions()

const { data: tokenBalance, isPending: isPendingBalances } = useCollectibleBalance({
const { data: tokenBalance, isPending: isPendingBalances } = useCollectibleBalanceDetails({
filter: {
accountAddresses: [accountAddress],
contractStatus: ContractVerificationStatus.ALL,
Expand Down

0 comments on commit 064c9bd

Please sign in to comment.