Skip to content

feat: use migration selectors for new assets controller#26975

Closed
bergarces wants to merge 66 commits into
mainfrom
assets-selectors-account-tracker-controller
Closed

feat: use migration selectors for new assets controller#26975
bergarces wants to merge 66 commits into
mainfrom
assets-selectors-account-tracker-controller

Conversation

@bergarces
Copy link
Copy Markdown
Contributor

@bergarces bergarces commented Mar 4, 2026

Description

Changelog

CHANGELOG entry:

Related issues

Fixes:

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

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
Changes how EVM native balances are sourced for multiple consumers when assetsUnifyState is enabled, which could affect balance-dependent UI/metrics if the derived mapping is wrong. Also bumps @metamask/assets-controller (and transitive deps), increasing integration risk.

Overview
selectAccountsByChainId is refactored to support the Assets Unify State migration. A new selector (getAccountTrackerControllerAccountsByChainId) returns the legacy AccountTrackerController.accountsByChainId when the assetsUnifyState flag is off, but when on it derives an accountsByChainId-shaped map from AssetsController native balances (keyed by CAIP asset ids) and AccountsController internal accounts.

Transaction gas metrics (metrics_properties/gas.ts) now read native balance via selectAccountsByChainId instead of directly accessing engine background state, and the account-tracker selectors are updated to use/re-export the new migration selector. @metamask/assets-controller is upgraded to ^2.2.0 (with corresponding yarn.lock updates).

Written by Cursor Bugbot for commit 1413fd1. This will update automatically on new commits. Configure here.

@bergarces bergarces requested review from a team as code owners March 4, 2026 10:27
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 4, 2026

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.

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

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.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Comment thread app/selectors/assets/assets-migration.ts Outdated
@bergarces bergarces marked this pull request as draft March 4, 2026 11:50
@github-actions github-actions Bot added size-XL and removed size-M labels Mar 16, 2026
@github-actions github-actions Bot added the risk-high Extensive testing required · High bug introduction risk label Mar 16, 2026
@github-actions github-actions Bot added risk-high Extensive testing required · High bug introduction risk and removed risk-high Extensive testing required · High bug introduction risk labels Mar 17, 2026
@bergarces bergarces changed the title account tracker controller selector feat: migration selectors for new assets controller Mar 17, 2026
@github-actions github-actions Bot added risk-high Extensive testing required · High bug introduction risk and removed risk-high Extensive testing required · High bug introduction risk labels Mar 17, 2026
@bergarces bergarces marked this pull request as ready for review March 17, 2026 10:17
@bergarces bergarces requested review from a team as code owners March 17, 2026 10:17
@bergarces bergarces marked this pull request as draft March 17, 2026 10:18
@bergarces bergarces changed the base branch from main to add-assets-migration-selectors April 28, 2026 15:27
@github-actions github-actions Bot added size-M and removed size-XL labels Apr 28, 2026
@bergarces bergarces force-pushed the add-assets-migration-selectors branch from f3d2958 to 0246d21 Compare April 28, 2026 15:34
@bergarces bergarces changed the title feat: migration selectors for new assets controller feat: use migration selectors for new assets controller Apr 30, 2026
Base automatically changed from add-assets-migration-selectors to main May 1, 2026 14:41
@bergarces bergarces dismissed Prithpal-Sooriya’s stale review May 1, 2026 14:41

The base branch was changed.

@bergarces bergarces marked this pull request as ready for review May 4, 2026 21:42
@bergarces bergarces marked this pull request as draft May 4, 2026 21:42
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeConfirmations, SmokeWalletPlatform, SmokeMoney, SmokeSwap, SmokeStake, SmokeAccounts
  • Selected Performance tags: @PerformanceAccountList, @PerformanceAssetLoading
  • Risk Level: medium
  • AI Confidence: 82%
click to see 🤖 AI reasoning details

E2E Test Selection:

The PR refactors state access patterns in three key areas:

  1. Engine.ts getTotalEvmFiatAccountBalance(): Migrated from direct controller state access (CurrencyRateController.state, AccountTrackerController.state, TokenRatesController.state, TokensController.state, TokenBalancesController.state) to Redux selectors via assets-migration selectors. This function is called in:

    • app/components/Views/confirmations/hooks/useAccountInfo.ts → affects SmokeConfirmations
    • app/components/hooks/useMultichainBalances/utils.ts → affects SmokeWalletPlatform (balance display)
    • app/components/hooks/useAccounts/useAccounts.ts → affects SmokeAccounts (account list balances)
    • Engine itself for analytics tracking
  2. gas.ts (TransactionController metrics): getNativeBalance() now uses selectAccountsByChainId selector instead of direct AccountTrackerController state access. This affects gas metrics properties in transaction flows → SmokeConfirmations.

  3. useAssetBalances.tsx (Card hook): Migrated from Engine.context.MultichainAssetsRatesController and Engine.context.TokenRatesController direct access to Redux selectors. This hook is used in Card home and asset selection flows → SmokeMoney.

The assets-migration selectors use a feature flag (isAssetsUnifyStateEnabled) that can change behavior between old and new asset state structures. If the selector returns different data than direct controller access (e.g., due to the feature flag being enabled), balance calculations could be incorrect across multiple flows.

Tag justification:

  • SmokeConfirmations: getTotalEvmFiatAccountBalance is used in confirmation hooks; gas metrics refactored
  • SmokeWalletPlatform: Multichain balance display uses getTotalEvmFiatAccountBalance; transaction history and balance display affected
  • SmokeMoney: useAssetBalances hook directly changed; Card flows depend on this for asset balance display
  • SmokeSwap: Per SmokeMoney tag description, when Card Add Funds flows execute swaps, SmokeSwap should also be selected; also SmokeSwap uses balance data
  • SmokeStake: Balance calculations affect staked ETH display via getTotalEvmFiatAccountBalance (includes stakedBalance)
  • SmokeAccounts: useAccounts hook uses getTotalEvmFiatAccountBalance for account balance display in account selector

Performance Test Selection:
The refactoring of getTotalEvmFiatAccountBalance to use Redux selectors (which include deep-equal memoized selectors via createDeepEqualSelector) could affect rendering performance. The assets-migration selectors add computation overhead for the feature flag check and potential data transformation. @PerformanceAccountList is relevant because useAccounts hook uses getTotalEvmFiatAccountBalance for balance display in the account selector. @PerformanceAssetLoading is relevant because the useAssetBalances hook refactoring affects token balance and market data loading in the Card component, and the migration selectors for TokensController, TokenRatesController, CurrencyRateController, and TokenBalancesController are now used in more places.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 4, 2026

@bergarces bergarces marked this pull request as ready for review May 5, 2026 09:08
@bergarces bergarces marked this pull request as draft May 5, 2026 09:08
@bergarces bergarces closed this May 5, 2026
@bergarces bergarces deleted the assets-selectors-account-tracker-controller branch May 5, 2026 15:51
@github-actions github-actions Bot locked and limited conversation to collaborators May 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

risk-high Extensive testing required · High bug introduction risk size-M team-assets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants