Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Chain Permissions (#10650)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **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: MetaMask/MetaMask-planning#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` 3. Navigate to a dapp and request a network switch to a chain ID not yet permitted. 4. Observe that a permission prompt appears asking to grant access to the requested network. 5. Approve the permission and verify that the network switch occurs successfully. 6. Repeat the network switch request and confirm that no prompt appears, indicating the permission is saved. 7. Attempt to switch to a different, unpermitted network and deny the permission. Verify that the network does not switch. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ## **Before** ### Switch Flow: https://github.com/user-attachments/assets/cc0ecee6-79c1-40ed-85a7-cb3effed4acb ### Add Flow https://github.com/user-attachments/assets/4d988a80-a020-49b4-89a5-527884a16558 ## **After** ### Connection + Switch Flow The initial connection flow suggests that your granting network permissions too but that is not wired up yet. https://github.com/user-attachments/assets/4a5ba93a-4de4-411e-97c3-abd4794e0539 ### Add Flow https://github.com/user-attachments/assets/41e22694-6aa5-444b-8231-7fccad942465 ## **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.
- Loading branch information