Skip to content

fix(assets-controller): heal native token assetsInfo entries#9099

Open
Prithpal-Sooriya wants to merge 9 commits into
mainfrom
fix/heal-native-token-entries
Open

fix(assets-controller): heal native token assetsInfo entries#9099
Prithpal-Sooriya wants to merge 9 commits into
mainfrom
fix/heal-native-token-entries

Conversation

@Prithpal-Sooriya

@Prithpal-Sooriya Prithpal-Sooriya commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

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

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

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
AssetsController now self-heals stale assetsInfo.type values during handleAssetsUpdate for any asset ID present in the incoming assetsInfo or assetsBalance payload. After metadata merge, it compares each touched entry to #getAssetType(assetId) and rewrites mismatches (e.g. zero-address native tokens still stored as erc20 from 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.

… 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.
@Prithpal-Sooriya Prithpal-Sooriya marked this pull request as ready for review June 11, 2026 22:39
@Prithpal-Sooriya Prithpal-Sooriya requested a review from a team as a code owner June 11, 2026 22:40
@Prithpal-Sooriya Prithpal-Sooriya deployed to default-branch June 11, 2026 22:40 — with GitHub Actions Active
@Prithpal-Sooriya

Copy link
Copy Markdown
Contributor Author

@cursor READ AND FOLLOW THESE MEMORY FILES:

/babysit fix CI

@cursor

cursor Bot commented Jun 11, 2026

Copy link
Copy Markdown

Taking a look!

Open in Web Open in Cursor 

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ 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.

Comment thread packages/assets-controller/src/AssetsController.ts
Comment thread packages/assets-controller/src/AssetsController.ts
Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
@cursor cursor Bot requested a review from a team as a code owner June 11, 2026 22:46
cursoragent and others added 4 commits June 11, 2026 22:48
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>
Comment on lines +2194 to +2196
const assetsInfoAssetIdsSet = new Set(
Object.keys(normalizedResponse.assetsInfo ?? {}) as Caip19AssetId[],
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@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?

@cursor cursor Bot Jun 11, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.assetsBalance entries

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:

  • assetsInfo or assetsBalance.

Validation run

Passed locally:

  • yarn lint:misc:check
  • yarn eslint packages/assets-controller/src/AssetsController.ts packages/assets-controller/src/AssetsController.test.ts
  • yarn workspace @metamask/assets-controller run jest --no-coverage src/AssetsController.test.ts --runInBand --forceExit
  • yarn changelog:validate

Git

Open in Web Open in Cursor 

Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants