metamask-extension
metamask-extension copied to clipboard
fix: UX: Multichain: Fix dead network problem when switching tabs
Description
This PR ensures that a connection to a given network does not block the UI when switching to a dapp tab that remembers that down network, thus preventing a non-respondent network from not displaying the MetaMask UI
Related issues
Fixes: https://github.com/MetaMask/metamask-extension/issues/25588
Manual testing steps
Scenario 1: Kill network, manually click MetaMask extension icon
- Start local ganache
- Add the local network to your network listing (Settings -> Networks -> Add custom network)
- In tab 1, connect to dapp 1 on Localhost
- In tab 2, connect to dapp 2 on Ethereum Mainnet
- Kill local ganache
- Click tab 1
- Click the MetaMask icon in the extension bar
- See UI pop up as expected
Scenario 2: Kill network, trigger transaction from dapp
- Start local ganache
- Add the local network to your network listing (Settings -> Networks -> Add custom network)
- In tab 1, connect to dapp 1 on Localhost
- In tab 2, connect to dapp 2 on Ethereum Mainnet
- Kill local ganache
- Click tab 1
- Trigger a transaction from the dapp
- See UI pop up quickly, with confirmation, as expected
Screenshots/Recordings
Before
After
Pre-merge author checklist
- [ ] I've followed MetaMask Contributor Docs and MetaMask Extension Coding Standards.
- [ ] 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 format if applicable
- [ ] I’ve applied the right labels on the PR (see labeling guidelines). 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.
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.
I noticed that this test was still taking a long time on Chrome so I did some more manual testing and it appears as though (assuming you kill local ganache):
- Click the send button in test dapp
- (random, sometimes long wait time)
- The confirmation eventually pops up
Spying on the service worker between clicking the send button and the confirmation finally coming up, it appears the confirmation doesn't appear until the following network request(s) complete:
https://tx-sentinel-ethereum-mainnet.api.cx.metamask.io/networkshttps://gas.api.cx.metamask.io/networks/1337/suggestedGasFees
When trying to send a transaction on a network with dead RPC, I see 2 RPC calls that each take ~5 seconds to fail, which together cause the ~10 second delay in receiving the metamask popup:
- Click send on test dapp
- extension executes
addTransactionWithController - Calls
TransactionController.addTransactiondetermineTransactionTyperuns theeth_getCodeRPC queryupdateGasPropertiesruns theeth_estimateGasRPC query
I don't know why the RPC queries take 5 seconds instead of failing fast. Perhaps somewhere lower level is doing retry. But that's the only code I see slowing down the popup.
https://github.com/MetaMask/metamask-extension/assets/3500406/ede4eeb9-bae9-4506-99aa-724a898317fa
on the test environment I am seeing a great amount of requests for mostly eth_estimateGas, eth_gasPrice and eth_blockNumber. Those return very fast, but we keep making requests until ~10seconds.
https://github.com/MetaMask/metamask-extension/assets/54408225/b91d21a3-a57b-443c-b5b1-682c1fd3d50f
and on the dev build from this branch, I am seeing a similar behaviour as I see in production: sometimes the popup is open fast, but sometimes it takes ~5 seconds
https://github.com/MetaMask/metamask-extension/assets/54408225/d7106023-dc9d-4f1b-a890-443698fd38b3
Codecov Report
Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
Project coverage is 69.56%. Comparing base (
4a9c480) to head (84786eb). Report is 25 commits behind head on develop.
| Files | Patch % | Lines |
|---|---|---|
| ui/store/actions.ts | 0.00% | 4 Missing :warning: |
| app/scripts/metamask-controller.js | 0.00% | 2 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## develop #25425 +/- ##
===========================================
- Coverage 69.57% 69.56% -0.01%
===========================================
Files 1360 1360
Lines 48172 48177 +5
Branches 13296 13296
===========================================
Hits 33513 33513
- Misses 14659 14664 +5
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Builds ready [84786eb]
- builds: chrome, firefox
- builds (beta): chrome
- builds (flask): chrome, firefox
- builds (MMI): chrome, firefox
- builds (test): chrome, firefox
- builds (test-flask): chrome, firefox
- build viz: Build System
- mv3: Background Module Init Stats
- mv3: UI Init Stats
- mv3: Module Load Stats
- mv3: Bundle Size Stats
- mv2: E2e Actions Stats
- code coverage: Report
- storybook: Storybook
- typescript migration: Dashboard
- all artifacts
Page Load Metrics (263 ± 280 ms)
| Platform | Page | Metric | Min (ms) | Max (ms) | Average (ms) | StandardDeviation (ms) | MarginOfError (ms) |
|---|---|---|---|---|---|---|---|
| Chrome | Home | firstPaint | 65 | 355 | 116 | 59 | 28 |
| domContentLoaded | 9 | 75 | 30 | 19 | 9 | ||
| load | 41 | 2024 | 263 | 582 | 280 | ||
| domInteractive | 9 | 75 | 30 | 19 | 9 |
Bundle size diffs [🚨 Warning! Bundle size has increased!]
- background: 80 Bytes (0.00%)
- ui: 0 Bytes (0.00%)
- common: 194 Bytes (0.00%)
Missing release label release-12.0.0 on PR. Adding release label release-12.0.0 on PR and removing other release labels(release-12.2.0), as PR was cherry-picked in branch 12.0.0.