-
Notifications
You must be signed in to change notification settings - Fork 5.5k
release(runway): cherry-pick fix: cp-13.11.0 patch TokenBalancesController to resolve missing balance state #38182
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
release(runway): cherry-pick fix: cp-13.11.0 patch TokenBalancesController to resolve missing balance state #38182
Conversation
…oller to resolve missing balance state (#38126) ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [](https://codespaces.new/MetaMask/metamask-extension/pull/38126?quickstart=1) ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: fix missing native token balances in wallet balance ## **Related issues** Fixes: #38114 ## **Manual testing steps** Onboard or existing user with AccountsAPI enabled 1. Go to a network with native + erc tokens 2. Notice aggregated wallet balance - it should have both native + erc tokens aggregated together for the balance. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> https://www.loom.com/share/aeccc8e3cef4479da0e9d44fc5ebf4fa ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Patches `TokenBalancesController` to use lowercase account keys when reading/writing `tokenBalances`, and wires the patch via a Yarn patched dependency for `@metamask/assets-controllers@89.0.1`. > > - **Assets Controllers Patch**: > - Normalize `account` to lowercase in `TokenBalancesController` (`dist/TokenBalancesController.{cjs,mjs}`) when checking and setting `d.tokenBalances[account][chainId][tokenAddress]`. > - **Build/Deps**: > - Apply Yarn patch for `@metamask/assets-controllers@89.0.1` via `package.json` and update lockfile to reference the patched package. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit d4370d9. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
|
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. |
| // Only update if the balance has actually changed | ||
| if (currentBalance !== newBalance) { | ||
| - ((_c = ((_a = d.tokenBalances)[_b = account] ?? (_a[_b] = {})))[chainId] ?? (_c[chainId] = {}))[tokenAddress] = newBalance; | ||
| + ((_b = ((_a = d.tokenBalances)[lowerCaseAccount] ?? (_a[lowerCaseAccount] = {})))[chainId] ?? (_b[chainId] = {}))[tokenAddress] = newBalance; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Case mismatch between stored and accessed account addresses
The patch stores token balances using lowercase account addresses via account.toLowerCase(), but consuming code accesses tokenBalances using selectedAccount.address directly without lowercasing. Since Ethereum addresses from AccountsController can be checksummed (mixed case per EIP-55), this creates a case-sensitivity mismatch. When the account address is checksummed, lookups like tokenBalances[selectedAccount.address] will fail to find balances stored under tokenBalances[selectedAccount.address.toLowerCase()], causing missing balance data in the UI.
Additional Locations (1)
Builds ready [5d6cd9f]
UI Startup Metrics (1220 ± 99 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
|
|
Not needed as included in stable-sync PR: #38183 |
Description
Changelog
CHANGELOG entry: fix missing native token balances in wallet balance
Related issues
Fixes: #38114
Manual testing steps
Onboard or existing user with AccountsAPI enabled
tokens aggregated together for the balance.
Screenshots/Recordings
Before
After
https://www.loom.com/share/aeccc8e3cef4479da0e9d44fc5ebf4fa
Pre-merge author checklist
Docs and MetaMask
Extension Coding
Standards.
if applicable
guidelines).
Not required for external contributors.
Pre-merge reviewer checklist
app, test code being changed).
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
Note
Patches assets-controllers to lower-case account keys in TokenBalancesController balance updates and wires the Yarn patch into the build.
@metamask/assets-controllers@89.0.1viapackage.jsonandyarn.lock.dist/TokenBalancesController.{cjs,mjs}to normalizeaccountto lower-case when reading/updatingd.tokenBalances, adjusting lookups and writes accordingly.Written by Cursor Bugbot for commit 5d6cd9f. This will update automatically on new commits. Configure here.
a2fe8c4