Skip to content

Commit 66c3f05

Browse files
committed
chore(multi-srp): review changes
1 parent f823f91 commit 66c3f05

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

packages/keyring-controller/src/KeyringController.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,7 +2699,7 @@ describe('KeyringController', () => {
26992699

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

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

packages/keyring-controller/src/KeyringController.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,10 +1516,7 @@ export class KeyringController extends BaseController<
15161516
)) as SelectedKeyring;
15171517
}
15181518
} else if ('id' in selector) {
1519-
const index = this.state.keyringsMetadata.findIndex(
1520-
(metadata) => metadata.id === selector.id,
1521-
);
1522-
keyring = this.#keyrings[index] as SelectedKeyring;
1519+
keyring = this.#getKeyringById(selector.id) as SelectedKeyring;
15231520
}
15241521

15251522
if (!keyring) {
@@ -1853,6 +1850,19 @@ export class KeyringController extends BaseController<
18531850
);
18541851
}
18551852

1853+
/**
1854+
* Get the keyring by id.
1855+
*
1856+
* @param keyringId - The id of the keyring.
1857+
* @returns The keyring.
1858+
*/
1859+
#getKeyringById(keyringId: string): EthKeyring<Json> | undefined {
1860+
const index = this.state.keyringsMetadata.findIndex(
1861+
(metadata) => metadata.id === keyringId,
1862+
);
1863+
return this.#keyrings[index];
1864+
}
1865+
18561866
/**
18571867
* Get the keyring by id or return the first keyring if the id is not found.
18581868
*
@@ -1864,10 +1874,7 @@ export class KeyringController extends BaseController<
18641874
return this.#keyrings[0] as EthKeyring<Json>;
18651875
}
18661876

1867-
const index = this.state.keyringsMetadata.findIndex(
1868-
(metadata) => metadata.id === keyringId,
1869-
);
1870-
return this.#keyrings[index];
1877+
return this.#getKeyringById(keyringId);
18711878
}
18721879

18731880
/**

0 commit comments

Comments
 (0)