diff --git a/packages/keyring-controller/src/KeyringController.test.ts b/packages/keyring-controller/src/KeyringController.test.ts index b9da878dfb..d9ce638972 100644 --- a/packages/keyring-controller/src/KeyringController.test.ts +++ b/packages/keyring-controller/src/KeyringController.test.ts @@ -262,15 +262,17 @@ describe('KeyringController', () => { const address = '0x51253087e6f8358b5f10c0a94315d69db3357859'; const newKeyring = { accounts: [address], type: 'Simple Key Pair' }; - const obj = await keyringController.importAccountWithStrategy( - AccountImportStrategy.privateKey, - [privateKey], - ); + const { keyringState, importedAccountAddress } = + await keyringController.importAccountWithStrategy( + AccountImportStrategy.privateKey, + [privateKey], + ); const modifiedState = { ...initialState, keyrings: [initialState.keyrings[0], newKeyring], }; - expect(obj).toStrictEqual(modifiedState); + expect(keyringState).toStrictEqual(modifiedState); + expect(importedAccountAddress).toBe(address); }); it('should not import account with strategy privateKey if wrong data is provided', async () => { @@ -303,17 +305,19 @@ describe('KeyringController', () => { const address = '0xb97c80fab7a3793bbe746864db80d236f1345ea7'; - const obj = await keyringController.importAccountWithStrategy( - AccountImportStrategy.json, - [input, somePassword], - ); + const { keyringState, importedAccountAddress } = + await keyringController.importAccountWithStrategy( + AccountImportStrategy.json, + [input, somePassword], + ); const newKeyring = { accounts: [address], type: 'Simple Key Pair' }; const modifiedState = { ...initialState, keyrings: [initialState.keyrings[0], newKeyring], }; - expect(obj).toStrictEqual(modifiedState); + expect(keyringState).toStrictEqual(modifiedState); + expect(importedAccountAddress).toBe(address); }); it('should throw when passed an unrecognized strategy', async () => { diff --git a/packages/keyring-controller/src/KeyringController.ts b/packages/keyring-controller/src/KeyringController.ts index ceb07aed0f..eb42bd2b90 100644 --- a/packages/keyring-controller/src/KeyringController.ts +++ b/packages/keyring-controller/src/KeyringController.ts @@ -356,12 +356,16 @@ export class KeyringController extends BaseController< * @param strategy - Import strategy name. * @param args - Array of arguments to pass to the underlying stategy. * @throws Will throw when passed an unrecognized strategy. - * @returns Promise resolving to current state when the import is complete. + * @returns Promise resolving to keyring current state and imported account + * address. */ async importAccountWithStrategy( strategy: AccountImportStrategy, args: any[], - ): Promise { + ): Promise<{ + keyringState: KeyringMemState; + importedAccountAddress: string; + }> { let privateKey; switch (strategy) { case 'privateKey': @@ -405,7 +409,10 @@ export class KeyringController extends BaseController< const allAccounts = await this.#keyring.getAccounts(); this.updateIdentities(allAccounts); this.setSelectedAddress(accounts[0]); - return this.fullUpdate(); + return { + keyringState: await this.fullUpdate(), + importedAccountAddress: accounts[0], + }; } /**