Skip to content
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

feat: Add Chain Permissions #10650

Merged
merged 32 commits into from
Oct 18, 2024
Merged

feat: Add Chain Permissions #10650

merged 32 commits into from
Oct 18, 2024

Conversation

adonesky1
Copy link
Contributor

@adonesky1 adonesky1 commented Aug 14, 2024

Description

This PR introduces the Chain Permissions feature, allowing users to grant dapps explicit permissions to switch to specific networks. When the MM_CHAIN_PERMISSIONS feature flag is enabled, dapps requesting network changes via wallet_addEthereumChain or wallet_switchEthereumChain will prompt the user to add permission to access the specified chain IDs and, if granted, subsequent wallet_switchEthereumChain requests made to that chainId will not require user confirmation.

  • Added a new permission endowment:permitted-chains with the caveat restrictNetworkSwitching.
  • Updated wallet_addEthereumChain and wallet_switchEthereumChain methods to integrate with the new chain permissions.
  • Introduced environment variables MM_CHAIN_PERMISSIONS to toggle the feature.
  • Changed MULTICHAIN_V1 env variable to MM_PER_DAPP_SELECTED_NETWORK (more specific/accurate name)
  • Implemented validation functions for chain IDs and network parameters.

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/2883

Manual testing steps

  1. Enable the Chain Permissions feature by setting MM_CHAIN_PERMISSIONS and the new UI by setting MM_MULTICHAIN_V1_ENABLED with the watch script: MM_CHAIN_PERMISSIONS=1 MM_MULTICHAIN_V1_ENABLED=1 yarn watch:clean
  2. Navigate to a dapp and request a network switch to a chain ID not yet permitted.
  3. Observe that a permission prompt appears asking to grant access to the requested network.
  4. Approve the permission and verify that the network switch occurs successfully.
  5. Repeat the network switch request and confirm that no prompt appears, indicating the permission is saved.
  6. Attempt to switch to a different, unpermitted network and deny the permission. Verify that the network does not switch.

Screenshots/Recordings

Before

Switch Flow:

Screen.Recording.2024-10-10.at.9.56.01.AM.mov

Add Flow

Screen.Recording.2024-10-10.at.9.57.15.AM.mov

After

Connection + Switch Flow

The initial connection flow suggests that your granting network permissions too but that is not wired up yet.

Screen.Recording.2024-10-09.at.5.23.24.PM.mov

Add Flow

Screen.Recording.2024-10-10.at.9.14.12.AM.mov

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

sentry-io bot commented Aug 14, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: app/core/Permissions/specifications.js

Function Unhandled Issue
validateCaveatAccounts Error: eth_accounts error: Received unrecognized address: "".** accounts.forEach$argument_0(app/core/Permissions/...
Event Count: 10 Affected Users: 8

Did you find this useful? React with a 👍 or 👎

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.

@adonesky1 adonesky1 added the Run Smoke E2E Triggers smoke e2e on Bitrise label Oct 8, 2024
Copy link
Contributor

github-actions bot commented Oct 8, 2024

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: fca7f97
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/06880b8f-f315-43a4-9f47-fa4da1b25d3f

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

@adonesky1 adonesky1 added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 8, 2024
@adonesky1 adonesky1 force-pushed the ad/permitted-chains-permission branch from fca7f97 to a57fd4b Compare October 8, 2024 17:44
@adonesky1 adonesky1 added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 8, 2024
Copy link
Contributor

github-actions bot commented Oct 8, 2024

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: a57fd4b
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/64fd702a-0673-4ed0-a5dc-e8ef8787be54

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

@adonesky1 adonesky1 added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 8, 2024
Copy link
Contributor

github-actions bot commented Oct 9, 2024

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: fbfcf03
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/7001a36f-bc8b-4cb5-a569-abe5d15f542b

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

@adonesky1 adonesky1 added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 9, 2024
Copy link
Contributor

github-actions bot commented Oct 9, 2024

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: d767a31
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/7934f69d-d53d-4925-b5d5-87a157c39b77

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

@adonesky1 adonesky1 changed the title WIP: Adding Chain Permissions feature: Add Chain Permissions Oct 9, 2024
@adonesky1 adonesky1 added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 9, 2024
Copy link
Contributor

github-actions bot commented Oct 9, 2024

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 0317ca6
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/04f77b43-c59c-484b-b664-fcc557dc02c9

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

@adonesky1 adonesky1 added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 10, 2024
Copy link
Contributor

github-actions bot commented Oct 10, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: d9fe0be
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/3781d830-6bdb-4f7f-91de-af615a9aec91

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

@adonesky1 adonesky1 changed the title feature: Add Chain Permissions feat: Add Chain Permissions Oct 10, 2024
@adonesky1 adonesky1 marked this pull request as ready for review October 10, 2024 15:47
Copy link
Contributor

github-actions bot commented Oct 18, 2024

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 9e0e643
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/707b0653-06cd-4c06-b7fb-d92b846a68ca

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

@adonesky1 adonesky1 added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 18, 2024
Copy link
Contributor

@tommasini tommasini left a comment

Choose a reason for hiding this comment

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

Lets re run the e2e 🍀 lgtm!!

@adonesky1 adonesky1 added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 18, 2024
@sethkfman
Copy link
Contributor

@adonesky1 adonesky1 added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 18, 2024
Copy link
Contributor

github-actions bot commented Oct 18, 2024

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 0a66b14
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/975b70e6-bd57-44ab-bfcb-559402b52d71

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

@adonesky1 adonesky1 added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 18, 2024
@adonesky1 adonesky1 added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Oct 18, 2024
Copy link
Contributor

github-actions bot commented Oct 18, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: ddea8bc
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/4dbe78ad-7d2c-40be-b5af-3ed981021cc2

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

Copy link

sonarcloud bot commented Oct 18, 2024

@adonesky1 adonesky1 added this pull request to the merge queue Oct 18, 2024
Merged via the queue into main with commit 583c309 Oct 18, 2024
43 checks passed
@adonesky1 adonesky1 deleted the ad/permitted-chains-permission branch October 18, 2024 22:34
@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2024
@metamaskbot metamaskbot added the release-9.10.9 Issue or pull request that will be included in release 9.10.9 label Oct 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-9.10.9 Issue or pull request that will be included in release 9.10.9 Run Smoke E2E Triggers smoke e2e on Bitrise team-wallet-api-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants