UNPKG

@lifi/widget

Version:

LI.FI Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.

28 lines (24 loc) 733 B
import { useMemo } from 'react' import type { TokenAmount } from '../types/token.js' import { useTokenBalances } from './useTokenBalances.js' export const useTokenAddressBalance = ( chainId?: number, tokenAddress?: string ) => { const { tokens, tokensWithBalance, chain, isBalanceLoading, refetch } = useTokenBalances(chainId) const token = useMemo(() => { if (tokenAddress && chainId) { const token = (tokensWithBalance ?? tokens)?.find( (token) => token.address === tokenAddress && token.chainId === chainId ) return token as TokenAmount } }, [chainId, tokenAddress, tokens, tokensWithBalance]) return { token, chain, isLoading: isBalanceLoading, refetch, } }