Skip to content

feat: Add handling to QueuedRequestController for requests that can switch the network without prompting user approval#4846

Merged
jiexi merged 26 commits intomainfrom
jl/fix-queued-request-controller-switch-chain
Oct 29, 2024
Merged

feat: Add handling to QueuedRequestController for requests that can switch the network without prompting user approval#4846
jiexi merged 26 commits intomainfrom
jl/fix-queued-request-controller-switch-chain

Conversation

@jiexi
Copy link
Copy Markdown
Member

@jiexi jiexi commented Oct 24, 2024

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

@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

@jiexi jiexi requested a review from a team as a code owner October 24, 2024 16:29
@jiexi
Copy link
Copy Markdown
Member Author

jiexi commented Oct 24, 2024

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "18.2.2-preview-5b0b6ae7",
  "@metamask-previews/address-book-controller": "6.0.1-preview-5b0b6ae7",
  "@metamask-previews/announcement-controller": "7.0.1-preview-5b0b6ae7",
  "@metamask-previews/approval-controller": "7.1.0-preview-5b0b6ae7",
  "@metamask-previews/assets-controllers": "39.0.0-preview-5b0b6ae7",
  "@metamask-previews/base-controller": "7.0.1-preview-5b0b6ae7",
  "@metamask-previews/build-utils": "3.0.1-preview-5b0b6ae7",
  "@metamask-previews/chain-controller": "0.1.3-preview-5b0b6ae7",
  "@metamask-previews/composable-controller": "9.0.1-preview-5b0b6ae7",
  "@metamask-previews/controller-utils": "11.4.0-preview-5b0b6ae7",
  "@metamask-previews/ens-controller": "14.0.1-preview-5b0b6ae7",
  "@metamask-previews/eth-json-rpc-provider": "4.1.5-preview-5b0b6ae7",
  "@metamask-previews/gas-fee-controller": "21.0.0-preview-5b0b6ae7",
  "@metamask-previews/json-rpc-engine": "10.0.0-preview-5b0b6ae7",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.4-preview-5b0b6ae7",
  "@metamask-previews/keyring-controller": "17.3.0-preview-5b0b6ae7",
  "@metamask-previews/logging-controller": "6.0.1-preview-5b0b6ae7",
  "@metamask-previews/message-manager": "11.0.0-preview-5b0b6ae7",
  "@metamask-previews/multichain": "0.0.0-preview-5b0b6ae7",
  "@metamask-previews/name-controller": "8.0.1-preview-5b0b6ae7",
  "@metamask-previews/network-controller": "22.0.0-preview-5b0b6ae7",
  "@metamask-previews/notification-controller": "7.0.0-preview-5b0b6ae7",
  "@metamask-previews/notification-services-controller": "0.12.0-preview-5b0b6ae7",
  "@metamask-previews/permission-controller": "11.0.2-preview-5b0b6ae7",
  "@metamask-previews/permission-log-controller": "3.0.1-preview-5b0b6ae7",
  "@metamask-previews/phishing-controller": "12.0.3-preview-5b0b6ae7",
  "@metamask-previews/polling-controller": "11.0.0-preview-5b0b6ae7",
  "@metamask-previews/preferences-controller": "13.1.0-preview-5b0b6ae7",
  "@metamask-previews/profile-sync-controller": "0.9.7-preview-5b0b6ae7",
  "@metamask-previews/queued-request-controller": "5.1.0-preview-5b0b6ae7",
  "@metamask-previews/rate-limit-controller": "6.0.1-preview-5b0b6ae7",
  "@metamask-previews/selected-network-controller": "18.0.2-preview-5b0b6ae7",
  "@metamask-previews/signature-controller": "20.1.0-preview-5b0b6ae7",
  "@metamask-previews/transaction-controller": "37.3.0-preview-5b0b6ae7",
  "@metamask-previews/user-operation-controller": "16.0.0-preview-5b0b6ae7"
}

@jiexi jiexi force-pushed the jl/fix-queued-request-controller-switch-chain branch from 9aeae07 to a227546 Compare October 24, 2024 20:17
@jiexi
Copy link
Copy Markdown
Member Author

