Skip to content

Commit

Permalink
use only chain address to avoid reverts (#1314)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsteenkamp89 authored Dec 12, 2024
1 parent 0ddd914 commit cb72176
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/hooks/useBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const getBalanceBySymbol = async (params: {
chainIdToQuery,
tokenSymbolToQuery
);
if (!tokenInfo) {
if (!tokenInfo || !tokenInfo.addresses?.[chainIdToQuery]) {
return undefined;
}
if (tokenInfo.isNative) {
Expand All @@ -45,7 +45,7 @@ const getBalanceBySymbol = async (params: {
return getBalance(
chainIdToQuery,
accountToQuery,
tokenInfo.address,
tokenInfo.addresses?.[chainIdToQuery],
"latest",
provider
);
Expand Down Expand Up @@ -178,20 +178,22 @@ export function useBalanceBySymbolPerChain({
>
>((chainId) => ({
queryKey: balanceQueryKey(account, chainId, tokenSymbol),
queryFn: ({ queryKey }) => {
queryFn: async ({ queryKey }) => {
const [, chainIdToQuery, tokenSymbolToQuery, accountToQuery] = queryKey;
if (
tokenSymbolToQuery === TOKEN_SYMBOLS_MAP.ETH.symbol &&
getNativeTokenSymbol(chainIdToQuery!) !== TOKEN_SYMBOLS_MAP.ETH.symbol
) {
return Promise.resolve(BigNumber.from(0));
}
return getBalanceBySymbol({
config,
chainIdToQuery,
tokenSymbolToQuery,
accountToQuery,
});
return (
(await getBalanceBySymbol({
config,
chainIdToQuery,
tokenSymbolToQuery,
accountToQuery,
})) ?? Promise.resolve(BigNumber.from(0))
);
},
enabled: Boolean(account && tokenSymbol),
refetchInterval: 10_000,
Expand Down

0 comments on commit cb72176

Please sign in to comment.