Skip to content

Commit 0e36024

Browse files
authored
feat: do not eagerly fetch prices for tokens with no balance (#3874)
this was causing us to fetch balances for every pre-configured token immediately on page load even when some had no balance
1 parent 4d82168 commit 0e36024

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/utils/tokenListUtils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import { calculateUSDPriceRaw, isFrankensteinToken } from 'utils';
1515
import config from 'config';
1616
import { isNttToken } from './ntt';
17+
import type { Balances } from './wallet/types';
1718

1819
export const getTokenPreferenceScore = (
1920
token: Token,
@@ -42,11 +43,11 @@ export const getTokenPreferenceScore = (
4243

4344
export const calculateTokenUSDBalance = (
4445
token: Token,
45-
balances: Record<string, { balance: any }>,
46+
balances: Balances,
4647
getTokenPrice: (token: Token) => number | undefined,
4748
): number => {
4849
const balance = balances[tokenKey(token)];
49-
if (!balance || !balance.balance) {
50+
if (!balance || !balance.balance || balance.balance.amount === '0') {
5051
return 0;
5152
}
5253
return calculateUSDPriceRaw(getTokenPrice, balance.balance, token) ?? 0;
@@ -87,7 +88,7 @@ export const applyTokenSearch = (
8788
export const sortTokensByPreference = (
8889
tokens: Token[],
8990
selectedToken: Token | undefined,
90-
balances: Record<string, { balance: any }>,
91+
balances: Balances,
9192
getTokenPrice: (token: Token) => number | undefined,
9293
): Token[] => {
9394
return tokens.sort((a, b) => {

0 commit comments

Comments
 (0)