jiexi commented Oct 24, 2024

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "18.2.2-preview-e9ee650e",
  "@metamask-previews/address-book-controller": "6.0.1-preview-e9ee650e",
  "@metamask-previews/announcement-controller": "7.0.1-preview-e9ee650e",
  "@metamask-previews/approval-controller": "7.1.0-preview-e9ee650e",
  "@metamask-previews/assets-controllers": "39.0.0-preview-e9ee650e",
  "@metamask-previews/base-controller": "7.0.1-preview-e9ee650e",
  "@metamask-previews/build-utils": "3.0.1-preview-e9ee650e",
  "@metamask-previews/chain-controller": "0.1.3-preview-e9ee650e",
  "@metamask-previews/composable-controller": "9.0.1-preview-e9ee650e",
  "@metamask-previews/controller-utils": "11.4.0-preview-e9ee650e",
  "@metamask-previews/ens-controller": "14.0.1-preview-e9ee650e",
  "@metamask-previews/eth-json-rpc-provider": "4.1.5-preview-e9ee650e",
  "@metamask-previews/gas-fee-controller": "21.0.0-preview-e9ee650e",
  "@metamask-previews/json-rpc-engine": "10.0.0-preview-e9ee650e",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.4-preview-e9ee650e",
  "@metamask-previews/keyring-controller": "17.3.0-preview-e9ee650e",
  "@metamask-previews/logging-controller": "6.0.1-preview-e9ee650e",
  "@metamask-previews/message-manager": "11.0.0-preview-e9ee650e",
  "@metamask-previews/multichain": "0.0.0-preview-e9ee650e",
  "@metamask-previews/name-controller": "8.0.1-preview-e9ee650e",
  "@metamask-previews/network-controller": "22.0.0-preview-e9ee650e",
  "@metamask-previews/notification-controller": "7.0.0-preview-e9ee650e",
  "@metamask-previews/notification-services-controller": "0.12.0-preview-e9ee650e",
  "@metamask-previews/permission-controller": "11.0.2-preview-e9ee650e",
  "@metamask-previews/permission-log-controller": "3.0.1-preview-e9ee650e",
  "@metamask-previews/phishing-controller": "12.1.0-preview-e9ee650e",
  "@metamask-previews/polling-controller": "11.0.0-preview-e9ee650e",
  "@metamask-previews/preferences-controller": "13.1.0-preview-e9ee650e",
  "@metamask-previews/profile-sync-controller": "0.9.7-preview-e9ee650e",
  "@metamask-previews/queued-request-controller": "5.1.0-preview-e9ee650e",
  "@metamask-previews/rate-limit-controller": "6.0.1-preview-e9ee650e",
  "@metamask-previews/selected-network-controller": "18.0.2-preview-e9ee650e",
  "@metamask-previews/signature-controller": "20.1.0-preview-e9ee650e",
  "@metamask-previews/transaction-controller": "37.3.0-preview-e9ee650e",
  "@metamask-previews/user-operation-controller": "16.0.0-preview-e9ee650e"
}

@jiexi
Copy link
Copy Markdown
Member Author

