From 30d4780afa3d1eccd9717e8e9fd9c96429ad6150 Mon Sep 17 00:00:00 2001 From: genaroibc Date: Fri, 28 Jun 2024 10:53:35 -0300 Subject: [PATCH] fix: catch errors getting evm balances --- src/handlers/evm/utils.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/handlers/evm/utils.ts b/src/handlers/evm/utils.ts index c4f2524..858af47 100644 --- a/src/handlers/evm/utils.ts +++ b/src/handlers/evm/utils.ts @@ -138,15 +138,25 @@ export class Utils { ); const getTokenData = async () => { - const balanceInWei = - await contract[isNativeToken ? "getEthBalance" : "balanceOf"](userAddress); + const { decimals, symbol, address, chainId } = token; + + let balance: string; + + try { + const balanceInWei = + await contract[isNativeToken ? "getEthBalance" : "balanceOf"](userAddress); + + balance = balanceInWei.toString(); + } catch (error) { + balance = "0"; + } return { - balance: balanceInWei.toString(), - symbol: token.symbol, - address: token.address, - decimals: token.decimals, - chainId: token.chainId, + balance, + symbol, + address, + decimals, + chainId, }; };