From 500075fd553a2bbc5c57449f892c8d5193df7b8b Mon Sep 17 00:00:00 2001 From: Michele Esposito Date: Fri, 28 Jul 2023 13:47:28 +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 e4476bfaf229..2350c59103ca 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -3361,7 +3361,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 = @@ -3371,10 +3371,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 (!oldIdentities[addedAccountAddress]) { + this.preferencesController.setSelectedAddress(addedAccountAddress); + } return addedAccountAddress; }