You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: fix granted permissions when adding an existing network via wallet_addEthereumChain (#29837)
<!--
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**
Fixes bug with the automatically permittedChains permission grant when
triggered via wallet_addEthereumChain in certain scenarios. See ticket
for details.
[](https://codespaces.new/MetaMask/metamask-extension/pull/29837?quickstart=1)
## **Related issues**
Fixes: MetaMask/MetaMask-planning#3814
## **Manual testing steps**
1. Add a new network to the dapp via
[wallet_addEthereumChain](https://docs.metamask.io/wallet/reference/json-rpc-methods/wallet_addethereumchain/)
2. After approval, the dapp should also have
`endowment:permitted-chains` permission for the recently added chain via
`wallet_getPermissions`
3. switch the dapp to a different chain via the wallet UI
4. revoke dapp permissions via the wallet UI
6. Add a new network to the dapp via
[wallet_addEthereumChain](https://docs.metamask.io/wallet/reference/json-rpc-methods/wallet_addethereumchain/)
using a DIFFERENT rpc endpoint, but for the same chainId added in step 1
7. After approval, the dapp should also have
`endowment:permitted-chains` permission for the recently added chain via
`wallet_getPermissions`
8. switch the dapp to a different chain via the wallet UI
9. revoke dapp permissions via the wallet UI
10. Add a new network to the dapp via
[wallet_addEthereumChain](https://docs.metamask.io/wallet/reference/json-rpc-methods/wallet_addethereumchain/)
using the SAME rpc endpoint in step 1 (i.e. repeat step 1 exactly)
11. You should get an approval for chain switch, NOT network adding.
Approve it.
12. After approval, the dapp should also have
`endowment:permitted-chains` permission for the recently added chain via
`wallet_getPermissions`
## **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/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-extension/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.
---------
Co-authored-by: Alex Donesky <[email protected]>
describe('if the proposed networkConfiguration does not have a different rpcUrl from the one already in state',()=>{
267
-
it('should only switch to the existing networkConfiguration if one already exists for the given chain id',async()=>{
267
+
it('should only switch to the existing networkConfiguration if one already exists for the given chain id without auto approving the chain permission',async()=>{
Copy file name to clipboardExpand all lines: app/scripts/lib/rpc-method-middleware/handlers/ethereum-chain-utils.js
+5-5
Original file line number
Diff line number
Diff line change
@@ -165,20 +165,20 @@ export function validateAddEthereumChainParams(params) {
165
165
* @param {string} chainId - The chainId being switched to.
166
166
* @param {string} networkClientId - The network client being switched to.
167
167
* @param {object} hooks - The hooks object.
168
-
* @param {boolean} hooks.isAddFlow - The boolean determining if this call originates from wallet_addEthereumChain.
168
+
* @param {boolean} [hooks.autoApprove] - A boolean indicating whether the request should prompt the user or be automatically approved.
169
169
* @param {Function} hooks.setActiveNetwork - The callback to change the current network for the origin.
170
170
* @param {Function} hooks.getCaveat - The callback to get the CAIP-25 caveat for the origin.
171
171
* @param {Function} hooks.requestPermittedChainsPermissionForOrigin - The callback to request a new permittedChains-equivalent CAIP-25 permission.
172
172
* @param {Function} hooks.requestPermittedChainsPermissionIncrementalForOrigin - The callback to add a new chain to the permittedChains-equivalent CAIP-25 permission.
173
-
* @returns a null response on success or an error if user rejects an approval when isAddFlow is false or on unexpected errors.
173
+
* @returns a null response on success or an error if user rejects an approval when autoApprove is false or on unexpected errors.
174
174
*/
175
175
exportasyncfunctionswitchChain(
176
176
response,
177
177
end,
178
178
chainId,
179
179
networkClientId,
180
180
{
181
-
isAddFlow,
181
+
autoApprove,
182
182
setActiveNetwork,
183
183
getCaveat,
184
184
requestPermittedChainsPermissionForOrigin,
@@ -197,13 +197,13 @@ export async function switchChain(
describe('with an existing CAIP-25 permission granted from the legacy flow (isMultichainOrigin: false) and the chainId is not already permissioned',()=>{
90
-
it('requests a switch chain approval with autoApprove and switches to it if isAddFlow: true',async()=>{
79
+
it('requests a switch chain approval with autoApprove and switches to it if autoApprove: true',async()=>{
0 commit comments