Skip to content

feat: add assets migration selectors#29423

Merged
bergarces merged 16 commits into
mainfrom
add-assets-migration-selectors
May 1, 2026
Merged

feat: add assets migration selectors#29423
bergarces merged 16 commits into
mainfrom
add-assets-migration-selectors

Conversation

@bergarces

@bergarces bergarces commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Description

  • Adds assets migration selectors (same ones used for extension).
  • Replaces use of multiple instances that directly access the state with one of the selectors.

Changelog

CHANGELOG entry: null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/ASSETS-2827

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Before

After

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

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.

Note

Medium Risk
Touches multiple core selectors that feed balances, token lists, and pricing into Bridge/asset UI; while gated by the assetsUnifyState flag, any selector mismatch could surface incorrect amounts/rates across the app.

Overview
Introduces a new selectors/assets/assets-migration.ts layer that, when assetsUnifyState is enabled, derives legacy controller-shaped data (tokens, token balances, account tracker balances, multichain balances/assets, currency rates, token market data, and conversion rates) from the new AssetsController unified state; when disabled it falls back to the existing controller state.

Updates Bridge selectors, multichain selectors, asset list selectors, currency/token balance/token rate selectors, AccountTracker selectors, and Sentry trace tagging to consume these migration selectors instead of directly reading engine.backgroundState controller slices.

Adjusts assetsControllerInit to pass through persisted AssetsController state as-is (undefined when absent rather than a synthesized empty object) and simplifies the assetsUnifyState feature-flag evaluation by removing app minimumVersion checks; corresponding tests are updated and a comprehensive test suite is added for the migration selectors.

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

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

@bergarces bergarces changed the title migration selectors feat: add assets migration selectors Apr 28, 2026
@bergarces bergarces marked this pull request as ready for review April 28, 2026 13:04
@bergarces bergarces requested a review from a team as a code owner April 28, 2026 13:04
@bergarces bergarces changed the base branch from bump-assets-controllers-105 to main April 28, 2026 13:05
@bergarces bergarces requested a review from a team as a code owner April 28, 2026 13:05
@bergarces bergarces changed the base branch from main to bump-assets-controllers-105 April 28, 2026 13:05
@bergarces bergarces marked this pull request as draft April 28, 2026 13:05
assetPreferences: {},
assetsInfo: {},
assetsBalance: {},
},

@bergarces bergarces Apr 28, 2026

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.

This is not a valid initial state anymore. If the initial state is undefined, better let the controller handle the shape of the default state.

@bergarces bergarces Apr 28, 2026

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.

These are the same selectors used in extension (the logic is, the selectors itself are slightly different because the state is not flattened here).

We also don't need to make assertions on the selector type here.

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.

As with extension, we now use the built-in mechanism for minimum version. This can be simplified.

@codecov-commenter

codecov-commenter commented Apr 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.31944% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.23%. Comparing base (f968f46) to head (8c1e847).
⚠️ Report is 111 commits behind head on main.

Files with missing lines Patch % Lines
app/selectors/assets/assets-migration.ts 91.04% 8 Missing and 16 partials ⚠️
app/selectors/currencyRateController.ts 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #29423      +/-   ##
==========================================
- Coverage   82.41%   82.23%   -0.18%     
==========================================
  Files        5157     5166       +9     
  Lines      136690   137201     +511     
  Branches    30816    30980     +164     
==========================================
+ Hits       112648   112826     +178     
- Misses      16407    16743     +336     
+ Partials     7635     7632       -3     

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

@bergarces bergarces force-pushed the add-assets-migration-selectors branch from 2f8d001 to 65b6a92 Compare April 28, 2026 14:06
@bergarces bergarces force-pushed the add-assets-migration-selectors branch from f3d2958 to 0246d21 Compare April 28, 2026 15:34
Base automatically changed from bump-assets-controllers-105 to main April 29, 2026 07:09
@bergarces bergarces marked this pull request as ready for review April 29, 2026 07:21
Comment thread app/selectors/featureFlagController/assetsUnifyState/index.ts
Comment thread app/core/redux/slices/bridge/index.ts
conversionRates: {},
};

///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)

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.

We can remove code fences. The selectors used will work even if multichain state is undefined.

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 3 total unresolved issues (including 2 from previous reviews).

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 af13243. Configure here.

