Skip to content

Commit

Permalink
[fix] account detail error when address is cosmos contract (#3629)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamvb2391 authored Jul 15, 2024
1 parent d5d7608 commit fbe4da7
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/app/core/data-services/api-cw20-token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit fbe4da7

Please sign in to comment.