-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Update QueuedRequestController
to support Multichain API
#4718
Update QueuedRequestController
to support Multichain API
#4718
Conversation
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
QueuedRequestController
to support Multichain API
@@ -162,6 +165,8 @@ export class QueuedRequestController extends BaseController< | |||
*/ | |||
#showApprovalRequest: () => void; | |||
|
|||
#networkClientIdOfCurrentBatch?: NetworkClientId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it okay if we move this next to originOfCurrentBatch
and add a small little comment description?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done here: 2603f25
packages/queued-request-controller/src/QueuedRequestController.ts
Outdated
Show resolved
Hide resolved
packages/queued-request-controller/src/QueuedRequestController.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥹
/** | ||
* The networkClientId of the queuedRequest. | ||
*/ | ||
networkClientId: NetworkClientId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a good catch that it will be on the request already and don't need the SelectedNetworkController call in here.
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
## Explanation This is a RC for v210.0.0. See changelog for more details - @metamask/[email protected] # [5.1.0] ### Changed - Batch processing now considers both origin and `networkClientId`, ensuring requests targeting different networks are processed separately. ([#4718](#4718)) - Incoming requests to `enqueueRequest` now must include a `networkClientId`; an error is thrown if it's missing. This was previously a required part of the type but since consumers like the extension do not have extensive typescript coverage this wasn't definitively enforced. ([#4718](#4718))
Explanation
The
QueuedRequestController
previously batched and processed requests based solely on theirorigin
. This approach doesn't account for scenarios where a dapp interacts with multiple networks simultaneously from the same origin as will be the case on the multichain API.This PR updates the
QueuedRequestController
to batch and process requests based on bothorigin
andnetworkClientId
. This ensures that:networkClientId
changes.Key changes:
origin
andnetworkClientId
, for the legacy API this shouldn't change anything, but it allows us to cleanly batch for the multichain API until we remove queueing altogther.networkClientId
.SelectedNetworkController
for determiningnetworkClientId
. NowNetworkClientId
is expected on every request. Which should always be the case if the middleware ordering is correct on both APIs.origin
s andnetworkClientId
s.Draft PR/Branch off caip-multichain feature branch with preview build: MetaMask/metamask-extension#27408
Videos demonstrating functionality w/ multichain API:
2 requests same network different dapps:
Simple-cross-dapp-same-network-batching.mov
2 requests different network same dapp
single-dapp-different-networks.mov
2 requests same network same dapp
single-dapp-same-network-batching.mov
More complex flows:
https://drive.google.com/file/d/1PvCmmCQbxXqglsFLUlyT_7P_znukLUxI/view?usp=drive_link
https://drive.google.com/file/d/18R8zEPz_zsfhsw-DOkRFwkYRI1URynis/view?usp=sharing
Queueing working same as before on legacy API
Branch/PR with preview builds on develop used to test
Screen.Recording.2024-09-26.at.10.37.44.AM.mov
References
Changelog
@metamask/queued-request-controller
origin
andnetworkClientId
, ensuring requests targeting different networks are processed separately.SelectedNetworkController
; the controller no longer usesSelectedNetworkController:getNetworkClientIdForDomain
.enqueueRequest
now must include anetworkClientId
; an error is thrown if it's missing. This was previously a required part of the type but since consumers like the extension do not have extensive typescript coverage this isn't definitively enforced.Checklist