Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix incorrect warnings when adding a chain from a dapp (#22309)
When a user adds a chain from a dapp, they will see warnings that the currency symbol is incorrect, even though it is correct. Part of the problem was that the `pendingConfirmation` variable inside of `fetchSafeChainsList` was undefined when it should not be. I guess it closed over the original value or something like that? I didn't verify. This PR corrects it by explictly passing the updated `pendingConfirmations` variable to `fetchSafeChainList` The other problem was that `useAlertState` was calling `getTemplateAlerts` twice, without resetting the alert state. On the first call, alerts were being set in state because the request to chainId.network had not yet resolved. This PR fixes it by ensuring that that `useAlertState` does not call `getTemplateAlerts` before the fetch to chainId.network has resolved (when this confrimation type is an add ethereum chain approval) An example of the problem can be seen by going to https://chainlist.org/?search=cro and adding Cronos Mainnet to metamask, only to see warnings that the currency symbol is incorrect even though it is correct. ![Screenshot from 2023-12-15 18-26-51](https://github.com/MetaMask/metamask-extension/assets/7499938/80e299d4-1545-4a38-981f-8b1eafc0b3dc) 1. Go to https://chainlist.org/?search=cro 2. Add Cronos mainnet to metamask 3. The confirmation window should open with an add ethereum chain confirmation. There should be no warnings 4. Reject the confirmation 5. Open the dev console and paste the below code, and press enter. The confirmation window should open with an add ethereum chain confirmation. There should be warnings about the currency symbol 6. Reject the confirmation 7. Modify the below code so that `"symbol": "cra",` becomes `"symbol": "cro",`, paste it in the dev console and press enter. There should be no warnings in the new confirmation window ``` await window.ethereum.request({ "method": "wallet_addEthereumChain", "params": [ { "blockExplorerUrls": [ "https://blockscout.com/poa/xdai/" ], "nativeCurrency": { "name": "CRO", "symbol": "cra", "decimals": 18 }, "rpcUrls": [ "https://evm.cronos.org", null ], "chainId": "0x19", "chainName": "Cronos Mainnet" } ] }); ``` https://github.com/MetaMask/metamask-extension/assets/7499938/d6f738be-8e4a-4618-8703-c2d94df9c8a7 https://github.com/MetaMask/metamask-extension/assets/7499938/c3ab5cf6-ac73-4ad3-b7b3-fd49910c0311 <!-- [screenshots/recordings] --> - [ ] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've clearly explained what problem this PR is solving and how it is solved. - [ ] I've linked related issues - [ ] I've included manual testing steps - [ ] I've included screenshots/recordings if applicable - [ ] 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. - [ ] I’ve properly set the pull request status: - [ ] In case it's not yet "ready for review", I've set it to "draft". - [ ] In case it's "ready for review", I've changed it from "draft" to "non-draft". - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] 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: Pedro Figueiredo <[email protected]>
- Loading branch information