Implement given instruction #6210
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation
Currently, users cannot easily view their aggregated balances per account group in the Account List, requiring manual and complex calculations across different chains and assets. This leads to a suboptimal user experience and potential performance bottlenecks.
This PR introduces
selectBalancesByAccountGroup
, a new memoized Redux selector withinassets-controllers
. This selector aggregates fiat-denominated balances for a given account group across both EVM and Solana accounts. It works by:entropySource
(wallet ID) andgroupIndex
using theMultichainAccountService
.TokenBalancesController
, converting them to ETH viaTokenRatesController
, and then to the user's selected fiat currency viaCurrencyRateController
.MultichainBalancesController
, converting them directly to fiat viaMultichainAssetsRatesController
.aggregatedBalance
along with thegroupId
andcurrency
.The use of
MultichainAccountService
is crucial for accurately identifying and retrieving accounts belonging to a specific group, as it is the authoritative source for the wallet and account tree structure. The distinct rate controllers for EVM and Solana assets are necessary because their conversion paths to fiat differ.This change adds
reselect
as a dependency for memoization, which is essential for meeting the performance requirements (e.g., fast rendering and smooth scrolling). It also adds@metamask/multichain-account-service
as a peer dependency to enable access to account group data.References
packages/assets-controllers/SELECTOR_IMPLEMENTATION.md
Changelog
Checklist
Learn more about Cursor Agents