MetaMask / metamask-mobile

Mobile web browser providing access to websites that use the Ethereum blockchain
https://metamask.io
Other
2.17k stars 1.12k forks source link

Feat: Bitcoin wallet overview (Flask Only) #12294

Open owencraston opened 1 week ago

owencraston commented 1 week ago

Description

This PR does enables the creation of Bitcoin (Mainnet and Testnet) accounts on MetaMask mobile. This is done via the snap-bitcoin-wallet which is included as a preinstalled snap. The added UI buttons to the account actions communicate with the snap, then the snap is routed through our SnapKeyring handlers to enable custom account names.

This is just the first step and does not include all of the necessary logic/UI to launch this feature. This PR simply enables Bitcoin account creation and renders the proper BTC address and network in the wallet view.

How

Related issues

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

Manual testing steps

Adding a Bitcoin Testnet account

  1. open .js.env and ensure that METAMASK_BUILD_TYPE is set to flask
  2. run the app on this branch
  3. complete onboarding
  4. click on your account
  5. the account list menu should open with a CTA to add a new account
  6. click Add account or hardware wallet
  7. then click Add a new Bitcoin Account (Testnet)
  8. a bottom sheet should open with a text field pre filled with Bitcoin Testnet Account
  9. click Add account
  10. the account should be added and selected on the wallet view.
  11. if you go through the same steps (steps 4-6) the option to add a Bitcoin testnet account should be disabled since you can only have one BTC Test account.
  12. Now that you are on the wallet view, verify that the address is rendered in short form i.e tb1qcv...4av3
  13. you will not see a balance rendered for this account since BTC balances are not yet supported.
  14. verify that the network that is displayed on the wallet view shows the Bitcoin logo and that when you click it nothing happens.
  15. verify that when clicking on the actions button in the bottom tab bar opens a list of actions that are disabled (send, swap, bridge etc). All of these features should be disabled for BTC
  16. click on your account, when the account list opens up select one of your ethereum accounts.
  17. the Balance should render and the network should display the ethereum network.
  18. clicking on the network picker DOES open the network selector list

Adding a Bitcoin Mainnet account

  1. open .js.env and ensure that METAMASK_BUILD_TYPE is set to flask
  2. run the app on this branch
  3. complete onboarding
  4. click on your account
  5. the account list menu should open with a CTA to add a new account
  6. click Add account or hardware wallet
  7. then click Add a new Bitcoin Account (Beta)
  8. a bottom sheet should open with a text field pre filled with Bitcoin Account
  9. click Add account
  10. the account should be added and selected on the wallet view.
  11. if you go through the same steps (steps 4-6) the option to add a Bitcoin Account should be disabled since you can only have one BTC mainnet account.
  12. Now that you are on the wallet view, verify that the address is rendered in short form i.e bc1qrw...atay
  13. you will not see a balance rendered for this account since BTC balances are not yet supported.
  14. verify that the network that is displayed on the wallet view shows the Bitcoin logo and that when you click it nothing happens.
    1. verify that when clicking on the actions button in the bottom tab bar opens a list of actions that are disabled (send, swap, bridge etc). All of these features should be disabled for BTC
  15. click on your account, when the account list opens up select one of your ethereum accounts.
  16. the Balance should render and the network should display the ethereum network.
  17. clicking on the network picker DOES open the network selector list

Verify ETH account address formats

  1. assuming you completed the above testing steps...
  2. select your ethereum account from the account list
  3. verify that when selected, the address is rendered in checksummed format WITH a 0z prefix.

Screenshots/Recordings

Before

N/A

After

https://github.com/user-attachments/assets/96836574-7b12-4566-b70f-ea85efa3b663

Pre-merge author checklist

Pre-merge reviewer checklist

github-actions[bot] commented 1 week ago

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.

socket-security[bot] commented 1 week ago

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

Package New capabilities Transitives Size Publisher
npm/@metamask/bitcoin-wallet-snap@0.8.2 network 0 1.61 MB gudahtt
npm/base58-js@1.0.5 None 0 9.65 kB pur3miish
npm/bitcoin-address-validation@2.2.3 None 0 35.5 kB ruigomes
npm/sha256-uint8array@0.10.7 None 0 33.2 kB kawanet

View full report↗︎

socket-security[bot] commented 1 week ago

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSourceCI
New author npm/@metamask/bitcoin-wallet-snap@0.8.2 🚫
Unstable ownership npm/@metamask/bitcoin-wallet-snap@0.8.2 🚫
Network access npm/@metamask/bitcoin-wallet-snap@0.8.2 🚫

View full report↗︎

Next steps

What is new author?

A new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.

Scrutinize new collaborator additions to packages because they now have the ability to publish code into your dependency tree. Packages should avoid frequent or unnecessary additions or changes to publishing rights.

What is unstable ownership?

A new collaborator has begun publishing package versions. Package stability and security risk may be elevated.

Try to reduce the amount of authors you depend on to reduce the risk to malicious actors gaining access to your supply chain. Packages should remove inactive collaborators with publishing rights from packages on npm.

What is network access?

This module accesses the network.

Packages should remove all network access that is functionally unnecessary. Consumers should audit network access to ensure legitimate use.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/foo@1.0.0 or ignore all packages with @SocketSecurity ignore-all

  • @SocketSecurity ignore npm/@metamask/bitcoin-wallet-snap@0.8.2
sonarcloud[bot] commented 18 hours ago

Quality Gate Passed Quality Gate passed

Issues
3 New issues
0 Accepted issues

Measures
0 Security Hotspots
69.1% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

github-actions[bot] commented 17 hours ago

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 389d496c85c48f129cbed51c88886c0f76c829ce Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/c0392760-05eb-42f2-915b-376cab548fdb

[!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