Skip to content

fix: add assets-controller temp state migration healing#9393

Open
Prithpal-Sooriya wants to merge 5 commits into
mainfrom
fix/add-assets-controller-temp-migration
Open

fix: add assets-controller temp state migration healing#9393
Prithpal-Sooriya wants to merge 5 commits into
mainfrom
fix/add-assets-controller-temp-migration

Conversation

@Prithpal-Sooriya

@Prithpal-Sooriya Prithpal-Sooriya commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Explanation

Background: After a prior defect in AssetsController, metadata (AssetsController.assetsInfo) for custom tokens were wiped. Most popular chains support auto-detection and can self-heal, however not all chains support auto-detection.

Fix: This migration restores metadata for custom tokens on niche EVM chains that are unable to auto-detect/self-heal.

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

Medium Risk
Mutates persisted wallet asset state at construction from untrusted legacy data; behavior is heavily guarded and idempotent, but incorrect host wiring could still affect token display and custom-asset lists.

Overview
Adds a temporary constructor hook tempMigrateAssetsInfoMetadataAssets3346 so hosts can supply legacy TokensController / AccountsController persisted state. On startup, AssetsController runs tempHealAssetsInfoMetadata to restore wiped assetsInfo ERC-20 metadata and customAssets tracking for niche EVM chains that do not self-heal via the Accounts API.

Healing reads allTokens, respects allIgnoredTokens and current hidden assetPreferences, skips Accounts-API-supported chains and ERC-721s, never overwrites existing metadata, and treats legacy input as untrusted with defensive validation. Failures are reported through optional captureException without blocking controller construction.

Also documents the fix in the package changelog and aligns AssetsControllerStateInternal in types.ts with selectedCurrency (typed as SupportedCurrency).

Reviewed by Cursor Bugbot for commit 5d54234. Bugbot is set up for automated code reviews on this repo. Configure here.

@Prithpal-Sooriya Prithpal-Sooriya marked this pull request as ready for review July 6, 2026 14:08
@Prithpal-Sooriya Prithpal-Sooriya requested review from a team as code owners July 6, 2026 14:08
- Updated the `tempHealAssetsInfoMetadata` function to return the updated controller state directly instead of a callback for the `update` method.
- Introduced a new `selectedCurrency` field in `AssetsControllerStateInternal` to track the currently active ISO 4217 currency code.
- Improved test coverage for `tempHealAssetsInfoMetadata`, including scenarios for healing state and error handling.

This change aims to streamline the healing process for asset metadata and ensure better state management during migrations.
…ate healing

- Added a test to verify that the `tempHealAssetsInfoMetadata` function does not mutate existing `customAssets` arrays in the input state.
- Refactored the `tempHealAssetsInfoMetadata` function to use `cloneDeep` for state management, ensuring that the original state remains unchanged during the healing process.

This change enhances the reliability of state migrations by preventing unintended side effects on the input state.
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.

1 participant