Skip to content

feat: Multichain account list balance #14278

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

Merged
merged 16 commits into from
Apr 11, 2025
Merged

Conversation

owencraston
Copy link
Contributor

@owencraston owencraston commented Mar 27, 2025

Description

This PR enables the account balances for non evm accounts (Solana) to be renders in the Account Selector List. This change was achieved by leveraging the existing logic in the useMultichainBalances hook which is already used in production to display both evm and non evm account balances for the selected account on the main wallet page. I had to expand this logic to not only derive the balance for the selected account on the selected chain but instead to derive the balances for all accounts. This way we can lookup the MultichainBalancesData (defined in useMultichainBalances.types.ts) in a map where the key is the account ID. The key changes that enabled this change were the following...

  1. multichain.ts

    • refactor some of the balance selector to use util functions so that they could be reused.
    • created a new selector called selectMultichainNetworkAggregatedBalanceForAllAccounts which, uses the same logic as selectSelectedAccountMultichainNetworkAggregatedBalance except for all accounts and returns a map of account ids and MultichainNetworkAggregatedBalance
  2. useMultichainBalances.ts

    • modified the return type of this hook so that it returns a map of account balance data and account ids as well as one single object for the selected account. The return type looks like this...
export interface UseMultichainBalancesHook {
  multichainBalancesForAllAccounts: Record<
    InternalAccount['id'],
    MultichainBalancesData
  >;
  selectedAccountMultichainBalance?: MultichainBalancesData;
}
  • I also had to decouple the the hook from the currently selected chainId. This means that we must select the evmChainId (either currently selected or previously selected chainId), and the nonEvmChainId (either currently selected or previously selected)
  1. useAccounts.ts

    • removed all of the balance computation inside the useAccounts hook (mostly through the getAccountBalances util that I removed) in favour of the results from the useMultichainBalances hook.
    • Memoized many of the functions in this hook.
  2. Engine.ts

    • renamed getTotalFiatAccountBalance to getTotalEvmFiatAccountBalance
    • Modified getTotalEvmFiatAccountBalance to take an optional InternalAccount param that allows this function to derive the evm balance for a specified account not just the currently selected account
    • Modified the getTotalEvmFiatAccountBalance to use TokenController.allTokens instead of TokenController.tokens which is tied to the currently selected account

Related issues

Fixes: https://github.com/MetaMask/accounts-planning/issues/697

Manual testing steps

  1. ensure you are building flask by verifying that your .js.env file contains export METAMASK_BUILD_TYPE="flask"
  2. yarn setup && yarn start:ios
  3. Import an account that has a balance, I can provide you with an SRP from 1Password if needed.
  4. click on "add account or hardware wallet"
  5. click on Solana account
  6. Once the account is created, open the account selector list
  7. The balance that is rendered on the right side of the the cell should match the balance rendered on the main wallet view. It should show your total fiat balance which is the sum of all of your native tokens (ETH/SOL) plus the sum of all of your token balances (ERC20/SPL tokens). This fiat balance should be in your currently selected currency and it should also show your native token balance.
  8. Changing your selected account between non evm and evm should not change the balances you see in the account list.
  9. Both EVM and Solana balances should be correct
  10. changing your selected currency should be reflected in balance in the accounts list.
  11. If you switch the network to a test net, the fiat balance should not be rendered and instead you should see your token balance.

Screenshots/Recordings

Before

ScreenRecording_04-02-2025.17-31-27_1.MP4

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.

Copy link
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.

@owencraston owencraston force-pushed the feat/account-list-balance branch 3 times, most recently from 55f44b0 to 63b88f3 Compare March 31, 2025 17:28
@owencraston owencraston force-pushed the feat/account-list-balance branch 3 times, most recently from 82cb9be to add3081 Compare April 1, 2025 21:11
github-merge-queue bot pushed a commit that referenced this pull request Apr 2, 2025
## **Description**

This PR provides a temporary fix for an issue where the Solana account
balances appear as "0 ETH" in the account selector list. A proper fix
that renders the correct Soalana fiat/token balance in this list is
being worked on
[here](#14278) but for
the sake of speed and to unblock the RC 7.44.0, we are going to simply
hide this incorrect value. This approach was disussed and confirmed with
Rizivi this morning.

The plan for this change to be cherry picked into rc 7.44.0 once it
merges.

## **Related issues**

Fixes: #14332

## **Manual testing steps**

1. ensure you are building flask by verifying that your `.js.env` file
contains `export METAMASK_BUILD_TYPE="flask"`
2. yarn setup && yarn start:ios
3. create or import a wallet
4. click on the account selector list
5. click on add account of hardware wallet
6. click on solana account
7. notice that there is no data at all in the right section of the
account selector list
8. if you select the solana account, it should still render your balance
in the main wallet page.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**


![image](https://github.com/user-attachments/assets/3b3b31bb-19e9-40b6-8fe2-8e0e1fda4599)


### **After**

<image
src="https://github.com/user-attachments/assets/e6214357-c1a0-4087-b051-ca7224b8d444"
height="700" width="350" />



https://github.com/user-attachments/assets/513bd567-8473-47b3-9cdc-3f29ddd6d496



## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] 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.
@owencraston owencraston force-pushed the feat/account-list-balance branch 5 times, most recently from 8497609 to 06f9108 Compare April 2, 2025 23:54
@owencraston owencraston marked this pull request as ready for review April 3, 2025 02:30
@owencraston owencraston requested review from a team as code owners April 3, 2025 02:30
@owencraston owencraston added the Run Smoke E2E Triggers smoke e2e on Bitrise label Apr 3, 2025
Copy link
Contributor

github-actions bot commented Apr 3, 2025

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 87f3d10
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/653cece3-9639-4aca-ac9b-84adcaf1ef22

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

@owencraston owencraston added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Apr 3, 2025
@owencraston owencraston force-pushed the feat/account-list-balance branch from 87f3d10 to 1cf5378 Compare April 3, 2025 16:36
@owencraston owencraston added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Apr 3, 2025
Copy link
Contributor

github-actions bot commented Apr 3, 2025

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 1cf5378
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/c9d61a1e-0015-46ed-9710-e08082b3afb1

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

@owencraston owencraston force-pushed the feat/account-list-balance branch from 0d22750 to 232cf50 Compare April 11, 2025 02:31
@owencraston owencraston added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Apr 11, 2025
Copy link
Contributor

github-actions bot commented Apr 11, 2025

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 232cf50
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/4409963f-4aad-4c15-8f34-c85ecda04142

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@owencraston owencraston added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Apr 11, 2025
@owencraston owencraston added this pull request to the merge queue Apr 11, 2025
Merged via the queue into main with commit 62a9a42 Apr 11, 2025
55 of 58 checks passed
@owencraston owencraston deleted the feat/account-list-balance branch April 11, 2025 17:29
@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2025
@metamaskbot metamaskbot added the release-7.46.0 Issue or pull request that will be included in release 7.46.0 label Apr 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-7.46.0 Issue or pull request that will be included in release 7.46.0 Run Smoke E2E Triggers smoke e2e on Bitrise team-accounts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants