Skip to content

Conversation

@gantunesr
Copy link
Member

@gantunesr gantunesr commented Nov 22, 2024

Explanation

This PR adds a new controller to track the balance from non-EVM accounts by using the snaps as the data source.

References

Related to https://github.com/MetaMask/accounts-planning/issues/723

Changelog

@metamask/assets-controller

  • ADDED: New MultichainBalancesController to track the balance from non-EVM accounts by using the snaps as the data source

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 highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@gantunesr gantunesr marked this pull request as ready for review December 2, 2024 03:39
@gantunesr gantunesr requested a review from a team December 2, 2024 03:39
@gantunesr
Copy link
Member Author

@metamaskbot publish-previews

@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2024

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "20.0.0-preview-890d317c",
  "@metamask-previews/address-book-controller": "6.0.1-preview-890d317c",
  "@metamask-previews/announcement-controller": "7.0.1-preview-890d317c",
  "@metamask-previews/approval-controller": "7.1.1-preview-890d317c",
  "@metamask-previews/assets-controllers": "45.1.0-preview-890d317c",
  "@metamask-previews/base-controller": "7.0.2-preview-890d317c",
  "@metamask-previews/build-utils": "3.0.1-preview-890d317c",
  "@metamask-previews/chain-controller": "0.2.0-preview-890d317c",
  "@metamask-previews/composable-controller": "9.0.1-preview-890d317c",
  "@metamask-previews/controller-utils": "11.4.3-preview-890d317c",
  "@metamask-previews/ens-controller": "15.0.0-preview-890d317c",
  "@metamask-previews/eth-json-rpc-provider": "4.1.6-preview-890d317c",
  "@metamask-previews/gas-fee-controller": "22.0.1-preview-890d317c",
  "@metamask-previews/json-rpc-engine": "10.0.1-preview-890d317c",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.5-preview-890d317c",
  "@metamask-previews/keyring-controller": "19.0.0-preview-890d317c",
  "@metamask-previews/logging-controller": "6.0.2-preview-890d317c",
  "@metamask-previews/message-manager": "11.0.1-preview-890d317c",
  "@metamask-previews/multichain": "1.1.0-preview-890d317c",
  "@metamask-previews/name-controller": "8.0.1-preview-890d317c",
  "@metamask-previews/network-controller": "22.0.2-preview-890d317c",
  "@metamask-previews/notification-services-controller": "0.14.0-preview-890d317c",
  "@metamask-previews/permission-controller": "11.0.3-preview-890d317c",
  "@metamask-previews/permission-log-controller": "3.0.1-preview-890d317c",
  "@metamask-previews/phishing-controller": "12.3.0-preview-890d317c",
  "@metamask-previews/polling-controller": "12.0.1-preview-890d317c",
  "@metamask-previews/preferences-controller": "15.0.0-preview-890d317c",
  "@metamask-previews/profile-sync-controller": "2.0.0-preview-890d317c",
  "@metamask-previews/queued-request-controller": "8.0.0-preview-890d317c",
  "@metamask-previews/rate-limit-controller": "6.0.1-preview-890d317c",
  "@metamask-previews/remote-feature-flag-controller": "1.0.0-preview-890d317c",
  "@metamask-previews/selected-network-controller": "20.0.0-preview-890d317c",
  "@metamask-previews/signature-controller": "23.0.0-preview-890d317c",
  "@metamask-previews/transaction-controller": "41.0.0-preview-890d317c",
  "@metamask-previews/user-operation-controller": "20.0.0-preview-890d317c"
}

@gantunesr
Copy link
Member Author

@metamaskbot publish-previews

owencraston
owencraston previously approved these changes Dec 14, 2024
Copy link
Contributor

@cryptodev-2s cryptodev-2s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment on lines +26 to +38
/**
* Starts the tracking process.
*/
start(): void {
this.#poller.start();
}

