Skip to content

Commit

Permalink
refactor: use option bag for constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesposito committed May 29, 2023
1 parent f0797c6 commit 522e462
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions packages/keyring-controller/src/KeyringController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,17 @@ export type KeyringControllerMessenger = RestrictedControllerMessenger<
string
>;

/**
* @type KeyringControllerConfig
*
* Keyring controller configuration
* @property encryptor - Keyring encryptor
*/
export type KeyringControllerConfig = {
export type KeyringControllerOptions = {
removeIdentity: PreferencesController['removeIdentity'];
syncIdentities: PreferencesController['syncIdentities'];
updateIdentities: PreferencesController['updateIdentities'];
setSelectedAddress: PreferencesController['setSelectedAddress'];
setAccountLabel?: PreferencesController['setAccountLabel'];
encryptor?: any;
keyringBuilders?: any[];
cacheEncryptionKey?: boolean;
messenger: KeyringControllerMessenger;
state?: Partial<KeyringControllerState>;
};

/**
Expand Down Expand Up @@ -189,34 +190,30 @@ export class KeyringController extends BaseControllerV2<
/**
* Creates a KeyringController instance.
*
* @param options - The controller options.
* @param options.removeIdentity - Remove the identity with the given address.
* @param options.syncIdentities - Sync identities with the given list of addresses.
* @param options.updateIdentities - Generate an identity for each address given that doesn't already have an identity.
* @param options.setSelectedAddress - Set the selected address.
* @param options.setAccountLabel - Set a new name for account.
* @param messenger - A restricted controller messenger.
* @param config - Initial options used to configure this controller.
* @param state - Initial state to set on this controller.
* @param opts - Initial options used to configure this controller
* @param opts.removeIdentity - Remove the identity with the given address.
* @param opts.syncIdentities - Sync identities with the given list of addresses.
* @param opts.updateIdentities - Generate an identity for each address given that doesn't already have an identity.
* @param opts.setSelectedAddress - Set the selected address.
* @param opts.setAccountLabel - Set a new name for account.
* @param opts.encryptor - An optional object for defining encryption schemes.
* @param opts.keyringBuilders - Set a new name for account.
* @param opts.cacheEncryptionKey - Whether to cache or not encryption key.
* @param opts.messenger - A restricted controller messenger.
* @param opts.state - Initial state to set on this controller.
*/
constructor(
{
removeIdentity,
syncIdentities,
updateIdentities,
setSelectedAddress,
setAccountLabel,
}: {
removeIdentity: PreferencesController['removeIdentity'];
syncIdentities: PreferencesController['syncIdentities'];
updateIdentities: PreferencesController['updateIdentities'];
setSelectedAddress: PreferencesController['setSelectedAddress'];
setAccountLabel?: PreferencesController['setAccountLabel'];
},
messenger: KeyringControllerMessenger,
config?: KeyringControllerConfig,
state?: Partial<KeyringControllerState>,
) {
constructor({
removeIdentity,
syncIdentities,
updateIdentities,
setSelectedAddress,
setAccountLabel,
encryptor,
keyringBuilders,
cacheEncryptionKey,
messenger,
state,
}: KeyringControllerOptions) {
super({
name,
metadata: {
Expand All @@ -233,7 +230,10 @@ export class KeyringController extends BaseControllerV2<
});

this.#keyring = new EthKeyringController(
Object.assign({ initState: state }, config),
Object.assign(
{ initState: state },
{ encryptor, keyringBuilders, cacheEncryptionKey },
),
);
this.#keyring.memStore.subscribe(this.#fullUpdate.bind(this));
this.#keyring.store.subscribe(this.#fullUpdate.bind(this));
Expand Down

0 comments on commit 522e462

Please sign in to comment.