-
-
Notifications
You must be signed in to change notification settings - Fork 268
fix: SelectedNetworkController network stateChange listener
#4638
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: SelectedNetworkController network stateChange listener
#4638
Conversation
SelectedNetworkController expected network stateChange patchSelectedNetworkController network stateChange listener
290f23a to
e0fda92
Compare
|
product change looks good, ive tested it via extension. Would be good to merge this to the main PR so we can publish a new preview release. Edit: I committed it to the main PR for that reason |
|
New dependencies detected. Learn more about Socket for GitHub ↗︎
|
| (availableNetworkClientIds) => { | ||
| // if a network is updated or removed, update the networkClientId for all domains | ||
| // that were using it to the selected network client id | ||
| const { selectedNetworkClientId } = this.messagingSystem.call( | ||
| 'NetworkController:getState', | ||
| ); | ||
| Object.entries(this.state.domains).forEach( | ||
| ([domain, networkClientIdForDomain]) => { | ||
| if (!availableNetworkClientIds.includes(networkClientIdForDomain)) { | ||
| this.setNetworkClientIdForDomain(domain, selectedNetworkClientId); | ||
| } | ||
| }, | ||
| ); |
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 usage of immer patches has been removed since it strictly depends on how state changes are made on the controller that originates the event.
We can reduce the number of events received by this listener using a selector
aa8d6f7 to
e050d07
Compare
Explanation
Currently,
SelectedNetworkControllersubscribes to theNetworkController:stateChangeevent to make sure that network client ids associated with managed domains stay valid. Though, we are currently checking on the specific immer patch applied to the NetworkController state: this means that based on how the state draft was manipulated on the origin controller, we may or may not capture the change and react to it.To fix it, now
SelectedNetworkControllerwill look at the actual content of the updated state, instead of relying on immer patches. To reduce the amount of event instances received by the controller, a selector is applied to the subscription, filtering out irrelevant instances.References
Changelog
@metamask/network-controllergetNetworkConfigurations,getAvailableNetworkClientIdsandselectAvailableNetworkClientIdsselectors@metamask/selected-network-controllerNo consumer-faced changes
Checklist