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: change queued-request-controller methods array params to callbacks #4423

Merged

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Jun 13, 2024

Explanation

The existing methodsWithConfirmation array param is not sufficient for determining if a method will cause a confirmation to be presented to the user or not because some methods such as eth_requestAccounts may only cause a prompt in some scenarios but not others.

This PR replaces the array params used in the QueuedRequestController and its middleware to be callbacks that accept the entire request object instead.

References

See: MetaMask/metamask-extension#25310

Changelog

@metamask/queued-request-controller

  • BREAKING: QueuedRequestController constructor no longer accepts the methodsRequiringNetworkSwitch array param. It's now replaced with the shouldRequestSwitchNetwork function param which should return true when a request requires the globally selected network to match that of the dapp.
  • BREAKING: createQueuedRequestMiddleware no longer accepts the methodsWithConfirmation array param. It's now replaced with the shouldEnqueueRequest function param which should return true when a request should be handled by the QueuedRequestController

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

@jiexi
Copy link
Contributor Author

jiexi commented Jun 13, 2024

@metamaskbot publish-preview

Copy link
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": "17.0.0-preview-b09c2ed",
  "@metamask-previews/address-book-controller": "5.0.0-preview-b09c2ed",
  "@metamask-previews/announcement-controller": "7.0.0-preview-b09c2ed",
  "@metamask-previews/approval-controller": "7.0.0-preview-b09c2ed",
  "@metamask-previews/assets-controllers": "33.0.0-preview-b09c2ed",
  "@metamask-previews/base-controller": "6.0.0-preview-b09c2ed",
  "@metamask-previews/build-utils": "3.0.0-preview-b09c2ed",
  "@metamask-previews/chain-controller": "0.1.0-preview-b09c2ed",
  "@metamask-previews/composable-controller": "7.0.0-preview-b09c2ed",
  "@metamask-previews/controller-utils": "11.0.0-preview-b09c2ed",
  "@metamask-previews/ens-controller": "12.0.0-preview-b09c2ed",
  "@metamask-previews/eth-json-rpc-provider": "4.0.0-preview-b09c2ed",
  "@metamask-previews/gas-fee-controller": "17.0.0-preview-b09c2ed",
  "@metamask-previews/json-rpc-engine": "9.0.0-preview-b09c2ed",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.0-preview-b09c2ed",
  "@metamask-previews/keyring-controller": "17.1.0-preview-b09c2ed",
  "@metamask-previews/logging-controller": "5.0.0-preview-b09c2ed",
  "@metamask-previews/message-manager": "10.0.0-preview-b09c2ed",
  "@metamask-previews/name-controller": "8.0.0-preview-b09c2ed",
  "@metamask-previews/network-controller": "19.0.0-preview-b09c2ed",
  "@metamask-previews/notification-controller": "6.0.0-preview-b09c2ed",
  "@metamask-previews/notification-services-controller": "0.0.0-preview-b09c2ed",
  "@metamask-previews/permission-controller": "10.0.0-preview-b09c2ed",
  "@metamask-previews/permission-log-controller": "3.0.0-preview-b09c2ed",
  "@metamask-previews/phishing-controller": "10.0.0-preview-b09c2ed",
  "@metamask-previews/polling-controller": "8.0.0-preview-b09c2ed",
  "@metamask-previews/preferences-controller": "13.0.0-preview-b09c2ed",
  "@metamask-previews/profile-sync-controller": "0.0.0-preview-b09c2ed",
  "@metamask-previews/queued-request-controller": "0.12.0-preview-b09c2ed",
  "@metamask-previews/rate-limit-controller": "6.0.0-preview-b09c2ed",
  "@metamask-previews/selected-network-controller": "15.0.2-preview-b09c2ed",
  "@metamask-previews/signature-controller": "18.0.0-preview-b09c2ed",
  "@metamask-previews/transaction-controller": "33.0.0-preview-b09c2ed",
  "@metamask-previews/user-operation-controller": "12.0.0-preview-b09c2ed"
}

Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

LGTM!

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, great solution!

@adonesky1 adonesky1 merged commit 0bd90e6 into main Jun 14, 2024
116 checks passed
@adonesky1 adonesky1 deleted the jl/change-queued-request-controller-method-param-to-callback branch June 14, 2024 22:59
jiexi added a commit to MetaMask/metamask-extension that referenced this pull request Jun 20, 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 `^1.0.0` in order to
handle the case where `eth_requestAccounts` requests that would not
cause a confirmation to be presented to the user (because they have
permitted some accounts for that dapp) would be stuck behind the request
queue when they could just be passed through.

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

## **Related issues**

See: MetaMask/core#4423
Fixes: #25407

## **Manual testing steps**

1. Open https://metamask.github.io/test-dapp/ and https://app.odos.xyz/,
connect to both
1. On the Test Dapp, send an EIP 1559 txn, but do not confirm/reject the
confirmation nor close the popup
1. Reload ODOS
1. ODOS should show that is connected to MetaMask in the top right of
the webpage
1. Open console on the ODOS page
1. run `await window.ethereum.request({method: 'eth_requestAccounts'})`,
it should return immediately with the permitted accounts


## **Screenshots/Recordings**

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

### **Before**



### **After**


https://github.com/MetaMask/metamask-extension/assets/918701/b76607ef-b0a3-4943-b1d5-85f8cd766343




## **Pre-merge author checklist**

- [x] 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).
- [x] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] 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 <[email protected]>
jiexi added a commit to MetaMask/metamask-extension that referenced this pull request Jun 20, 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 `^1.0.0` in order to
handle the case where `eth_requestAccounts` requests that would not
cause a confirmation to be presented to the user (because they have
permitted some accounts for that dapp) would be stuck behind the request
queue when they could just be passed through.

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

See: MetaMask/core#4423
Fixes: #25407

1. Open https://metamask.github.io/test-dapp/ and https://app.odos.xyz/,
connect to both
1. On the Test Dapp, send an EIP 1559 txn, but do not confirm/reject the
confirmation nor close the popup
1. Reload ODOS
1. ODOS should show that is connected to MetaMask in the top right of
the webpage
1. Open console on the ODOS page
1. run `await window.ethereum.request({method: 'eth_requestAccounts'})`,
it should return immediately with the permitted accounts

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

https://github.com/MetaMask/metamask-extension/assets/918701/b76607ef-b0a3-4943-b1d5-85f8cd766343

- [x] 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).
- [x] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] 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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants