Skip to content

Commit

Permalink
fix: fetch balances when wallet address is valid (#1778)
Browse files Browse the repository at this point in the history
  • Loading branch information
brtkx authored Jul 22, 2024
1 parent f07b0c5 commit 6cb1eea
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/arb-token-bridge-ui/src/hooks/useBalance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useMemo } from 'react'
import { BigNumber } from 'ethers'
import { BigNumber, utils } from 'ethers'
import useSWR, {
useSWRConfig,
unstable_serialize,
Expand Down Expand Up @@ -40,10 +40,13 @@ const merge: Middleware = (useSWRNext: SWRHook) => {
}

const useBalance = ({ chainId, walletAddress }: UseBalanceProps) => {
const walletAddressLowercased = useMemo(
() => walletAddress?.toLowerCase(),
[walletAddress]
)
const walletAddressLowercased = useMemo(() => {
// use balances for the wallet address only if it's valid
if (!walletAddress || !utils.isAddress(walletAddress)) {
return undefined
}
return walletAddress.toLowerCase()
}, [walletAddress])

const queryKey = useCallback(
(type: 'eth' | 'erc20') => {
Expand Down

0 comments on commit 6cb1eea

Please sign in to comment.