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 023cdfa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 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
18 changes: 14 additions & 4 deletions packages/keyring-controller/src/KeyringController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,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 +1877,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 023cdfa

Please sign in to comment.