Skip to content

Implement given instruction #6210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

amitabh94
Copy link
Contributor

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 within assets-controllers. This selector aggregates fiat-denominated balances for a given account group across both EVM and Solana accounts. It works by:

  1. Retrieving accounts within a specified entropySource (wallet ID) and groupIndex using the MultichainAccountService.
  2. Processing EVM account balances from TokenBalancesController, converting them to ETH via TokenRatesController, and then to the user's selected fiat currency via CurrencyRateController.
  3. Processing Solana account balances from MultichainBalancesController, converting them directly to fiat via MultichainAssetsRatesController.
  4. Returning a combined aggregatedBalance along with the groupId and currency.

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

  • Fixes ASSETS-1077
  • Related to ASSETS-1055
  • UI Design: Figma Link
  • Detailed implementation guide: packages/assets-controllers/SELECTOR_IMPLEMENTATION.md

Changelog

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, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to adopt any breaking changes

Open in Cursor Open in Web

Learn more about Cursor Agents

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