From 027707a57b58225fe97d57fe75d51c67d9a74c49 Mon Sep 17 00:00:00 2001 From: Michele Esposito Date: Mon, 31 Jul 2023 11:10:36 +0200 Subject: [PATCH] refactor: select account only when is new --- app/scripts/metamask-controller.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 8bf28f0d66a2..7eb291d89605 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -3378,7 +3378,7 @@ export default class MetamaskController extends EventEmitter { * Adds a new account to the default (first) HD seed phrase Keyring. * * @param accountCount - * @returns {} keyState + * @returns {Promise} The address of the newly-created account. */ async addNewAccount(accountCount) { const isActionMetricsQueueE2ETest = @@ -3388,10 +3388,15 @@ export default class MetamaskController extends EventEmitter { await new Promise((resolve) => setTimeout(resolve, 5_000)); } + const { identities: oldIdentities } = + this.preferencesController.store.getState(); + const { addedAccountAddress } = await this.coreKeyringController.addNewAccount(accountCount); - this.preferencesController.setSelectedAddress(addedAccountAddress); + if (Object.keys(oldIdentities).length === accountCount) { + this.preferencesController.setSelectedAddress(addedAccountAddress); + } return addedAccountAddress; }