Skip to content

Commit

Permalink
chore(multi-srp): review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykLucka committed Feb 17, 2025
1 parent f823f91 commit 66c3f05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
3 changes: 1 addition & 2 deletions packages/keyring-controller/src/KeyringController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2699,7 +2699,7 @@ describe('KeyringController', () => {

const keyringId = controller.state.keyringsMetadata[1].id;
await expect(controller.verifySeedPhrase(keyringId)).rejects.toThrow(
'KeyringController - The keyring does not support the method verifySeedPhrase.',
KeyringControllerError.UnsupportedVerifySeedPhrase,
);
});
});
Expand Down Expand Up @@ -4060,7 +4060,6 @@ describe('KeyringController', () => {
await controller.persistAllKeyrings();
}
});
// TODO: Either fix this lint violation or explain why it's necessary to ignore.

messenger.subscribe('KeyringController:stateChange', listener);

Expand Down
23 changes: 15 additions & 8 deletions packages/keyring-controller/src/KeyringController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1516,10 +1516,7 @@ export class KeyringController extends BaseController<
)) as SelectedKeyring;
}
} else if ('id' in selector) {
const index = this.state.keyringsMetadata.findIndex(
(metadata) => metadata.id === selector.id,
);
keyring = this.#keyrings[index] as SelectedKeyring;
keyring = this.#getKeyringById(selector.id) as SelectedKeyring;
}

if (!keyring) {
Expand Down Expand Up @@ -1853,6 +1850,19 @@ export class KeyringController extends BaseController<
);
}

/**
* Get the keyring by id.
*
* @param keyringId - The id of the keyring.
* @returns The keyring.
*/
#getKeyringById(keyringId: string): EthKeyring<Json> | undefined {
const index = this.state.keyringsMetadata.findIndex(
(metadata) => metadata.id === keyringId,
);
return this.#keyrings[index];
}

/**
* Get the keyring by id or return the first keyring if the id is not found.
*
Expand All @@ -1864,10 +1874,7 @@ export class KeyringController extends BaseController<
return this.#keyrings[0] as EthKeyring<Json>;
}

const index = this.state.keyringsMetadata.findIndex(
(metadata) => metadata.id === keyringId,
);
return this.#keyrings[index];
return this.#getKeyringById(keyringId);
}

/**
Expand Down

0 comments on commit 66c3f05

Please sign in to comment.