Skip to content

Commit

Permalink
fix: total fiat calculation (#2457)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Nardi <[email protected]>
  • Loading branch information
nicole-obrien and MarkNerdi authored May 8, 2024
1 parent e5e0892 commit faa12cc
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ITokenWithBalance, TokenFilter } from '../interfaces'
import { AccountTokens, IAccountTokensPerNetwork } from '../interfaces/account-tokens.interface'
import { getPersistedToken, persistedTokens } from './persisted-tokens.store'
import { activeAccounts, activeProfile } from '@core/profile/stores'
import { tryNumberOrZero } from '@core/utils'

export const tokenFilter: Writable<TokenFilter> = writable(DEFAULT_ASSET_FILTER)

Expand Down Expand Up @@ -52,9 +53,9 @@ export const allAccountFiatBalances: Readable<{ [accountIndex: string]: string }
let fiatBalance = 0
for (const networkId of Object.keys(accountTokens)) {
const tokens = accountTokens[networkId as NetworkId]
fiatBalance += Number(tokens?.baseCoin?.balance?.totalFiat ?? 0)
fiatBalance += tryNumberOrZero(tokens?.baseCoin?.balance?.totalFiat)
for (const token of tokens?.nativeTokens ?? []) {
const totalFiat = Number(token.balance.totalFiat) ?? 0
const totalFiat = tryNumberOrZero(token.balance.totalFiat)
const fiatValue = Number.isFinite(totalFiat) ? totalFiat : 0
fiatBalance += fiatValue
}
Expand Down

0 comments on commit faa12cc

Please sign in to comment.