jiexi commented Oct 24, 2024

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "18.2.2-preview-b4526f73",
  "@metamask-previews/address-book-controller": "6.0.1-preview-b4526f73",
  "@metamask-previews/announcement-controller": "7.0.1-preview-b4526f73",
  "@metamask-previews/approval-controller": "7.1.0-preview-b4526f73",
  "@metamask-previews/assets-controllers": "39.0.0-preview-b4526f73",
  "@metamask-previews/base-controller": "7.0.1-preview-b4526f73",
  "@metamask-previews/build-utils": "3.0.1-preview-b4526f73",
  "@metamask-previews/chain-controller": "0.1.3-preview-b4526f73",
  "@metamask-previews/composable-controller": "9.0.1-preview-b4526f73",
  "@metamask-previews/controller-utils": "11.4.0-preview-b4526f73",
  "@metamask-previews/ens-controller": "14.0.1-preview-b4526f73",
  "@metamask-previews/eth-json-rpc-provider": "4.1.5-preview-b4526f73",
  "@metamask-previews/gas-fee-controller": "21.0.0-preview-b4526f73",
  "@metamask-previews/json-rpc-engine": "10.0.0-preview-b4526f73",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.4-preview-b4526f73",
  "@metamask-previews/keyring-controller": "17.3.0-preview-b4526f73",
  "@metamask-previews/logging-controller": "6.0.1-preview-b4526f73",
  "@metamask-previews/message-manager": "11.0.0-preview-b4526f73",
  "@metamask-previews/multichain": "0.0.0-preview-b4526f73",
  "@metamask-previews/name-controller": "8.0.1-preview-b4526f73",
  "@metamask-previews/network-controller": "22.0.0-preview-b4526f73",
  "@metamask-previews/notification-controller": "7.0.0-preview-b4526f73",
  "@metamask-previews/notification-services-controller": "0.12.0-preview-b4526f73",
  "@metamask-previews/permission-controller": "11.0.2-preview-b4526f73",
  "@metamask-previews/permission-log-controller": "3.0.1-preview-b4526f73",
  "@metamask-previews/phishing-controller": "12.1.0-preview-b4526f73",
  "@metamask-previews/polling-controller": "11.0.0-preview-b4526f73",
  "@metamask-previews/preferences-controller": "13.1.0-preview-b4526f73",
  "@metamask-previews/profile-sync-controller": "0.9.7-preview-b4526f73",
  "@metamask-previews/queued-request-controller": "5.1.0-preview-b4526f73",
  "@metamask-previews/rate-limit-controller": "6.0.1-preview-b4526f73",
  "@metamask-previews/selected-network-controller": "18.0.2-preview-b4526f73",
  "@metamask-previews/signature-controller": "20.1.0-preview-b4526f73",
  "@metamask-previews/transaction-controller": "37.3.0-preview-b4526f73",
  "@metamask-previews/user-operation-controller": "16.0.0-preview-b4526f73"
}

@jiexi
Copy link
Copy Markdown
Member Author

jiexi commented Oct 24, 2024

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "18.2.2-preview-49199726",
  "@metamask-previews/address-book-controller": "6.0.1-preview-49199726",
  "@metamask-previews/announcement-controller": "7.0.1-preview-49199726",
  "@metamask-previews/approval-controller": "7.1.0-preview-49199726",
  "@metamask-previews/assets-controllers": "39.0.0-preview-49199726",
  "@metamask-previews/base-controller": "7.0.1-preview-49199726",
  "@metamask-previews/build-utils": "3.0.1-preview-49199726",
  "@metamask-previews/chain-controller": "0.1.3-preview-49199726",
  "@metamask-previews/composable-controller": "9.0.1-preview-49199726",
  "@metamask-previews/controller-utils": "11.4.0-preview-49199726",
  "@metamask-previews/ens-controller": "14.0.1-preview-49199726",
  "@metamask-previews/eth-json-rpc-provider": "4.1.5-preview-49199726",
  "@metamask-previews/gas-fee-controller": "21.0.0-preview-49199726",
  "@metamask-previews/json-rpc-engine": "10.0.0-preview-49199726",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.4-preview-49199726",
  "@metamask-previews/keyring-controller": "17.3.0-preview-49199726",
  "@metamask-previews/logging-controller": "6.0.1-preview-49199726",
  "@metamask-previews/message-manager": "11.0.0-preview-49199726",
  "@metamask-previews/multichain": "0.0.0-preview-49199726",
  "@metamask-previews/name-controller": "8.0.1-preview-49199726",
  "@metamask-previews/network-controller": "22.0.0-preview-49199726",
  "@metamask-previews/notification-controller": "7.0.0-preview-49199726",
  "@metamask-previews/notification-services-controller": "0.12.0-preview-49199726",
  "@metamask-previews/permission-controller": "11.0.2-preview-49199726",
  "@metamask-previews/permission-log-controller": "3.0.1-preview-49199726",
  "@metamask-previews/phishing-controller": "12.1.0-preview-49199726",
  "@metamask-previews/polling-controller": "11.0.0-preview-49199726",
  "@metamask-previews/preferences-controller": "13.1.0-preview-49199726",
  "@metamask-previews/profile-sync-controller": "0.9.7-preview-49199726",
  "@metamask-previews/queued-request-controller": "5.1.0-preview-49199726",
  "@metamask-previews/rate-limit-controller": "6.0.1-preview-49199726",
  "@metamask-previews/selected-network-controller": "18.0.2-preview-49199726",
  "@metamask-previews/signature-controller": "20.1.0-preview-49199726",
  "@metamask-previews/transaction-controller": "37.3.0-preview-49199726",
  "@metamask-previews/user-operation-controller": "16.0.0-preview-49199726"
}

