fix(assets-controller): heal native token assetsInfo entries#9099
fix(assets-controller): heal native token assetsInfo entries#9099Prithpal-Sooriya wants to merge 9 commits into
Conversation
… metadata This commit introduces a new test case to ensure that the middleware correctly refetches asset metadata when the stored type is stale, even if an image is present. The test verifies that a previously misclassified native asset is updated to its correct type, enhancing the robustness of the asset handling logic.
|
@cursor READ AND FOLLOW THESE MEMORY FILES: /babysit fix CI |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7480667. Configure here.
Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
| const assetsInfoAssetIdsSet = new Set( | ||
| Object.keys(normalizedResponse.assetsInfo ?? {}) as Caip19AssetId[], | ||
| ); |
There was a problem hiding this comment.
@cursor I had a good back and forth with Claude around this.
The reason this works is because RPC detection can pick this up and therefore have some assetsInfo to rely on.
So as a safe measure we can use both the assetsInfo and assetsBalance.
const assetsInfoAssetIdsSet = new Set([
...Object.keys(normalizedResponse.assetsInfo ?? {}),
...Object.entries(normalizedResponse.assetsBalance ?? {}).flatMap(
([_, b]) => Object.keys(b),
),
] as Caip19AssetId[]);
Thoughts?
There was a problem hiding this comment.
Good call — I agree with your proposal, and I’ve already applied it.
Thoughts
Using both normalized assetsInfo and normalized assetsBalance keys is the safer behavior:
- It preserves the
assetsInfo-first logic. - It also heals stale types when a response only touches balance (which can happen via RPC detection flows).
- Because both come from
normalizedResponse, it avoids the non-checksummed key mismatch bug.
What I changed
Implemented reconciliation key set as union of:
Object.keys(normalizedResponse.assetsInfo ?? {})- asset IDs found in
normalizedResponse.assetsBalanceentries
Then reconciles metadata[assetId].type for all those touched IDs.
Added coverage
- New test:
reconciles a stale native type stored as erc20 when assetsBalance includes the asset - Existing normalized-key reconciliation test remains in place.
Changelog
Updated to reflect behavior now applies when asset appears in incoming:
assetsInfoorassetsBalance.
Validation run
Passed locally:
yarn lint:misc:checkyarn eslint packages/assets-controller/src/AssetsController.ts packages/assets-controller/src/AssetsController.test.tsyarn workspace @metamask/assets-controller run jest --no-coverage src/AssetsController.test.ts --runInBand --forceExityarn changelog:validate
Git
- Commit:
0eef15d37 - Pushed to
fix/heal-native-token-entries - PR fix(assets-controller): heal native token assetsInfo entries #9099 updated
- Fresh CI run is in progress for this commit.
Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>



Explanation
This commit introduces a new test case to ensure that the middleware correctly refetches asset metadata when the stored type is stale, even if an image is present. The test verifies that a previously misclassified native asset is updated to its correct type, enhancing the robustness of the asset handling logic.
References
Checklist
Note
Low Risk
Localized metadata correction on update paths; behavior is covered by new unit tests and does not change auth or external APIs.
Overview
AssetsControllernow self-heals staleassetsInfo.typevalues duringhandleAssetsUpdatefor any asset ID present in the incomingassetsInfoorassetsBalancepayload. After metadata merge, it compares each touched entry to#getAssetType(assetId)and rewrites mismatches (e.g. zero-address native tokens still stored aserc20from older builds), including when existing metadata already has an image.Tests cover reconciliation via metadata or balance updates, unchanged real ERC-20s, and type fixes when responses use non-checksummed asset IDs. The unreleased changelog documents the fix.
Reviewed by Cursor Bugbot for commit 0eef15d. Bugbot is set up for automated code reviews on this repo. Configure here.