Skip to content

Commit 9f9e935

Browse files
authored
allow initial state to be passed into the constructor (#3585)
## Explanation We were not able to use persisted values because the initial state could not be passed in. This fixes the issue. ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? For example: * Fixes #12345 * Related to #67890 --> ## 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/selected-network-controller` - **Added**: Ability to pass in initial state. ## 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
1 parent 69e95b1 commit 9f9e935

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/selected-network-controller/src/SelectedNetworkController.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export type SelectedNetworkControllerMessenger = RestrictedControllerMessenger<
8686
>;
8787

8888
export type SelectedNetworkControllerOptions = {
89+
state?: SelectedNetworkControllerState;
8990
messenger: SelectedNetworkControllerMessenger;
9091
};
9192

@@ -109,13 +110,17 @@ export class SelectedNetworkController extends BaseController<
109110
*
110111
* @param options - The controller options.
111112
* @param options.messenger - The restricted controller messenger for the EncryptionPublicKey controller.
113+
* @param options.state - The controllers initial state.
112114
*/
113-
constructor({ messenger }: SelectedNetworkControllerOptions) {
115+
constructor({
116+
messenger,
117+
state = getDefaultState(),
118+
}: SelectedNetworkControllerOptions) {
114119
super({
115120
name: controllerName,
116121
metadata: stateMetadata,
117122
messenger,
118-
state: getDefaultState(),
123+
state,
119124
});
120125
this.#registerMessageHandlers();
121126
}

0 commit comments

Comments
 (0)