@@ -1381,7 +1381,7 @@ export class KeyringController<
13811381 ) ;
13821382 }
13831383
1384- const { keyring } = this . #keyrings[ keyringIndex ] ;
1384+ const { keyring, keyringV2 } = this . #keyrings[ keyringIndex ] ;
13851385
13861386 const isPrimaryKeyring = keyringIndex === 0 ;
13871387 const shouldRemoveKeyring = ( await keyring . getAccounts ( ) ) . length === 1 ;
@@ -1411,7 +1411,7 @@ export class KeyringController<
14111411
14121412 if ( shouldRemoveKeyring ) {
14131413 this . #keyrings. splice ( keyringIndex , 1 ) ;
1414- await this . #destroyKeyring( keyring ) ;
1414+ await this . #destroyKeyring( keyring , keyringV2 ) ;
14151415 }
14161416 } ) ;
14171417
@@ -2916,8 +2916,8 @@ export class KeyringController<
29162916 */
29172917 async #clearKeyrings( ) : Promise < void > {
29182918 this . #assertControllerMutexIsLocked( ) ;
2919- for ( const { keyring } of this . #keyrings) {
2920- await this . #destroyKeyring( keyring ) ;
2919+ for ( const { keyring, keyringV2 } of this . #keyrings) {
2920+ await this . #destroyKeyring( keyring , keyringV2 ) ;
29212921 }
29222922 this . #keyrings = [ ] ;
29232923 this . #unsupportedKeyrings = [ ] ;
@@ -2980,9 +2980,16 @@ export class KeyringController<
29802980 * clears the keyring bridge iframe from the DOM.
29812981 *
29822982 * @param keyring - The keyring to destroy.
2983+ * @param keyringV2 - The keyring v2 to destroy (if any).
29832984 */
2984- async #destroyKeyring( keyring : EthKeyring ) : Promise < void > {
2985+ async #destroyKeyring(
2986+ keyring : EthKeyring ,
2987+ keyringV2 ?: KeyringV2 ,
2988+ ) : Promise < void > {
29852989 await keyring . destroy ?.( ) ;
2990+ if ( keyringV2 ) {
2991+ await keyringV2 . destroy ?.( ) ;
2992+ }
29862993 }
29872994
29882995 /**
0 commit comments