@jiexi jiexi marked this pull request as draft October 24, 2024 21:40
@jiexi
Copy link
Copy Markdown
Member Author

jiexi commented Oct 25, 2024

@metamaskbot publish-preview

@jiexi jiexi changed the title fix: Fix queuing being broken in QueuedRequestController due to wallet_switchEthereumChain and wallet_addEthereumChain now potentially changing the selected network without needing to prompt the user for approval feat: Add handling to QueuedRequestController for requests that can switch the network without prompting user approval Oct 25, 2024
@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "18.2.2-preview-f9d64175",
  "@metamask-previews/address-book-controller": "6.0.1-preview-f9d64175",
  "@metamask-previews/announcement-controller": "7.0.1-preview-f9d64175",
  "@metamask-previews/approval-controller": "7.1.0-preview-f9d64175",
  "@metamask-previews/assets-controllers": "39.0.0-preview-f9d64175",
  "@metamask-previews/base-controller": "7.0.1-preview-f9d64175",
  "@metamask-previews/build-utils": "3.0.1-preview-f9d64175",
  "@metamask-previews/chain-controller": "0.1.3-preview-f9d64175",
  "@metamask-previews/composable-controller": "9.0.1-preview-f9d64175",
  "@metamask-previews/controller-utils": "11.4.0-preview-f9d64175",
  "@metamask-previews/ens-controller": "14.0.1-preview-f9d64175",
  "@metamask-previews/eth-json-rpc-provider": "4.1.5-preview-f9d64175",
  "@metamask-previews/gas-fee-controller": "21.0.0-preview-f9d64175",
  "@metamask-previews/json-rpc-engine": "10.0.0-preview-f9d64175",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.4-preview-f9d64175",
  "@metamask-previews/keyring-controller": "17.3.0-preview-f9d64175",
  "@metamask-previews/logging-controller": "6.0.1-preview-f9d64175",
  "@metamask-previews/message-manager": "11.0.0-preview-f9d64175",
  "@metamask-previews/multichain": "0.0.0-preview-f9d64175",
  "@metamask-previews/name-controller": "8.0.1-preview-f9d64175",
  "@metamask-previews/network-controller": "22.0.0-preview-f9d64175",
  "@metamask-previews/notification-controller": "7.0.0-preview-f9d64175",
  "@metamask-previews/notification-services-controller": "0.12.0-preview-f9d64175",
  "@metamask-previews/permission-controller": "11.0.2-preview-f9d64175",
  "@metamask-previews/permission-log-controller": "3.0.1-preview-f9d64175",
  "@metamask-previews/phishing-controller": "12.2.0-preview-f9d64175",
  "@metamask-previews/polling-controller": "11.0.0-preview-f9d64175",
  "@metamask-previews/preferences-controller": "13.1.0-preview-f9d64175",
  "@metamask-previews/profile-sync-controller": "0.9.7-preview-f9d64175",
  "@metamask-previews/queued-request-controller": "5.1.0-preview-f9d64175",
  "@metamask-previews/rate-limit-controller": "6.0.1-preview-f9d64175",
  "@metamask-previews/selected-network-controller": "18.0.2-preview-f9d64175",
  "@metamask-previews/signature-controller": "20.1.0-preview-f9d64175",
  "@metamask-previews/transaction-controller": "37.3.0-preview-f9d64175",
  "@metamask-previews/user-operation-controller": "16.0.0-preview-f9d64175"
}

@jiexi
Copy link
Copy Markdown
Member Author

jiexi commented Oct 28, 2024

@metamaskbot publish-preview

