diff --git a/packages/widget/src/hooks/useGasSufficiency.ts b/packages/widget/src/hooks/useGasSufficiency.ts index b5920aa4f..75dea44e8 100644 --- a/packages/widget/src/hooks/useGasSufficiency.ts +++ b/packages/widget/src/hooks/useGasSufficiency.ts @@ -16,9 +16,9 @@ export interface GasSufficiency { const refetchInterval = 30_000; export const useGasSufficiency = (route?: Route) => { - const { account } = useWallet(); + const { account, provider } = useWallet(); const { getChainById } = useChains(); - const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(); + const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(provider); const { data: insufficientGas, isInitialLoading } = useQuery( ['gas-sufficiency-check', account.address, route?.id], diff --git a/packages/widget/src/hooks/useGetTokenBalancesWithRetry.ts b/packages/widget/src/hooks/useGetTokenBalancesWithRetry.ts index 0871a435d..2b76dd123 100644 --- a/packages/widget/src/hooks/useGetTokenBalancesWithRetry.ts +++ b/packages/widget/src/hooks/useGetTokenBalancesWithRetry.ts @@ -1,8 +1,10 @@ +import { isAddress } from '@ethersproject/address'; +import type { Provider } from '@ethersproject/providers'; import type { Token, TokenAmount } from '@lifi/sdk'; import { useCallback } from 'react'; import { useLiFi } from '../providers'; -export const useGetTokenBalancesWithRetry = () => { +export const useGetTokenBalancesWithRetry = (provider?: Provider) => { const lifi = useLiFi(); const getTokenBalancesWithRetry = useCallback( @@ -12,8 +14,12 @@ export const useGetTokenBalancesWithRetry = () => { depth = 0, ): Promise => { try { + const walletAddress = isAddress(accountAddress) + ? accountAddress + : await provider?.resolveName(accountAddress); + const tokenBalances = await lifi.getTokenBalances( - accountAddress as string, + walletAddress as string, tokens, ); if (!tokenBalances.every((token) => token.blockNumber)) { @@ -31,7 +37,7 @@ export const useGetTokenBalancesWithRetry = () => { // } }, - [lifi], + [lifi, provider], ); return getTokenBalancesWithRetry; diff --git a/packages/widget/src/hooks/useTokenBalance.ts b/packages/widget/src/hooks/useTokenBalance.ts index 3f0d409e0..e5b0594c8 100644 --- a/packages/widget/src/hooks/useTokenBalance.ts +++ b/packages/widget/src/hooks/useTokenBalance.ts @@ -8,11 +8,11 @@ import { useGetTokenBalancesWithRetry } from './useGetTokenBalancesWithRetry'; const defaultRefetchInterval = 30_000; export const useTokenBalance = (token?: Token, accountAddress?: string) => { - const { account } = useWallet(); + const { account, provider } = useWallet(); const queryClient = useQueryClient(); const walletAddress = accountAddress || account.address; - const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(); + const getTokenBalancesWithRetry = useGetTokenBalancesWithRetry(provider); const tokenBalanceQueryKey = useMemo( () => ['token-balance', walletAddress, token?.chainId, token?.address],