From fbe4da7014aa0b46e385639b076aad1895921201 Mon Sep 17 00:00:00 2001 From: tamvb2391 <33695595+tamvb2391@users.noreply.github.com> Date: Mon, 15 Jul 2024 10:49:04 +0700 Subject: [PATCH] [fix] account detail error when address is cosmos contract (#3629) --- .../data-services/api-cw20-token.service.ts | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/app/core/data-services/api-cw20-token.service.ts b/src/app/core/data-services/api-cw20-token.service.ts index ff9e217b6..c627874e2 100644 --- a/src/app/core/data-services/api-cw20-token.service.ts +++ b/src/app/core/data-services/api-cw20-token.service.ts @@ -75,13 +75,15 @@ export class ApiCw20TokenService { BigNumber(token.balance).gt(0), ); - const usdcCoin = this.parseUSDCToken(USDCToken, coinsMarkets); - - const idx = tokens?.findIndex((f) => f.contract_address?.toLowerCase() === USDC_ADDRESS); - if (idx >= 0) { - tokens[idx] = usdcCoin; - } else { - tokens.push(usdcCoin); + if (USDCToken) { + const usdcCoin = this.parseUSDCToken(USDCToken, coinsMarkets); + + const idx = tokens?.findIndex((f) => f.contract_address?.toLowerCase() === USDC_ADDRESS); + if (idx >= 0) { + tokens[idx] = usdcCoin; + } else { + tokens.push(usdcCoin); + } } const allTokens = [nativeToken, ...tokens]; @@ -115,12 +117,15 @@ export class ApiCw20TokenService { } async getUSDCToken(address: string) { + if (!address) { + return null; + } const contract = this.createContract(); const balance = await contract.balanceOf(address); const name = await contract.name(); const symbol = await contract.symbol(); const decimals = await contract.decimals(); - + return { ...USDC_TOKEN, tokenUrl: USDC_ADDRESS, @@ -135,7 +140,7 @@ export class ApiCw20TokenService { const USDCMarket = coinsMarkets?.find((item) => item.coinId === USDC_COIN_ID); const amount = getBalance(token?.balance || 0, token?.decimals); const value = new BigNumber(amount).multipliedBy(Number(USDCMarket?.currentPrice || 0)); - + return { ...token, change: null,