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

feat: Bump QueuedRequestController from ^2.0.0 to ^7.0.0  #28090

Merged
merged 34 commits into from
Oct 30, 2024

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Oct 24, 2024

Description

Bumps @metamask/queued-request-controller to fix queueing issue with Chain Permission wallet_switchEthereumChain and wallet_addEthereumChain when switching to a previously permitted chain and with wallet_addEthereumChain not being enqueued when it still should be.

Open in GitHub Codespaces

Related issues

Related: MetaMask/core#4846
Fixes: #28101
Fixes: #27977
Fixes: #28102

Manual testing steps

The easiest way to test this would be a combination of using the test dapp and the following request to switch chains

await window.ethereum.request({
 "method": "wallet_switchEthereumChain",
 "params": [
  {
    chainId: "0x1"
  }
],
});

The behaviors you should see include:
One dapp:

  • On a dapp permissioned for chain A and B, on chain A, queue up several send transactions, then use wallet_switchEthereumChain to switch to chain B. The send transactions should NOT get cleared immediately after requesting the chain switch. Chain switch should NOT happen until the previous approvals are approved/rejected.
  • On a dapp permissioned for chain A and B, on chain A, queue up one send transaction, then use wallet_switchEthereumChain to switch to chain B, then queue up several more send transactions. Reject/approve the first transaction. Afterwards, you should see chain B as the active chain for the dapp, and all subsequent approvals cleared/rejected automatically.
  • On a dapp permissioned for ONLY chain A, on chain A, queue up one send transaction, then use wallet_switchEthereumChain to switch to chain B, then queue up several more send transactions. Reject/approve the first transaction. Afterwards, you should an approval prompt for adding chain B. If you approve it, the dapp should then be on chain B, with all subsequent approvals cleared/rejected. If you disapprove it, you should be prompted with the subsequent approvals.
  • On a dapp permissioned for ONLY chain A, on chain A, wallet_switchEthereumChain to switch to chain B, then queue up several more send transactions. Reject/approve the first transaction. Afterwards, you should an approval prompt for adding chain B. If you approve it, the dapp should then be on chain B, with all subsequent approvals cleared/rejected. If you disapprove it, you should be prompted with the subsequent approvals.

Two dapps:

  • On a dapp permissioned for chain A, on chain A, queue up several send transactions, On a separate dapp permissioned for chain A and B, on chain A, use wallet_switchEthereumChain to switch to chain B. The send transactions should NOT get cleared immediately after requesting the chain switch. Chain switch should NOT happen until the previous approvals are approved/rejected.
  • On a dapp permissioned for chain A and B, on chain A, queue up one send transaction. On a separate dapp permissioned for chain A and B, on chain A, use wallet_switchEthereumChain to switch to chain B. Then on the first dapp queue up several more send transactions. Reject/approve the first transaction. Afterwards, you should see chain B as the active chain for the second dapp, and then you should still be prompted with the subsequent approvals for the first dapp.
  • One one dapp, start a wallet_addEthereumChain for a chain that does not exist in the wallet and leave the approval alone. On a different dapp, do the same thing. Only the request from the first dapp should be accessible (i.e. no scrubbing between both of them). After rejecting the first request, the second request should then appear (which will look exactly the same of course). Wallet should not lock up if you repeat this and accept either of the requests

Screenshots/Recordings

Before

After

Screen.Recording.2024-10-24.at.1.57.19.PM.mov
Screen.Recording.2024-10-30.at.8.44.54.AM.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.

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.

Copy link

socket-security bot commented Oct 24, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@metamask/[email protected] None 0 0 B

🚮 Removed packages: npm/@metamask/[email protected]

View full report↗︎

@jiexi
Copy link
Contributor Author

jiexi commented Oct 24, 2024

@metamaskbot update-policies

Copy link

socket-security bot commented Oct 24, 2024

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report↗︎

@metamaskbot
Copy link
Collaborator

Policies updated.
👀 Please review the diff for suspicious new powers.

🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff

@metamaskbot
Copy link
Collaborator