Comment thread app/selectors/assets/assets-migration.ts Outdated
@bergarces bergarces enabled auto-merge May 1, 2026 10:50
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeWalletPlatform, SmokeConfirmations, SmokeSwap, SmokeStake, SmokeNetworkExpansion, SmokeNetworkAbstractions, SmokeMultiChainAPI, SmokeAccounts, SmokeMoney, SmokePerps
  • Selected Performance tags: @PerformanceAssetLoading, @PerformanceAccountList, @PerformanceSwaps
  • Risk Level: high
  • AI Confidence: 88%
click to see 🤖 AI reasoning details

E2E Test Selection:
These changes introduce a major architectural refactoring of asset-related selectors across the entire app. A new assets-migration.ts file creates a compatibility layer that intercepts state reads from multiple controllers (TokenBalancesController, CurrencyRateController, TokenRatesController, TokensController, AccountTrackerController, MultichainBalancesController, MultichainAssetsController, MultichainAssetsRatesController) and either returns legacy state or derives equivalent data from the new unified AssetsController state based on a feature flag.

The impact is extremely broad:

  1. Token balances - affects wallet home token list, confirmations simulation, bridge/swap token selection
  2. Currency/conversion rates - affects fiat display everywhere (token list, confirmations, swap quotes, earn)
  3. Token market data - affects price display, swap/bridge exchange rates
  4. Account balances (native ETH) - affects account selector, wallet home balance display
  5. Multichain assets (Solana/non-EVM) - affects non-EVM token display and balances
  6. Bridge/Swap state - directly updated to use migration selectors for rates and market data

The feature flag simplification (removing minimumVersion check) could also change which users see the new behavior.

Tags selected:

  • SmokeWalletPlatform: Token list, balances, transaction history all use affected selectors
  • SmokeConfirmations: SimulationDetails uses currencyRate and tokenRates selectors; fiat display in confirmations
  • SmokeSwap: Bridge/swap hooks use tokenRates, currencyRates, tokenBalances selectors directly
  • SmokeStake: Earn/staking uses token balances and rates selectors
  • SmokeNetworkExpansion: Solana multichain balances and assets selectors are refactored
  • SmokeNetworkAbstractions: Network-aware token filtering uses affected selectors
  • SmokeMultiChainAPI: Multichain session data relies on multichain asset selectors
  • SmokeAccounts: Account balance display uses accountTrackerController selector
  • SmokeMoney: Ramps use balance and currency rate selectors
  • SmokePerps: Perps portfolio balance uses currency rate selectors

Per tag descriptions: SmokeSwap requires SmokeConfirmations (already included); SmokeStake requires SmokeConfirmations (already included); SmokePerps requires SmokeWalletPlatform and SmokeConfirmations (already included); SmokeMultiChainAPI requires SmokeNetworkAbstractions and SmokeNetworkExpansion (already included).

Performance Test Selection:
The new assets-migration.ts selectors add computational overhead by deriving state from the AssetsController instead of directly reading from individual controllers. When the assetsUnifyState feature flag is enabled, these selectors perform complex transformations (iterating over accounts, assets, chains, computing checksummed addresses, parsing CAIP asset types, converting balances). This could impact: (1) Asset loading performance - getTokensControllerAllTokens, getTokenBalancesControllerTokenBalances, and getTokenRatesControllerMarketData are called on every render of the token list; (2) Account list rendering - getAccountTrackerControllerAccountsByChainId is used in account selector; (3) Swap performance - bridge/swap slice now uses migration selectors for rates and market data which adds computation to quote fetching flows.

View GitHub Actions results

@sonarqubecloud

sonarqubecloud Bot commented May 1, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
3.5% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@bergarces bergarces added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label May 1, 2026
@bergarces bergarces added this pull request to the merge queue May 1, 2026
Merged via the queue into main with commit 5c58a8c May 1, 2026
190 of 197 checks passed
@bergarces bergarces deleted the add-assets-migration-selectors branch May 1, 2026 14:41
@github-actions github-actions Bot locked and limited conversation to collaborators May 1, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.77.0 Issue or pull request that will be included in release 7.77.0 label May 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.77.0 Issue or pull request that will be included in release 7.77.0 size-XL skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-assets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants