You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix: SelectedNetworkController should return globally selected networkClient from getProviderAndBlockTracker when domain not in state (#4063)
## Explanation
The SelectedNetworkController currently constructs a proxy for any
domain that has permissions. Other domains have no associated proxy, so
the getProviderAndBlockTracker method would throw an error.
This is problematic because we grab the network client for an origin a
single time when constructing an RPC pipeline for that origin in the
MetaMask extension. We don't re-create the RPC pipeline when permissions
change. That means that the pipeline is setup with the wrong network
client (see here for more details on this bug:
MetaMask/metamask-extension#23509 )
To resolve this problem, we can instead keep network client proxies for
all origins, not just those with permissions. Origins without
permissions still should not have a selected network client ID state,
but they can have proxies that point at the globally selected network
client. That way, when the origin is granted permissions, we can
redirect this proxy to the selected network client and everything works
smoothly, without needing to reconstruct the RPC pipeline.
This PR should be merged shortly after
#4104
## References
Fixes: #4062
See: #4104
## 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/network-controller`
- **ADDED**: Add `getSelectedNetworkClient()` method that returns the
provider and blockTracker for the currently selected network
- **ADDED**: Add 'NetworkController:getSelectedNetworkClient' action
### `@metamask/selected-network-controller`
- **BREAKING**: `SelectedNetworkController` now requires the
`NetworkController:getSelectedNetworkClient` messenger action
- **CHANGED**: Previously when a domain became no longer permissioned,
it's network client proxy would continue to point at the networkClientId
it was last set to. Now it is set to follow the globally selected
network
- **CHANGED**: `SelectedNetworkController. getProviderAndBlockTracker()`
no longer throws an error if the `useRequestQueue` flag is false
- **CHANGED**: Previously `SelectedNetworkController.
getProviderAndBlockTracker()` threw an error if there was no
networkClientId set for the passed domain. Now it returns a proxy that
follows the globally selected network instead.
## 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
---------
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
Co-authored-by: Jiexi Luan <jiexiluan@gmail.com>
* Accesses the provider and block tracker for the currently selected network.
642
-
*
643
653
* @returns The proxy and block tracker proxies.
654
+
* @deprecated This method has been replaced by `getSelectedNetworkClient` (which has a more easily used return type) and will be removed in a future release.
* This method is used when a domain is removed from the PermissionsController.
236
+
* It will remove re-point the network proxy to the globally selected network in the domainProxyMap or, if no globally selected network client is available, delete the proxy.
237
+
*
238
+
* @param domain - The domain for which to unset the network client ID.
0 commit comments