-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jl/caip multichain/fix connection flow for permitted chains (#27471)
<!-- 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** Connects the new AmonHenV2 Connection Flow to CAIP Multichain: * Preserves and syncs eth accounts across eip155 scopes when permitted chains are changed * Grants full methods and notifications to scopeObject when a new chain is permitted * `ConnectPage` Approval now uses the caveat values from eth_accounts and endowment:permitted-chains as the default selected account and chains * `wallet_createSession` passes a list of supported eth accounts and eth chainIds based on the supported scopes to be used as the preselected/default values in the ConnectPage Approval * `wallet_createSession` removes supported eip155 scopes that were not approved and adds ones that were not in the original request but were approved [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27471?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** Replace the account addresses below with your own addresses to test the preselected accounts. This request should preselect mainnet and sepolia (which is different from the default which preselects all non testnet networks) ``` const EXTENSION_ID = 'nonfpcflonapegmnfeafnddgdniflbnk'; const extensionPort = chrome.runtime.connect(EXTENSION_ID) extensionPort.onMessage.addListener((msg) => console.log('extensionPort on message', msg)) extensionPort.postMessage({ type: 'caip-x', data: { "jsonrpc": "2.0", method: 'wallet_createSession', params: { requiredScopes: { 'eip155': { references: ['1', '11155111'], methods: [ 'eth_sendTransaction', 'eth_getBalance', 'eth_subscribe' ], notifications: ['eth_subscription'], accounts: ['eip155:1:0x5bA08AF1bc30f17272178bDcACA1C74e94955cF4', 'eip155:1:0xdeadbeef', 'eip155:1:0x398fC6Ec25889e7373310dC4c3491b18575d5d6B'] } }, optionalScopes: { }, sessionProperties: { 'caip154-mandatory': 'true', }, }, } }) ``` replace this with your own address to test preselected accounts. ``` "method": "wallet_requestPermissions", "params": [ { eth_accounts: { caveats: [ { type: 'restrictReturnedAccounts', value: ['0x5bA08AF1bc30f17272178bDcACA1C74e94955cF4'] } ] } } ], }); ``` This one works for preselecting chains ``` "method": "wallet_requestPermissions", "params": [ { 'endowment:permitted-chains': { caveats: [ { type: 'restrictNetworkSwitching', value: ['0x1'] } ] } } ], }); ``` You can also combine the params of these two wallet_requestPermissions examples One for eth_requestAccounts ``` await window.ethereum.request({ "method": "eth_requestAccounts", "params": [], }); ``` And of course you can connect via the wallet UI directly. ## **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 Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.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-extension/blob/develop/.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
Showing
18 changed files
with
278 additions
and
494 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.