Skip to content

Commit

Permalink
refactor: use new importaccount from keyring controller
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesposito committed Jul 25, 2023
1 parent 4b9a4d3 commit 7c6a29c
Show file tree
Hide file tree
Showing 17 changed files with 458 additions and 807 deletions.

This file was deleted.

75 changes: 0 additions & 75 deletions app/scripts/account-import-strategies/index.js

This file was deleted.

4 changes: 2 additions & 2 deletions app/scripts/metamask-controller.actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ describe('MetaMaskController', function () {

await metamaskController.createNewVaultAndKeychain('test@123');
await Promise.all([
metamaskController.importAccountWithStrategy('Private Key', [
metamaskController.importAccountWithStrategy('privateKey', [
importPrivkey,
]),
Promise.resolve(1).then(() => {
keyringControllerState1 = JSON.stringify(
metamaskController.keyringController.memStore.getState(),
);
metamaskController.importAccountWithStrategy('Private Key', [
metamaskController.importAccountWithStrategy('privateKey', [
importPrivkey,
]);
}),
Expand Down
19 changes: 7 additions & 12 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ import DecryptMessageController from './controllers/decrypt-message';
import TransactionController from './controllers/transactions';
import DetectTokensController from './controllers/detect-tokens';
import SwapsController from './controllers/swaps';
import accountImporter from './account-import-strategies';
import seedPhraseVerifier from './lib/seed-phrase-verifier';
import MetaMetricsController from './controllers/metametrics';
import { segment } from './lib/segment';
Expand Down Expand Up @@ -3533,21 +3532,17 @@ export default class MetamaskController extends EventEmitter {
* These are defined in app/scripts/account-import-strategies
* Each strategy represents a different way of serializing an Ethereum key pair.
*
* @param {string} strategy - A unique identifier for an account import strategy.
* @param {'privateKey' | 'json'} strategy - A unique identifier for an account import strategy.
* @param {any} args - The data required by that strategy to import an account.
*/
async importAccountWithStrategy(strategy, args) {
const privateKey = await accountImporter.importAccount(strategy, args);
const keyring = await this.keyringController.addNewKeyring(
KeyringType.imported,
[privateKey],
);
const [firstAccount] = await keyring.getAccounts();
// update accounts in preferences controller
const allAccounts = await this.keyringController.getAccounts();
this.preferencesController.setAddresses(allAccounts);
const { importedAccountAddress } =
await this.coreKeyringController.importAccountWithStrategy(
strategy,
args,
);
// set new account as selected
this.preferencesController.setSelectedAddress(firstAccount);
this.preferencesController.setSelectedAddress(importedAccountAddress);
}

// ---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/metamask-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ describe('MetaMaskController', function () {
beforeEach(async function () {
const password = 'a-fake-password';
await metamaskController.createNewVaultAndRestore(password, TEST_SEED);
await metamaskController.importAccountWithStrategy('Private Key', [
await metamaskController.importAccountWithStrategy('privateKey', [
importPrivkey,
]);
});
Expand Down
Loading

0 comments on commit 7c6a29c

Please sign in to comment.