1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00

Use getKeyringsByType from core KeyringController (#20210)

This commit is contained in:
cryptodev-2s 2023-07-31 16:45:20 +01:00 committed by GitHub
parent d3236b3b42
commit 5df6a71cea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 16 deletions

View File

@ -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) {
@ -2932,7 +2932,7 @@ export default class MetamaskController extends EventEmitter {
ethQuery,
);
const [primaryKeyring] = keyringController.getKeyringsByType(
const [primaryKeyring] = this.coreKeyringController.getKeyringsByType(
KeyringType.hdKeyTree,
);
if (!primaryKeyring) {
@ -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) {
@ -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
@ -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);
}
@ -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) {
@ -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) {
@ -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?.();

View File

@ -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();
@ -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(
@ -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(
@ -638,7 +638,7 @@ describe('MetaMaskController', function () {
mnemonic: uint8ArrayMnemonic,
};
sinon
.stub(metamaskController.keyringController, 'getKeyringsByType')
.stub(metamaskController.coreKeyringController, 'getKeyringsByType')
.returns([mockHDKeyring]);
const recoveredMnemonic =
@ -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,
);
@ -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);