Skip to content

Commit

Permalink
Use getKeyringsByType from core KeyringController (MetaMask#20210)
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptodev-2s authored Jul 31, 2023
1 parent d3236b3 commit 5df6a71
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
21 changes: 12 additions & 9 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,7 @@ export default class MetamaskController extends EventEmitter {
*/
async getSnapKeyring() {
if (!this.snapKeyring) {
let [snapKeyring] = this.keyringController.getKeyringsByType(
let [snapKeyring] = this.coreKeyringController.getKeyringsByType(
KeyringType.snap,
);
if (!snapKeyring) {
Expand Down Expand Up @@ -2932,7 +2932,7 @@ export default class MetamaskController extends EventEmitter {
ethQuery,
);

const [primaryKeyring] = keyringController.getKeyringsByType(
const [primaryKeyring] = this.coreKeyringController.getKeyringsByType(
KeyringType.hdKeyTree,
);
if (!primaryKeyring) {
Expand Down Expand Up @@ -3122,7 +3122,7 @@ export default class MetamaskController extends EventEmitter {
* Gets the mnemonic of the user's primary keyring.
*/
getPrimaryKeyringMnemonic() {
const [keyring] = this.keyringController.getKeyringsByType(
const [keyring] = this.coreKeyringController.getKeyringsByType(
KeyringType.hdKeyTree,
);
if (!keyring.mnemonic) {
Expand All @@ -3137,7 +3137,8 @@ export default class MetamaskController extends EventEmitter {
const custodyType = this.custodyController.getCustodyTypeByAddress(
toChecksumHexAddress(address),
);
const keyring = this.keyringController.getKeyringsByType(custodyType)[0];
const keyring =
this.coreKeyringController.getKeyringsByType(custodyType)[0];
return keyring?.getAccountDetails(address) ? keyring : undefined;
}
///: END:ONLY_INCLUDE_IN
Expand Down Expand Up @@ -3174,7 +3175,9 @@ export default class MetamaskController extends EventEmitter {
'MetamaskController:getKeyringForDevice - Unknown device',
);
}
let [keyring] = await this.keyringController.getKeyringsByType(keyringName);
let [keyring] = await this.coreKeyringController.getKeyringsByType(
keyringName,
);
if (!keyring) {
keyring = await this.keyringController.addNewKeyring(keyringName);
}
Expand Down Expand Up @@ -3387,7 +3390,7 @@ export default class MetamaskController extends EventEmitter {
await new Promise((resolve) => setTimeout(resolve, 5_000));
}

const [primaryKeyring] = this.keyringController.getKeyringsByType(
const [primaryKeyring] = this.coreKeyringController.getKeyringsByType(
KeyringType.hdKeyTree,
);
if (!primaryKeyring) {
Expand Down Expand Up @@ -3432,7 +3435,7 @@ export default class MetamaskController extends EventEmitter {
* encoded as an array of UTF-8 bytes.
*/
async verifySeedPhrase() {
const [primaryKeyring] = this.keyringController.getKeyringsByType(
const [primaryKeyring] = this.coreKeyringController.getKeyringsByType(
KeyringType.hdKeyTree,
);
if (!primaryKeyring) {
Expand Down Expand Up @@ -4649,14 +4652,14 @@ export default class MetamaskController extends EventEmitter {
* Locks MetaMask
*/
setLocked() {
const [trezorKeyring] = this.keyringController.getKeyringsByType(
const [trezorKeyring] = this.coreKeyringController.getKeyringsByType(
KeyringType.trezor,
);
if (trezorKeyring) {
trezorKeyring.dispose();
}

const [ledgerKeyring] = this.keyringController.getKeyringsByType(
const [ledgerKeyring] = this.coreKeyringController.getKeyringsByType(
KeyringType.ledger,
);
ledgerKeyring?.destroy?.();
Expand Down
14 changes: 7 additions & 7 deletions app/scripts/metamask-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ describe('MetaMaskController', function () {
]);
});

it('adds private key to keyrings in KeyringController', async function () {
it('adds private key to keyrings in core KeyringController', async function () {
const simpleKeyrings =
metamaskController.keyringController.getKeyringsByType(
metamaskController.coreKeyringController.getKeyringsByType(
KeyringType.imported,
);
const pubAddressHexArr = await simpleKeyrings[0].getAccounts();
Expand Down Expand Up @@ -595,7 +595,7 @@ describe('MetaMaskController', function () {
.connectHardware(HardwareDeviceNames.trezor, 0)
.catch(() => null);
const keyrings =
await metamaskController.keyringController.getKeyringsByType(
await metamaskController.coreKeyringController.getKeyringsByType(
KeyringType.trezor,
);
assert.deepEqual(
Expand All @@ -611,7 +611,7 @@ describe('MetaMaskController', function () {
.connectHardware(HardwareDeviceNames.ledger, 0)
.catch(() => null);
const keyrings =
await metamaskController.keyringController.getKeyringsByType(
await metamaskController.coreKeyringController.getKeyringsByType(
KeyringType.ledger,
);
assert.deepEqual(
Expand All @@ -638,7 +638,7 @@ describe('MetaMaskController', function () {
mnemonic: uint8ArrayMnemonic,
};
sinon
.stub(metamaskController.keyringController, 'getKeyringsByType')
.stub(metamaskController.coreKeyringController, 'getKeyringsByType')
.returns([mockHDKeyring]);

const recoveredMnemonic =
Expand Down Expand Up @@ -692,7 +692,7 @@ describe('MetaMaskController', function () {
.catch(() => null);
await metamaskController.forgetDevice(HardwareDeviceNames.trezor);
const keyrings =
await metamaskController.keyringController.getKeyringsByType(
await metamaskController.coreKeyringController.getKeyringsByType(
KeyringType.trezor,
);

Expand Down Expand Up @@ -755,7 +755,7 @@ describe('MetaMaskController', function () {

it('should set unlockedAccount in the keyring', async function () {
const keyrings =
await metamaskController.keyringController.getKeyringsByType(
await metamaskController.coreKeyringController.getKeyringsByType(
KeyringType.trezor,
);
assert.equal(keyrings[0].unlockedAccount, accountToUnlock);
Expand Down

0 comments on commit 5df6a71

Please sign in to comment.