1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +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() { async getSnapKeyring() {
if (!this.snapKeyring) { if (!this.snapKeyring) {
let [snapKeyring] = this.keyringController.getKeyringsByType( let [snapKeyring] = this.coreKeyringController.getKeyringsByType(
KeyringType.snap, KeyringType.snap,
); );
if (!snapKeyring) { if (!snapKeyring) {
@ -2932,7 +2932,7 @@ export default class MetamaskController extends EventEmitter {
ethQuery, ethQuery,
); );
const [primaryKeyring] = keyringController.getKeyringsByType( const [primaryKeyring] = this.coreKeyringController.getKeyringsByType(
KeyringType.hdKeyTree, KeyringType.hdKeyTree,
); );
if (!primaryKeyring) { if (!primaryKeyring) {
@ -3122,7 +3122,7 @@ export default class MetamaskController extends EventEmitter {
* Gets the mnemonic of the user's primary keyring. * Gets the mnemonic of the user's primary keyring.
*/ */
getPrimaryKeyringMnemonic() { getPrimaryKeyringMnemonic() {
const [keyring] = this.keyringController.getKeyringsByType( const [keyring] = this.coreKeyringController.getKeyringsByType(
KeyringType.hdKeyTree, KeyringType.hdKeyTree,
); );
if (!keyring.mnemonic) { if (!keyring.mnemonic) {
@ -3137,7 +3137,8 @@ export default class MetamaskController extends EventEmitter {
const custodyType = this.custodyController.getCustodyTypeByAddress( const custodyType = this.custodyController.getCustodyTypeByAddress(
toChecksumHexAddress(address), toChecksumHexAddress(address),
); );
const keyring = this.keyringController.getKeyringsByType(custodyType)[0]; const keyring =
this.coreKeyringController.getKeyringsByType(custodyType)[0];
return keyring?.getAccountDetails(address) ? keyring : undefined; return keyring?.getAccountDetails(address) ? keyring : undefined;
} }
///: END:ONLY_INCLUDE_IN ///: END:ONLY_INCLUDE_IN
@ -3174,7 +3175,9 @@ export default class MetamaskController extends EventEmitter {
'MetamaskController:getKeyringForDevice - Unknown device', 'MetamaskController:getKeyringForDevice - Unknown device',
); );
} }
let [keyring] = await this.keyringController.getKeyringsByType(keyringName); let [keyring] = await this.coreKeyringController.getKeyringsByType(
keyringName,
);
if (!keyring) { if (!keyring) {
keyring = await this.keyringController.addNewKeyring(keyringName); keyring = await this.keyringController.addNewKeyring(keyringName);
} }
@ -3387,7 +3390,7 @@ export default class MetamaskController extends EventEmitter {
await new Promise((resolve) => setTimeout(resolve, 5_000)); await new Promise((resolve) => setTimeout(resolve, 5_000));
} }
const [primaryKeyring] = this.keyringController.getKeyringsByType( const [primaryKeyring] = this.coreKeyringController.getKeyringsByType(
KeyringType.hdKeyTree, KeyringType.hdKeyTree,
); );
if (!primaryKeyring) { if (!primaryKeyring) {
@ -3432,7 +3435,7 @@ export default class MetamaskController extends EventEmitter {
* encoded as an array of UTF-8 bytes. * encoded as an array of UTF-8 bytes.
*/ */
async verifySeedPhrase() { async verifySeedPhrase() {
const [primaryKeyring] = this.keyringController.getKeyringsByType( const [primaryKeyring] = this.coreKeyringController.getKeyringsByType(
KeyringType.hdKeyTree, KeyringType.hdKeyTree,
); );
if (!primaryKeyring) { if (!primaryKeyring) {
@ -4649,14 +4652,14 @@ export default class MetamaskController extends EventEmitter {
* Locks MetaMask * Locks MetaMask
*/ */
setLocked() { setLocked() {
const [trezorKeyring] = this.keyringController.getKeyringsByType( const [trezorKeyring] = this.coreKeyringController.getKeyringsByType(
KeyringType.trezor, KeyringType.trezor,
); );
if (trezorKeyring) { if (trezorKeyring) {
trezorKeyring.dispose(); trezorKeyring.dispose();
} }
const [ledgerKeyring] = this.keyringController.getKeyringsByType( const [ledgerKeyring] = this.coreKeyringController.getKeyringsByType(
KeyringType.ledger, KeyringType.ledger,
); );
ledgerKeyring?.destroy?.(); 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 = const simpleKeyrings =
metamaskController.keyringController.getKeyringsByType( metamaskController.coreKeyringController.getKeyringsByType(
KeyringType.imported, KeyringType.imported,
); );
const pubAddressHexArr = await simpleKeyrings[0].getAccounts(); const pubAddressHexArr = await simpleKeyrings[0].getAccounts();
@ -595,7 +595,7 @@ describe('MetaMaskController', function () {
.connectHardware(HardwareDeviceNames.trezor, 0) .connectHardware(HardwareDeviceNames.trezor, 0)
.catch(() => null); .catch(() => null);
const keyrings = const keyrings =
await metamaskController.keyringController.getKeyringsByType( await metamaskController.coreKeyringController.getKeyringsByType(
KeyringType.trezor, KeyringType.trezor,
); );
assert.deepEqual( assert.deepEqual(
@ -611,7 +611,7 @@ describe('MetaMaskController', function () {
.connectHardware(HardwareDeviceNames.ledger, 0) .connectHardware(HardwareDeviceNames.ledger, 0)
.catch(() => null); .catch(() => null);
const keyrings = const keyrings =
await metamaskController.keyringController.getKeyringsByType( await metamaskController.coreKeyringController.getKeyringsByType(
KeyringType.ledger, KeyringType.ledger,
); );
assert.deepEqual( assert.deepEqual(
@ -638,7 +638,7 @@ describe('MetaMaskController', function () {
mnemonic: uint8ArrayMnemonic, mnemonic: uint8ArrayMnemonic,
}; };
sinon sinon
.stub(metamaskController.keyringController, 'getKeyringsByType') .stub(metamaskController.coreKeyringController, 'getKeyringsByType')
.returns([mockHDKeyring]); .returns([mockHDKeyring]);
const recoveredMnemonic = const recoveredMnemonic =
@ -692,7 +692,7 @@ describe('MetaMaskController', function () {
.catch(() => null); .catch(() => null);
await metamaskController.forgetDevice(HardwareDeviceNames.trezor); await metamaskController.forgetDevice(HardwareDeviceNames.trezor);
const keyrings = const keyrings =
await metamaskController.keyringController.getKeyringsByType( await metamaskController.coreKeyringController.getKeyringsByType(
KeyringType.trezor, KeyringType.trezor,
); );
@ -755,7 +755,7 @@ describe('MetaMaskController', function () {
it('should set unlockedAccount in the keyring', async function () { it('should set unlockedAccount in the keyring', async function () {
const keyrings = const keyrings =
await metamaskController.keyringController.getKeyringsByType( await metamaskController.coreKeyringController.getKeyringsByType(
KeyringType.trezor, KeyringType.trezor,
); );
assert.equal(keyrings[0].unlockedAccount, accountToUnlock); assert.equal(keyrings[0].unlockedAccount, accountToUnlock);