Commit e624efc
fix: prevent calling wallet_addEthereumChain only on persistent chains (MetaMask#18958)
<!--
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**
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->
`wallet_addEthereumChain` was throwing when trying to add any "default
chains", in the sense of chains that are present by default when
installing MetaMask Mobile. These default chains, like Base, can however
be removed by users, so `wallet_addEthereumChain` shouldn't throw.
~This PR updates `wallet_addEthereumChain` to fail only for chains that
can't be removed by users, like Ethereum Mainnet, Linea Mainnet and
default testnets.~
This PR removes the out of date conditional where
`wallet_addEthereumChain` can't be called with some chainIds. This API
can be called with any `chainId` and will prompt the user to update the
default `rpcUrl` for an enabled networks (including "default networks")
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry: `wallet_addEthereumChain` no longer throws an error
when called with "default network" chainIds. This API can be called with
any `chainId` and will prompt the user to update the default `rpcUrl`
for an enabled networks (including "default networks").
## **Related issues**
Fixes:
[WAPI-408](https://consensyssoftware.atlassian.net/browse/WAPI-408)
## **Manual testing steps**
```gherkin
Feature: Add default chain
Scenario: user tries to add a default chain previously removed
Given a default chain (i.g. Base Mainnet) isn't part of the user's known networks
When user visit an app that tries to switch to Base Mainnet
Then it should correctly prompt to add Base Mainnet network
```
## **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 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.
[WAPI-408]:
https://consensyssoftware.atlassian.net/browse/WAPI-408?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
---------
Co-authored-by: Alex Donesky <adonesky@gmail.com>1 parent 32fa6c9 commit e624efc
1 file changed
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | 115 | | |
121 | 116 | | |
122 | 117 | | |
| |||
0 commit comments