Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use importAccountWithStrategy from core KeyringController #19815

Merged
merged 4 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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 @@ -172,14 +172,14 @@ describe('MetaMaskController', function () {

await metamaskController.createNewVaultAndKeychain('test@123');
await Promise.all([
metamaskController.importAccountWithStrategy('Private Key', [
metamaskController.importAccountWithStrategy('privateKey', [
Copy link
Contributor

@mcmire mcmire Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It might be nice if we can import an enum and use that here (and other places) so we can see the significance of this value. Not a big deal if that's not doable though.

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 @@ -190,7 +190,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 @@ -3548,21 +3547,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 @@ -326,7 +326,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