Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Commit 9434b90

Browse files
committed
refactor: update utils package and rename dispose fn
1 parent 624ee59 commit 9434b90

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"@metamask/eth-hd-keyring": "^6.0.0",
4545
"@metamask/eth-sig-util": "^6.0.0",
4646
"@metamask/eth-simple-keyring": "^5.0.0",
47-
"@metamask/utils": "^5.0.0",
47+
"@metamask/utils": "^6.1.0",
4848
"obs-store": "^4.0.3"
4949
},
5050
"devDependencies": {

src/KeyringController.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ class KeyringController extends EventEmitter {
641641
if (accounts.length > 0) {
642642
validKeyrings.push(keyring);
643643
} else {
644-
await this.#disposeKeyring(keyring);
644+
await this.#destroyKeyring(keyring);
645645
}
646646
}),
647647
);
@@ -991,7 +991,7 @@ class KeyringController extends EventEmitter {
991991
async #clearKeyrings() {
992992
// clear keyrings from memory
993993
for (const keyring of this.keyrings) {
994-
await this.#disposeKeyring(keyring);
994+
await this.#destroyKeyring(keyring);
995995
}
996996
this.keyrings = [];
997997
this.memStore.updateState({
@@ -1000,23 +1000,16 @@ class KeyringController extends EventEmitter {
10001000
}
10011001

10021002
/**
1003-
* Dispose Keyring
1003+
* Destroy Keyring
10041004
*
1005-
* The Trezor Keyring has a method called `dispose` that removes the
1006-
* iframe from the DOM. The Ledger Keyring has a method called `destroy`
1007-
* that clears the keyring event listeners. This method checks if the provided
1008-
* keyring has either of these methods and calls them if they exist.
1005+
* Some keyrings support a method called `destroy`, that destroys the
1006+
* keyring along with removing all its event listeners and, in some cases,
1007+
* clears the keyring bridge iframe from the DOM.
10091008
*
1010-
* @param keyring - The keyring to dispose or destroy.
1009+
* @param keyring - The keyring to destroy.
10111010
*/
1012-
async #disposeKeyring(keyring: Keyring<Json>) {
1013-
if ('dispose' in keyring && typeof keyring.dispose === 'function') {
1014-
await keyring.dispose();
1015-
}
1016-
1017-
if ('destroy' in keyring && typeof keyring.destroy === 'function') {
1018-
await keyring.destroy();
1019-
}
1011+
async #destroyKeyring(keyring: Keyring<Json>) {
1012+
await keyring.destroy?.();
10201013
}
10211014

10221015
/**

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ __metadata:
10741074
"@metamask/eth-hd-keyring": ^6.0.0
10751075
"@metamask/eth-sig-util": ^6.0.0
10761076
"@metamask/eth-simple-keyring": ^5.0.0
1077-
"@metamask/utils": ^5.0.0
1077+
"@metamask/utils": ^6.1.0
10781078
"@types/jest": ^29.4.0
10791079
"@types/sinon": ^10.0.13
10801080
"@typescript-eslint/eslint-plugin": ^5.55.0
@@ -1152,16 +1152,16 @@ __metadata:
11521152
languageName: node
11531153
linkType: hard
11541154

1155-
"@metamask/utils@npm:^5.0.0":
1156-
version: 5.0.2
1157-
resolution: "@metamask/utils@npm:5.0.2"
1155+
"@metamask/utils@npm:^6.1.0":
1156+
version: 6.1.0
1157+
resolution: "@metamask/utils@npm:6.1.0"
11581158
dependencies:
11591159
"@ethereumjs/tx": ^4.1.2
11601160
"@types/debug": ^4.1.7
11611161
debug: ^4.3.4
11621162
semver: ^7.3.8
11631163
superstruct: ^1.0.3
1164-
checksum: eca82e42911b2840deb4f32f0f215c5ffd14d22d68afbbe92d3180e920e509e310777b15eab29def3448f3535b66596ceb4c23666ec846adacc8e1bb093ff882
1164+
checksum: d4eac3ce3c08674b8e9ef838d1661a5025690c6f266c26ebdb8e8d0da11fce786e54c326b5d9c6d33b262f37e7057e31d6545a3715613bd0a5bfa10e7755643a
11651165
languageName: node
11661166
linkType: hard
11671167

0 commit comments

Comments
 (0)