From 76a8c673cd11c0836a2eef66227e34a7c0329b54 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 26df2ae43c91..06751f5d94e5 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -3375,7 +3375,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 = @@ -3385,10 +3385,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; }