@github-actions
Copy link
Copy Markdown
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/accounts-controller": "18.2.2-preview-6bb6f553",
  "@metamask-previews/address-book-controller": "6.0.1-preview-6bb6f553",
  "@metamask-previews/announcement-controller": "7.0.1-preview-6bb6f553",
  "@metamask-previews/approval-controller": "7.1.0-preview-6bb6f553",
  "@metamask-previews/assets-controllers": "39.0.0-preview-6bb6f553",
  "@metamask-previews/base-controller": "7.0.1-preview-6bb6f553",
  "@metamask-previews/build-utils": "3.0.1-preview-6bb6f553",
  "@metamask-previews/chain-controller": "0.1.3-preview-6bb6f553",
  "@metamask-previews/composable-controller": "9.0.1-preview-6bb6f553",
  "@metamask-previews/controller-utils": "11.4.0-preview-6bb6f553",
  "@metamask-previews/ens-controller": "14.0.1-preview-6bb6f553",
  "@metamask-previews/eth-json-rpc-provider": "4.1.5-preview-6bb6f553",
  "@metamask-previews/gas-fee-controller": "21.0.0-preview-6bb6f553",
  "@metamask-previews/json-rpc-engine": "10.0.0-preview-6bb6f553",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.4-preview-6bb6f553",
  "@metamask-previews/keyring-controller": "17.3.0-preview-6bb6f553",
  "@metamask-previews/logging-controller": "6.0.1-preview-6bb6f553",
  "@metamask-previews/message-manager": "11.0.0-preview-6bb6f553",
  "@metamask-previews/multichain": "0.0.0-preview-6bb6f553",
  "@metamask-previews/name-controller": "8.0.1-preview-6bb6f553",
  "@metamask-previews/network-controller": "22.0.0-preview-6bb6f553",
  "@metamask-previews/notification-controller": "7.0.0-preview-6bb6f553",
  "@metamask-previews/notification-services-controller": "0.12.0-preview-6bb6f553",
  "@metamask-previews/permission-controller": "11.0.2-preview-6bb6f553",
  "@metamask-previews/permission-log-controller": "3.0.1-preview-6bb6f553",
  "@metamask-previews/phishing-controller": "12.3.0-preview-6bb6f553",
  "@metamask-previews/polling-controller": "11.0.0-preview-6bb6f553",
  "@metamask-previews/preferences-controller": "13.1.0-preview-6bb6f553",
  "@metamask-previews/profile-sync-controller": "0.9.7-preview-6bb6f553",
  "@metamask-previews/queued-request-controller": "5.1.0-preview-6bb6f553",
  "@metamask-previews/rate-limit-controller": "6.0.1-preview-6bb6f553",
  "@metamask-previews/selected-network-controller": "18.0.2-preview-6bb6f553",
  "@metamask-previews/signature-controller": "20.1.0-preview-6bb6f553",
  "@metamask-previews/transaction-controller": "37.3.0-preview-6bb6f553",
  "@metamask-previews/user-operation-controller": "16.0.0-preview-6bb6f553"
}

Gudahtt
Gudahtt previously approved these changes Oct 28, 2024
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
@jiexi jiexi merged commit 555137c into main Oct 29, 2024
@jiexi jiexi deleted the jl/fix-queued-request-controller-switch-chain branch October 29, 2024 17:07
github-merge-queue bot pushed a commit to MetaMask/metamask-extension that referenced this pull request Oct 30, 2024
<!--
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**

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](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28090?quickstart=1)

## **Related issues**

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

## **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**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**


https://github.com/user-attachments/assets/2634119f-67db-4866-8520-9320a9400b1d



https://github.com/user-attachments/assets/c78c13ab-ea4f-4420-bccc-70959786e8db



## **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.

---------

Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
Gudahtt pushed a commit to MetaMask/metamask-extension that referenced this pull request Oct 30, 2024
<!--
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.
-->

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](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28090?quickstart=1)

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

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

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

<!-- [screenshots/recordings] -->

https://github.com/user-attachments/assets/2634119f-67db-4866-8520-9320a9400b1d

https://github.com/user-attachments/assets/c78c13ab-ea4f-4420-bccc-70959786e8db

- [ ] 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.

- [ ] 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.

---------

Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
Gudahtt added a commit to MetaMask/metamask-extension that referenced this pull request Oct 30, 2024
This is a cherry-pick of #28090 for v12.6.0. Original description:

