Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] account detail error when address is cosmos contract #3629

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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