Builds ready [fbc055b]
Page Load Metrics (1725 ± 58 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint30721101647328157
domContentLoaded15082009170210651
load15172118172512158
domInteractive239249199
backgroundConnect9109232311
firstReactRender45185873115
getState55114168
initialActions00000
loadScripts1084145112568742
setupStore106422189
uiStartup16642451192116981
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -117.39 KiB (-2.65%)
  • ui: 0 Bytes (0.00%)
  • common: 37.09 KiB (0.47%)

jiexi added a commit to MetaMask/core that referenced this pull request Oct 29, 2024
… switch the network without prompting user approval (#4846)

## Explanation

The release of Chain Permissions in Extension have changed the behavior
of `wallet_switchEthereumChain` and `wallet_addEthereumChain` which
breaks previous assumptions that the `QueuedRequestController` operated
from. Specifically, it was previously assumed that the above methods
would ALWAYS generate an approval that the user must accept or reject.
This is important because the side effect of this behavior was that it
was not possible for those two methods to immediately switch the chain
if there happened to be existing pending approvals. The result of this
new behavior was that pending approvals were being immediately cleared
if one of the method calls above were to a chain that was already
permitted which is the case where a network switch happens immediately
without user interaction.

This PR fixes this new case by:
* explicitly waiting for any batch of processing requests to finish
before proceeding with processing a request that has the potential to
switch the globally selected network
* processing a request that has the potential to switch the globally
selected network by itself (rather than releasing it within a batch of
several requests for the same origin)
* flushing the request queue for the origin IF a request that has the
potential to switch the globally selected network actually does change
the globally selected network

## References

Related: MetaMask/metamask-extension#28090

## Changelog

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/queued-request-controller`

- **BREAKING**: `QueuedRequestController` now requires the
`canRequestSwitchNetworkWithoutApproval` callback in its constructor
params.
- **CHANGED**: `QueuedRequestController` now ensures that any queued
requests for a origin are failed if a request that can switch the
globally selected network without approval actually does change the
globally selected network for that origin.
- **CHANGED**: `QueuedRequestController` now ensures that a request that
can switch the globally selected network without approval is queued
behind any existing pending requests.

## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
- [ ] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes

---------

Co-authored-by: Mark Stacey <[email protected]>
@metamaskbot
Copy link
Collaborator

Builds ready [31d8bdc]
Page Load Metrics (2011 ± 64 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint18052277202412861
domContentLoaded17752201197211957
load18082277201113364
domInteractive219149209
backgroundConnect1085382412
firstReactRender53130106157
getState75314136
initialActions01000
loadScripts12361685144710651
setupStore1170252110
uiStartup20342484222713163
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -79.84 KiB (-1.80%)
  • ui: 0 Bytes (0.00%)
  • common: 74.83 KiB (0.95%)

Gudahtt
Gudahtt previously approved these changes Oct 29, 2024
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

NidhiKJha
NidhiKJha previously approved these changes Oct 30, 2024
@jiexi jiexi dismissed stale reviews from NidhiKJha and Gudahtt via 7a85b89 October 30, 2024 15:41
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@metamaskbot
Copy link
Collaborator

Builds ready [f8ca8b5]
Page Load Metrics (2196 ± 157 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint55830062123488234
domContentLoaded172429472160321154
load177730162196327157
domInteractive29109572210
backgroundConnect984332612
firstReactRender622021123216
getState56120178
initialActions01000
loadScripts127223831619281135
setupStore11174503818
uiStartup197332312451347166
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -79.76 KiB (-1.75%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [951bd80]
Page Load Metrics (1939 ± 78 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint31220591758453218
domContentLoaded16482462191116479
load16622468193916278
domInteractive21173483316
backgroundConnect975302110
firstReactRender572001113919
getState590282613
initialActions01000
loadScripts11431919139915675
setupStore1274332311
uiStartup18582759219220599
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -79.76 KiB (-1.75%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@Gudahtt
Copy link
Member

Gudahtt commented Oct 30, 2024

I have manually tested and confirmed that this fixes #28102 as well. I have added it to the description.

@metamaskbot
Copy link
Collaborator

Builds ready [ae936a0]
Page Load Metrics (1963 ± 133 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint166228931962278134
domContentLoaded165226721923238114
load166329001963278133
domInteractive168049168
backgroundConnect8225404823
firstReactRender532081003115
getState596172311
initialActions01000
loadScripts113821261417219105
setupStore1188342512
uiStartup182236512196382183
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -79.76 KiB (-1.75%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Followed the manual testing steps and they all worked for me.

Merged via the queue into develop with commit 956f99a Oct 30, 2024
85 checks passed
@jiexi jiexi deleted the jl/fix-queued-request-controller-add-switch-chain branch October 30, 2024 20:32
@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 2024
@metamaskbot metamaskbot added the release-12.7.0 Issue or pull request that will be included in release 12.7.0 label Oct 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.