<!--
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**

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](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28090?quickstart=1)

## **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**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**


https://github.com/user-attachments/assets/2634119f-67db-4866-8520-9320a9400b1d



https://github.com/user-attachments/assets/c78c13ab-ea4f-4420-bccc-70959786e8db



## **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.

---------

Co-authored-by: jiexi <jiexiluan@gmail.com>
Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
adonesky1 added a commit that referenced this pull request Nov 6, 2024
…s not updated after flushing requests for an origin (#4898)

## Explanation

Fix issue where `QueuedRequestController.state.queuedRequestCount` is
not updated after flushing requests for an origin

## References
- #4846
- MetaMask/metamask-extension#28090

## Fixes
- Bug identified [in v12.7.0 RC
Thread](https://consensys.slack.com/archives/C029JG63136/p1730918073046389?thread_ts=1729246801.516029&cid=C029JG63136)

## Before


https://drive.google.com/file/d/1ujdQgVLlT8KlwRwO-Cc3XvRHPrkpxIg_/view?usp=drive_link

## After


https://github.com/user-attachments/assets/e77928e5-165b-441a-b4da-0e10471c0529


## Changelog

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

- **FIX**: Ensure queuedRequestCount value is updated properly after
flushing the queue for a given origin

## 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
github-merge-queue bot pushed a commit to MetaMask/metamask-extension that referenced this pull request Nov 7, 2024
## **Description**

Bumps version of QueuedRequestController, with a patch that fixes an
issue where `QueuedRequestController.state.queuedRequestCount` is not
updated after flushing requests for an origin

## References
- MetaMask/core#4899
- MetaMask/core#4846
- #28090

## Fixes
Fixes #28358

[Slack discussion in v12.7.0 RC
Thread](https://consensys.slack.com/archives/C029JG63136/p1730918073046389?thread_ts=1729246801.516029&cid=C029JG63136)

## Before


https://drive.google.com/file/d/1ujdQgVLlT8KlwRwO-Cc3XvRHPrkpxIg_/view?usp=drive_link

## After


https://github.com/user-attachments/assets/e77928e5-165b-441a-b4da-0e10471c0529


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

## **Manual testing steps**

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.


- [ ] 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.
adonesky1 added a commit to MetaMask/metamask-extension that referenced this pull request Nov 7, 2024
## **Description**

Bumps version of QueuedRequestController, with a patch that fixes an
issue where `QueuedRequestController.state.queuedRequestCount` is not
updated after flushing requests for an origin

## References
- MetaMask/core#4899
- MetaMask/core#4846
- #28090

## Fixes
Fixes #28358

[Slack discussion in v12.7.0 RC
Thread](https://consensys.slack.com/archives/C029JG63136/p1730918073046389?thread_ts=1729246801.516029&cid=C029JG63136)

## Before


https://drive.google.com/file/d/1ujdQgVLlT8KlwRwO-Cc3XvRHPrkpxIg_/view?usp=drive_link

## After


https://github.com/user-attachments/assets/e77928e5-165b-441a-b4da-0e10471c0529


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

## **Manual testing steps**

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.


- [ ] 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.
adonesky1 added a commit to MetaMask/metamask-extension that referenced this pull request Nov 8, 2024
#28355) (#28371)

## **Description**

Bumps version of QueuedRequestController, with a patch that fixes an
issue where `QueuedRequestController.state.queuedRequestCount` is not
updated after flushing requests for an origin

## References
- MetaMask/core#4899
- MetaMask/core#4846
- #28090

## Fixes
Fixes #28358

[Slack discussion in v12.7.0 RC

Thread](https://consensys.slack.com/archives/C029JG63136/p1730918073046389?thread_ts=1729246801.516029&cid=C029JG63136)

## Before



https://drive.google.com/file/d/1ujdQgVLlT8KlwRwO-Cc3XvRHPrkpxIg_/view?usp=drive_link

## After



https://github.com/user-attachments/assets/e77928e5-165b-441a-b4da-0e10471c0529


[![Open in GitHub

Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28355?quickstart=1)

## **Manual testing steps**

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.


- [ ] 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.


<!--
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?
-->

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

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants