Skip to content

fix: balance stuck in loading state.#17372

Merged
darioAnongba merged 10 commits into
mainfrom
fix/balances-bitcoin
Jul 22, 2025
Merged

fix: balance stuck in loading state.#17372
darioAnongba merged 10 commits into
mainfrom
fix/balances-bitcoin

Conversation

@darioAnongba

@darioAnongba darioAnongba commented Jul 18, 2025

Copy link
Copy Markdown
Contributor

Description

Fixes bug where native balances are not displayed for non EVM accounts on the accounts list because we try fetching the balance of the current selected network instead of the network of the account.

Changelog

CHANGELOG entry: Fixes bug where native balances are not displayed for non EVM accounts on the accounts list

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/NWNT-408

Manual testing steps

  1. Create Bitcoin account
  2. Create Solana account
  3. Navigate to Solana or Bitcoin account
  4. See Bitcoin account balance displayed

Screenshots/Recordings

Before

After

Simulator Screenshot - iPhone 16 Pro - 2025-07-18 at 15 42 49

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@darioAnongba darioAnongba self-assigned this Jul 18, 2025
@github-actions

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-networks Networks team label Jul 18, 2025
@darioAnongba darioAnongba added the No QA Needed Apply this label when your PR does not need any QA effort. label Jul 18, 2025
@darioAnongba darioAnongba marked this pull request as ready for review July 18, 2025 14:46
@darioAnongba darioAnongba requested a review from a team as a code owner July 18, 2025 14:46
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Native Token Balance Overwrite Bug

The getMultichainNetworkAggregatedBalance function processes all assets for an account. If an account holds native assets from multiple chains (e.g., Bitcoin and Solana), the totalNativeTokenBalance is repeatedly overwritten during asset iteration. This causes only the balance of the last native asset processed to be retained, leading to data loss and non-deterministic, incorrect native token balance reporting.

app/selectors/multichain/multichain.ts#L292-L314

for (const assetId of assetIds) {
const { chainId } = parseCaipAssetType(assetId);
const nativeAssetId =
AVAILABLE_MULTICHAIN_NETWORK_CONFIGURATIONS[
chainId as SupportedCaipChainId
]?.nativeCurrency;
const balance = balances[assetId] || { amount: '0', unit: '' };
// Safely handle undefined rate
const rate = multichainAssetsRates?.[assetId]?.rate;
const balanceInFiat =
balance.amount && rate
? new BigNumber(balance.amount).times(rate)
: new BigNumber(0);
fiatBalances[assetId] = balanceInFiat.toString();
// If the asset is the native asset of the chain, set it as total native token balance
// This assumes the account is always on the same chain (excludes testnets)
if (assetId === nativeAssetId) {
totalNativeTokenBalance = balance;
}

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.77%. Comparing base (5184987) to head (ce55051).
Report is 21 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17372      +/-   ##
==========================================
+ Coverage   73.57%   73.77%   +0.20%     
==========================================
  Files        2845     2852       +7     
  Lines       63338    63814     +476     
  Branches    10328    10445     +117     
==========================================
+ Hits        46598    47076     +478     
+ Misses      13741    13707      -34     
- Partials     2999     3031      +32     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Jul 22, 2025

Copy link
Copy Markdown
Contributor

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: ce55051
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/77a0c73b-1597-479f-8997-9f8e3a2c8d02

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Comment thread app/selectors/multichain/multichain.test.ts
@darioAnongba darioAnongba added this pull request to the merge queue Jul 22, 2025
Merged via the queue into main with commit ee7b314 Jul 22, 2025
54 of 56 checks passed
@darioAnongba darioAnongba deleted the fix/balances-bitcoin branch July 22, 2025 16:46
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 22, 2025
@metamaskbot metamaskbot added the release-7.53.0 Issue or pull request that will be included in release 7.53.0 label Jul 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

No QA Needed Apply this label when your PR does not need any QA effort. release-7.53.0 Issue or pull request that will be included in release 7.53.0 team-networks Networks team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants