-
-
Notifications
You must be signed in to change notification settings - Fork 203
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
Fix issue with selectedNetworkMiddlware
where all domains are added to state regardless of whether they have permissions
#3908
Conversation
1067774
to
10d6e66
Compare
103055a
to
99e2006
Compare
@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.
|
f7736f1
to
08978bf
Compare
@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.
|
@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.
|
067fd49
to
3905f51
Compare
@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.
|
@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.
|
@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.
|
packages/selected-network-controller/tests/SelectedNetworkMiddleware.test.ts
Show resolved
Hide resolved
57aad5e
to
b790270
Compare
packages/selected-network-controller/src/SelectedNetworkController.ts
Outdated
Show resolved
Hide resolved
@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.
|
1a0f393
to
3b3808f
Compare
packages/selected-network-controller/src/SelectedNetworkController.ts
Outdated
Show resolved
Hide resolved
88b679e
to
ecb5e72
Compare
…electedNetworkMiddleware. Fallback to metamask domain networkClientId to add to the req object.
Cleans up and simplifies
a209931
to
a71ecdd
Compare
Object.keys(this.state.domains).forEach((domain) => { | ||
// when perDomainNetwork is false, getNetworkClientIdForDomain always returns the networkClientId for the domain 'metamask' | ||
this.setNetworkClientIdForDomain( | ||
domain, | ||
this.getNetworkClientIdForDomain(domain), | ||
); | ||
}); |
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.
No need to update the domain state when the perDomainNetwork
flag is toggled on or off, we can just reference this flag in the relevant methods to determine which networkClient to access in either case.
packages/selected-network-controller/src/SelectedNetworkController.ts
Outdated
Show resolved
Hide resolved
Changes make sense. |
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.
Oops, didn't realize I didn't approve 😅
# @metamask/selected-network-controller ## [8.0.0] ### Changed - **BREAKING:** `setNetworkClientIdForDomain` now throws an error if passed `metamask` as its first (`domain`) argument ([#3908](#3908)). - **BREAKING:** `setNetworkClientIdForDomain` now includes a check that the requesting `domain` has already been granted permissions in the `PermissionsController` before adding it to `domains` state and throws an error if the domain does not have permissions ([#3908](#3908)). - **BREAKING:** the `domains` state now no longer contains a `metamask` domain key Consumers should instead use the `selectedNetworkClientId` from the `NetworkController` to get the selected network for the `metamask` domain ([#3908](#3908)). - **BREAKING:** `getProviderAndBlockTracker` now throws an error if called with any domain while the `perDomainNetwork` flag is false. Consumers should instead use the `provider` and `blockTracker` from the `NetworkController` when the `perDomainNetwork` flag is false ([#3908](#3908)). - **BREAKING:** `getProviderAndBlockTracker` now throws an error if called with a domain that is not in domains state ([#3908](#3908)). - **BREAKING:** `getNetworkClientIdForDomain` now returns the `selectedNetworkClientId` for the globally selected network if the `perDomainNetwork` flag is false and if the domain is not in the `domains` state ([#3908](#3908)). ### Removed - **BREAKING:** Remove logic in `selectedNetworkMiddleware` to set a default `networkClientId` for the requesting origin when not already set. Now if no `networkClientId` is already set for the requesting origin, the middleware will not add the origin to `domains` state but will add the `networkClientId` currently set for the `selectedNetworkClient` from the `NetworkController` to the request object ([#3908](#3908)). ### Fixed - The `SelectedNetworkController` now listens for `networkConfiguration` removal events on the `NetworkController` and if a removed `networkClientId` matches the set `networkClientId` for any domains in its state, it updates them to the globally selected `networkClientId` and repoints the proxies accordingly. ([#3926](#3926)) --------- Co-authored-by: jiexi <jiexiluan@gmail.com> Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
@metamask/selected-network-controller
Changed
selectedNetworkMiddleware
to set a defaultnetworkClientId
for the requesting origin when not already set. Now if nonetworkClientId
is already set for the requesting origin, the middleware will not add the origin todomains
state but will add thenetworkClientId
currently set for theselectedNetworkClient
from theNetworkController
to the request object.setNetworkClientIdForDomain
now throws an error if passedmetamask
as its first (domain
) argumentsetNetworkClientIdForDomain
now includes a check that the requestingdomain
has already been granted permissions in thePermissionsController
before adding it todomains
state and throws an error if the domain does not have permissions.domains
state now no longer contains ametamask
key.getProviderAndBlockTracker
now throws an error if called with any domain while theperDomainNetwork
flag is false.(These changes help fix an issue where the
SelectedNetworkController
adds any and all domains the user visits to its domains state whether or not the user has connected to these sites.)Currently can be e2e tested on this WIP integration branch: MetaMask/metamask-extension#22860