Skip to content

Commit 5a456ff

Browse files
committed
fix: properly destroy v2 instances
1 parent 058b411 commit 5a456ff

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

packages/keyring-controller/src/KeyringController.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)