Skip to content

Commit

Permalink
refactor: select account only when is new
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesposito committed Aug 1, 2023
1 parent d93be8f commit 027707a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>} The address of the newly-created account.
*/
async addNewAccount(accountCount) {
const isActionMetricsQueueE2ETest =
Expand All @@ -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;
}
Expand Down

0 comments on commit 027707a

Please sign in to comment.