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

fix(cherry-pick): Fix wallet_addEthereumChain/wallet_switchEthereumChain error handling bug #25339

Merged
merged 1 commit into from
Jun 14, 2024

Conversation

adonesky1
Copy link
Contributor

@adonesky1 adonesky1 commented Jun 14, 2024

Description

A bug was introduced in #24415, where user rejected request errors are not correctly handled in either wallet_switchEthereumChain nor wallet_addEthereumChain calls.

At first we thought his just resulted in incorrect errors being returned to dapps when users clicked cancel on wallet_switchEthereumChain calls but it turns out this incorrect error handling results in very strange and severe bugs when subsequent requests are enqueued in the QueuedRequestController - the functionality of which is turned on by default in release v12.0.0. See the Before video below.

Open in GitHub Codespaces

Related issues

See: https://consensys.slack.com/archives/CTQAGKY5V/p1718385169900809?thread_ts=1718140104.578969&cid=CTQAGKY5V

Manual testing steps

(have gnosis chain added to the wallet)

  1. Go to https://metamask.github.io/test-dapp/ and connect
  2. Go to https://docs.metamask.io/wallet/reference/wallet_switchethereumchain/
  3. Submit the switch chain request on the dapp but do not confirm or reject the confirmation
  4. Go back to https://metamask.github.io/test-dapp/
  5. Click Send EIP-1559 Transaction, see that the badge number in the MM tray icon increments
  6. Open the pop up and cancel the still pending switchChain confirmation
  7. You should see the transactions you initiated on https://metamask.github.io/test-dapp/ pop up now

Screenshots/Recordings

Before

Screen.Recording.2024-06-14.at.12.13.41.PM.mov

After

Screen.Recording.2024-06-14.at.2.32.04.PM.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.

…ed in either wallet_switchEthereumChain nor wallet_addEthereumChain calls (#25269)

## **Description**

A bug was introduced in
#24415, where user
rejected request errors are not correctly handled in either
`wallet_switchEthereumChain` nor `wallet_addEthereumChain` calls.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25269?quickstart=1)

## **Related issues**

Fixes: Regression in API error handling found on a local run of [the new
API testing
tool](#24132), will
link report when available.

## **Manual testing steps**

**wallet_addEthereumChain**
1. Go to
https://docs.metamask.io/wallet/reference/wallet_addethereumchain/
2. Submit the prepopulated `wallet_addEthereumChain` request
3. Confirm the request to add Gnosis Chain
4. But click "Cancel" on the second request to switch to the newly added
chain
5. You should see `null` as the response

**wallet_switchEthereumChain**
1. Make sure the wallet is on a chain other than gnosis
2. Go to
https://docs.metamask.io/wallet/reference/wallet_switchethereumchain/
3. Submit the prepopulated switchEthereumChain request (for chainId:
0x64)
4. Click cancel on the request to switch to gnosis chain
5. you should see:
```
{
  "code": 4001,
  "message": "User rejected the request.",
  "stack": "{\n  \"code\": 4001,\n  \"message\": \"User rejected the request.\",\n  \"stack\": \"Error: User rejected the request.\\n  
 }
 ```
 in the response


## **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.
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 marked this pull request as ready for review June 14, 2024 19:36
@adonesky1 adonesky1 requested a review from a team as a code owner June 14, 2024 19:36
@danjm danjm changed the title Fix wallet_addEthereumChain/wallet_switchEthereumChain error handling bug fix(cherry-pick): Fix wallet_addEthereumChain/wallet_switchEthereumChain error handling bug Jun 14, 2024
@danjm danjm merged commit c788598 into Version-v12.0.0 Jun 14, 2024
85 of 86 checks passed
@danjm danjm deleted the ad/Version-v12.0.0-patch-switch-chain-bug branch June 14, 2024 20:54
@github-actions github-actions bot locked and limited conversation to collaborators Jun 14, 2024
@metamaskbot metamaskbot added the release-12.0.0 Issue or pull request that will be included in release 12.0.0 label Jun 14, 2024
@metamaskbot
Copy link
Collaborator

No release label on PR. Adding release label release-12.0.0 on PR, as PR was cherry-picked in branch 12.0.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.0.0 Issue or pull request that will be included in release 12.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants