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
Refactor: Expose SelectedNetworkController proxies map in the constructor params (#4104)
## Explanation
In a [preceding PR](#4063), the
SelectedNetworkController will start to keep proxy instances for all
domains seen without a way to remove them when they become stale. This
PR exposes the private proxies cache map as a constructor param which
will enable callers to implement their own cache invalidation strategies
without needing to concern the SelectedNetworkController of the
implementation details themselves. This is needed because Mobile and
Extension will need to follow different cache invalidation strategies.
This PR should be merged before
#4063
## References
Fixes: #4062
See: #4063
## Changelog
### `@metamask/selected-network-controller`
- **BREAKING**: `SelectedNetworkController` now expects the
`domainProxyMap` param which is a `Map` of `Domain` to `NetworkProxy`
- **ADDED**: exports the `Domain` type
## 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: Alex Donesky <adonesky@gmail.com>
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
Copy file name to clipboardExpand all lines: packages/selected-network-controller/src/SelectedNetworkController.ts
+10-6Lines changed: 10 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ const stateMetadata = {
24
24
25
25
constgetDefaultState=()=>({domains: {}});
26
26
27
-
typeDomain=string;
27
+
exporttypeDomain=string;
28
28
29
29
exportconstMETAMASK_DOMAIN='metamask'asconst;
30
30
@@ -96,6 +96,7 @@ export type SelectedNetworkControllerOptions = {
96
96
state?: SelectedNetworkControllerState;
97
97
messenger: SelectedNetworkControllerMessenger;
98
98
getUseRequestQueue: GetUseRequestQueue;
99
+
domainProxyMap: Map<Domain,NetworkProxy>;
99
100
};
100
101
101
102
exporttypeNetworkProxy={
@@ -111,7 +112,7 @@ export class SelectedNetworkController extends BaseController<
111
112
SelectedNetworkControllerState,
112
113
SelectedNetworkControllerMessenger
113
114
>{
114
-
#proxies =newMap<Domain,NetworkProxy>();
115
+
#domainProxyMap: Map<Domain,NetworkProxy>;
115
116
116
117
#getUseRequestQueue: GetUseRequestQueue;
117
118
@@ -122,11 +123,13 @@ export class SelectedNetworkController extends BaseController<
122
123
* @param options.messenger - The restricted controller messenger for the EncryptionPublicKey controller.
123
124
* @param options.state - The controllers initial state.
124
125
* @param options.getUseRequestQueue - feature flag for perDappNetwork & request queueing features
126
+
* @param options.domainProxyMap - A map for storing domain-specific proxies that are held in memory only during use.
125
127
*/
126
128
constructor({
127
129
messenger,
128
130
state =getDefaultState(),
129
131
getUseRequestQueue,
132
+
domainProxyMap,
130
133
}: SelectedNetworkControllerOptions){
131
134
super({
132
135
name: controllerName,
@@ -135,6 +138,7 @@ export class SelectedNetworkController extends BaseController<
135
138
state,
136
139
});
137
140
this.#getUseRequestQueue =getUseRequestQueue;
141
+
this.#domainProxyMap =domainProxyMap;
138
142
this.#registerMessageHandlers();
139
143
140
144
// this is fetching all the dapp permissions from the PermissionsController and looking for any domains that are not in domains state in this controller. Then we take any missing domains and add them to state here, setting it with the globally selected networkClientId (fetched from the NetworkController)
@@ -218,9 +222,9 @@ export class SelectedNetworkController extends BaseController<
0 commit comments