@@ -724,9 +724,7 @@ export class KeyringController extends BaseController<
724724 return this . getOrAddQRKeyring ( ) ;
725725 }
726726
727- return this . #persistOrRollback( async ( ) =>
728- this . #newKeyring( type , opts , true ) ,
729- ) ;
727+ return this . #persistOrRollback( async ( ) => this . #newKeyring( type , opts ) ) ;
730728 }
731729
732730 /**
@@ -962,11 +960,9 @@ export class KeyringController extends BaseController<
962960 default :
963961 throw new Error ( `Unexpected import strategy: '${ strategy } '` ) ;
964962 }
965- const newKeyring = ( await this . #newKeyring(
966- KeyringTypes . simple ,
967- [ privateKey ] ,
968- true ,
969- ) ) as EthKeyring < Json > ;
963+ const newKeyring = ( await this . #newKeyring( KeyringTypes . simple , [
964+ privateKey ,
965+ ] ) ) as EthKeyring < Json > ;
970966 const accounts = await newKeyring . getAccounts ( ) ;
971967 return accounts [ 0 ] ;
972968 } ) ;
@@ -1237,13 +1233,6 @@ export class KeyringController extends BaseController<
12371233 encryptionSalt ,
12381234 ) ;
12391235 this . #setUnlocked( ) ;
1240-
1241- const qrKeyring = this . getQRKeyring ( ) ;
1242- if ( qrKeyring ) {
1243- // if there is a QR keyring, we need to subscribe
1244- // to its events after unlocking the vault
1245- this . #subscribeToQRKeyringEvents( qrKeyring ) ;
1246- }
12471236 } ) ;
12481237 }
12491238
@@ -1258,13 +1247,6 @@ export class KeyringController extends BaseController<
12581247 return this . #withRollback( async ( ) => {
12591248 this . #keyrings = await this . #unlockKeyrings( password ) ;
12601249 this . #setUnlocked( ) ;
1261-
1262- const qrKeyring = this . getQRKeyring ( ) ;
1263- if ( qrKeyring ) {
1264- // if there is a QR keyring, we need to subscribe
1265- // to its events after unlocking the vault
1266- this . #subscribeToQRKeyringEvents( qrKeyring ) ;
1267- }
12681250 } ) ;
12691251 }
12701252
@@ -1547,18 +1529,9 @@ export class KeyringController extends BaseController<
15471529 this . #assertControllerMutexIsLocked( ) ;
15481530
15491531 // QRKeyring is not yet compatible with Keyring type from @metamask /utils
1550- const qrKeyring = ( await this . #newKeyring( KeyringTypes . qr , {
1532+ return ( await this . #newKeyring( KeyringTypes . qr , {
15511533 accounts : [ ] ,
15521534 } ) ) as unknown as QRKeyring ;
1553-
1554- const accounts = await qrKeyring . getAccounts ( ) ;
1555- await this . #checkForDuplicate( KeyringTypes . qr , accounts ) ;
1556-
1557- this . #keyrings. push ( qrKeyring as unknown as EthKeyring < Json > ) ;
1558-
1559- this . #subscribeToQRKeyringEvents( qrKeyring ) ;
1560-
1561- return qrKeyring ;
15621535 }
15631536
15641537 /**
@@ -1881,11 +1854,7 @@ export class KeyringController extends BaseController<
18811854 async #createKeyringWithFirstAccount( type : string , opts ?: unknown ) {
18821855 this . #assertControllerMutexIsLocked( ) ;
18831856
1884- const keyring = ( await this . #newKeyring(
1885- type ,
1886- opts ,
1887- true ,
1888- ) ) as EthKeyring < Json > ;
1857+ const keyring = ( await this . #newKeyring( type , opts ) ) as EthKeyring < Json > ;
18891858
18901859 const [ firstAccount ] = await keyring . getAccounts ( ) ;
18911860 if ( ! firstAccount ) {
@@ -1901,15 +1870,10 @@ export class KeyringController extends BaseController<
19011870 *
19021871 * @param type - The type of keyring to add.
19031872 * @param data - The data to restore a previously serialized keyring.
1904- * @param persist - Whether to persist the keyring to the vault.
19051873 * @returns The new keyring.
19061874 * @throws If the keyring includes duplicated accounts.
19071875 */
1908- async #newKeyring(
1909- type : string ,
1910- data : unknown ,
1911- persist = false ,
1912- ) : Promise < EthKeyring < Json > > {
1876+ async #newKeyring( type : string , data : unknown ) : Promise < EthKeyring < Json > > {
19131877 this . #assertControllerMutexIsLocked( ) ;
19141878
19151879 const keyringBuilder = this . #getKeyringBuilderForType( type ) ;
@@ -1942,10 +1906,14 @@ export class KeyringController extends BaseController<
19421906
19431907 await this . #checkForDuplicate( type , await keyring . getAccounts ( ) ) ;
19441908
1945- if ( persist ) {
1946- this . #keyrings. push ( keyring ) ;
1909+ if ( type === KeyringTypes . qr ) {
1910+ // In case of a QR keyring type, we need to subscribe
1911+ // to its events after creating it
1912+ this . #subscribeToQRKeyringEvents( keyring as unknown as QRKeyring ) ;
19471913 }
19481914
1915+ this . #keyrings. push ( keyring ) ;
1916+
19491917 return keyring ;
19501918 }
19511919
@@ -1975,13 +1943,7 @@ export class KeyringController extends BaseController<
19751943
19761944 try {
19771945 const { type, data } = serialized ;
1978- const keyring = await this . #newKeyring( type , data ) ;
1979-
1980- // getAccounts also validates the accounts for some keyrings
1981- await keyring . getAccounts ( ) ;
1982- this . #keyrings. push ( keyring ) ;
1983-
1984- return keyring ;
1946+ return await this . #newKeyring( type , data ) ;
19851947 } catch ( _ ) {
19861948 this . #unsupportedKeyrings. push ( serialized ) ;
19871949 return undefined ;
0 commit comments