/**
* Stops the tracking process.
*/
stop(): void {
this.#poller.stop();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an ideal world, we will expose these methods onto the client, so that polling loops can be started/stopped in UI based way.

Meaning that we only start polling loops on components that need Multichain balances (like the asset list). However, if a user pops open the extension to sign a transaction, we don't need to start this polling loop, to minimize requests and improve perf.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me get that working on a follow up PR

@socket-security
Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/bitcoin-address-validation@2.2.3 None +3 88.6 kB ruigomes

View full report↗︎

@gantunesr gantunesr merged commit c3b90a5 into main Jan 10, 2025
120 checks passed
@gantunesr gantunesr deleted the feat/add-multichain-balances branch January 10, 2025 21:50
github-merge-queue bot pushed a commit to MetaMask/metamask-mobile that referenced this pull request Jan 16, 2025
# **Description**

The primary purpose of this PR is to update the accounts controller and
the assets-controller to the latest version. In doing that, there were
several other package updates that were needed. Here is a summary of the
updates...


# 🔴  Major updates 🔴 

### "@metamask/accounts-controller": "^20.0.1" -> ^21.0.0
-
[changelog](https://github.com/MetaMask/core/blob/main/packages/accounts-controller/CHANGELOG.md#2100)
- Breaking changes
- BREAKING: Add scopes field to KeyringAccount
(MetaMask/core#5066),
(MetaMask/core#5136)
This field is now required and will be used to identify the supported
chains (using CAIP-2 chain IDs) for every accounts.
- Changes
- Bump @metamask/base-controller from ^7.0.0 to ^7.1.1
(MetaMask/core#5079),
(MetaMask/core#5135)
- Bump @metamask/utils to ^11.0.1
(MetaMask/core#5080)
- Bump @metamask/rpc-errors to ^7.0.2
(MetaMask/core#5080)
- Use new @metamask/keyring-internal-api@^1.0.0
(MetaMask/core#4695)
This package has been split out from the Keyring API.
- Bump @metamask/keyring-api from ^10.1.0 to ^12.0.0
(MetaMask/core#4695)
- Bump @metamask/eth-snap-keyring from ^5.0.1 to ^7.0.0
(MetaMask/core#4695)
ESM/CommonJS support.

### "@metamask/assets-controllers": "^45.1.1", ->  ^46.0.0",
-
[changelog](https://github.com/MetaMask/core/blob/main/packages/assets-controllers/CHANGELOG.md#4600)
- Breaking changes
- BREAKING: Bump @metamask/accounts-controller peer dependency from
^20.0.0 to ^21.0.0 (MetaMask/core#5140)
- Changes
- Remove use of @metamask/keyring-api
(MetaMask/core#4695)
@metamask/providers and webextension-polyfill peer dependencies are no
longer required.
- Use new @metamask/keyring-internal-api@^1.0.0
(MetaMask/core#4695)
This package has been split out from the Keyring API. Its types are
compatible with the @metamask/keyring-api package used previously.
- Bump @metamask/base-controller from ^7.0.0 to ^7.1.1
(MetaMask/core#5079),
(MetaMask/core#5135)
- Bump @metamask/keyring-api from ^12.0.0 to ^13.0.0
(MetaMask/core#5066)
- Bump @metamask/utils to ^11.0.1
(MetaMask/core#5080)
- Bump @metamask/rpc-errors to ^7.0.2
(MetaMask/core#5080)
- Added
- Add new MultichainBalancesController
(MetaMask/core#4965)
This controller has been migrated from the MetaMask extension codebase.

### "@metamask/utils": "^10.0.1" -> ^11.0.1"
-
[changelog](https://github.com/MetaMask/utils/blob/main/CHANGELOG.md#1101)
- breaking changes
- BREAKING: generateRandomMnemonic now returns Promise<void> instead of
void (MetaMask/utils#222)

### Added "@metamask/keyring-internal-api": "^2.0.0",
-
[changelog](https://github.com/MetaMask/accounts/blob/main/packages/keyring-internal-api/CHANGELOG.md#200)
- This package was a peer dep on the latest accounts controller and
assets controller. Given this I figured we should add it now anyway.
- Changes needed
- update imports from `@metamask/keyring-api` to
`@metamask/keyring-internal-api`
   - add support for scopes in the InternalAccount object
- added migration (066.ts) to backfill the scopes to existing accounts.
- This change is based off a [similar change made in the
extension](MetaMask/metamask-extension#29195)
made by @ccharly

### Added @metamask/keyring-snap-client: "^2.0.0"
-
[changelog](https://github.com/MetaMask/accounts/blob/main/packages/keyring-snap-client/CHANGELOG.md#200)
- Added because KeyringClient is now exported from
`@metamask/keyring-snap-client` instead of `@metamask/keyring-api'`. See
`app/components/Views/AddAccountActions/AddAccountActions.tsx` for
changes.

### "@metamask/keyring-api": "^10.1.0", -> ^13.0.0"
-
[changelog](https://github.com/MetaMask/accounts/blob/main/packages/keyring-api/CHANGELOG.md#1300)
- Breaking changes
- BREAKING: Add scopes field to KeyringAccount
(MetaMask/accounts#101)
- BREAKING: Split into several smaller packages
(MetaMask/accounts#24)
        - This should improve dependencies management.
- Internal related types (internal to both clients) have been moved to
keyring-internal-* packages.
- Keyring API clients (mainly used by dapps) have been moved to
keyring-snap-client package.
        - Common utils have been moevd to keyring-utils package.

### "@metamask/eth-snap-keyring": "^5.0.1" -> ^7.0.0"
-
[changelog](https://github.com/MetaMask/accounts/blob/main/packages/keyring-eth-simple/CHANGELOG.md#700)
- breaking changes
- BREAKING: Increase minimum Node.js version to 16
(MetaMask/eth-simple-keyring#152)
- BREAKING: Bump @metamask/eth-sig-util from ^6.0.1 to ^7.0.0
(MetaMask/eth-simple-keyring#156)
- Bump @metamask/utils from ^5.0.0 to ^8.1.0
(MetaMask/eth-simple-keyring#153)
- Bump ethereum-cryptography from ^1.2.0 to ^2.1.2
(MetaMask/eth-simple-keyring#153)
- BREAKING: Bump @metamask/eth-sig-util dependency from ^7.0.3 to ^8.0.0
(MetaMask/accounts#79)
- signTypedData no longer support number for addresses, see
[here](https://github.com/MetaMask/eth-sig-util/blob/main/CHANGELOG.md#800).

## 🟡 Minor updates 🟡 

### "@metamask/base-controller": "^7.0.1", -> ^7.1.1
-
[changelog](https://github.com/MetaMask/core/blob/main/packages/base-controller/CHANGELOG.md#711)
- Changes
    -  Bump @metamask/utils from ^10.0.0 to ^11.0.1
- Rename ControllerMessenger to Messenger
(MetaMask/core#5050)
        - ControllerMessenger has been renamed to Messenger
- RestrictedControllerMessengerConstraint has been renamed to
RestrictedMessengerConstraint
- RestrictedControllerMessenger has been renamed to RestrictedMessenger
- The RestrictedMessenger constructor parameter controllerMessenger has
been renamed to messenger, though the old name is still accepted
- The old names remain exported as deprecated aliases of the new names,
so this is not a breaking change.

### "@metamask/providers": "^18.1.0" -> ^18.3.1"
-
[changelog](https://github.com/MetaMask/providers/blob/main/CHANGELOG.md#1831)
- Changes
- Bump @metamask/json-rpc-engine from ^10.0.1 to ^10.0.2
(MetaMask/providers#397)
- Bump @metamask/json-rpc-middleware-stream from ^8.0.5 to ^8.0.6
(MetaMask/providers#397)
- Bump @metamask/rpc-errors from ^7.0.1 to ^7.0.2
(MetaMask/providers#397)
- Bump @metamask/utils from ^10.0.0 to ^11.0.1
(MetaMask/providers#397)


## 🟢  Patch updates 🟢 

### "@metamask/json-rpc-engine": "^10.0.0" -> ^10.0.2",
-
[changelog](https://github.com/MetaMask/core/blob/main/packages/json-rpc-engine/CHANGELOG.md#1002)

### "@metamask/json-rpc-middleware-stream": "^8.0.2" -> 8.0.6"
-
[changelog](https://github.com/MetaMask/core/blob/main/packages/json-rpc-middleware-stream/CHANGELOG.md#806)
- changed
- Bump @metamask/json-rpc-engine from ^10.0.1 to ^10.0.2
(MetaMask/core#5082)
- Bump @metamask/utils from ^10.0.0 to ^11.0.1
(MetaMask/core#5080)

### "@metamask/rpc-errors": "^7.0.1" -> ^7.0.2"
-
[changelog](https://github.com/MetaMask/rpc-errors/blob/main/CHANGELOG.md#702)
- changes
- Bump @metamask/utils from ^10.0.0 to ^11.0.1
(MetaMask/rpc-errors#166)


## **Related issues**

Fixes: #12967
Fixes: #12966

Fixes: MetaMask/accounts-planning#758

Unblocks: #12599

## **Manual testing steps**

#### Basic import account flow with tokens


https://github.com/user-attachments/assets/1a8d3e59-34e4-413e-a3e8-7dbdc5f7424a



## **Screenshots/Recordings**

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

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] 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).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] 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**

- [ ] 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.
github-merge-queue bot pushed a commit to MetaMask/metamask-mobile that referenced this pull request Feb 7, 2025
## **Description**
Builds off of the work done in [this
PR](MetaMask/core#4965).

- This PR adds the ability to see your non EVM token balance and the
fiat token rates (Solana and Bitcoin accounts)
- This is achieved by using the RatesController and the
MultichainBalanceController
- This PR also extract the balance logic from the PortfolioBalance PR
into the useMultichainBalances hook
- creates the selectors for multichain non evm

This PR DOES NOT...
1. show the correct native token balance in the account picker. This
will be done in a [following
PR](MetaMask/accounts-planning#697) that
builds off of this work.
2. enable token details for these non evm assets. (for now it will
simply show no data)

## **Related issues**

Fixes: MetaMask/accounts-planning#696

## **Manual testing steps**

1. checkout this branch
3. open .js.env
4. set export METAMASK_BUILD_TYPE="flask" // flask
5. source .js.env
6. yarn setup
7. yarn start:ios
8. create/import a wallet
9. open the account menu actions
10. you should see that you can add a BTC and BTC Testnet account
11. click Add a new Bitcoin account (Beta)
12. a popup with a suggested name should appear click confirm
13. the newly selected account should be your Bitcoin account and the
network picker should show the Bitcoin logo the network should not be
clickable
14. Optionally, create a testnet account and fund it with this faucet:
https://bitcoinfaucet.uo1.net/
15. If you have a balance, you should see the fiat balance rendered on
the wallet
16. if not you have a balance, then you should see a 0 fiat balance.
17. If you change your selected currency (settings/general) and then
return to the main wallet view, the balance should update based on the
new fiat currency.
18. The token list should also list your account balance in both fiat
and and the native token balance.
19. the token displayed should be the BTC logo and not have any network
badge above it (like the eth account does)
20. now add a bitcoin TestNet account.
21. the portfolio balance should show the native token balance not the
fiat balance.
22. repeat the above steps but this time add a new Solana account. If
your Solana account has a balance, it should be rendered on the home
page in fiat. If not you should see a 0 balance.
23. we do not currently support Solana testnet accounts.


## **Screenshots/Recordings**

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

### **Before**

<!-- [screenshots/recordings] -->

### **After**


https://github.com/user-attachments/assets/12d4bfeb-608f-4744-9c0a-459163eb0dba



<img
src="https://github.com/user-attachments/assets/f8428b91-fb45-433d-921e-3824845a71ef"
height="400" height="600"/>



## **Pre-merge author checklist**

- [ ] 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).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] 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**

- [ ] 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants