-
-
Notifications
You must be signed in to change notification settings - Fork 134
Dispose or destroy keyrings on reference drop #233
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Left a few comments/suggestions
src/KeyringController.ts
Outdated
} | ||
|
||
if ('destroy' in keyring && typeof keyring.destroy === 'function') { | ||
keyring.destroy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Between the two names, I'm slightly more inclined to use destroy because we already use this method name for some controllers and middleware.
Perhaps we could align on this name? Not a blocker, but renaming the method on Trezor might be fairly easy (that package had a recent release)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting removing the dispose
call, then changing the method name on Trezor Keyring after this PR has been merged, or should we do it before this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either before or after; as long as that change gets included in core and in the clients prior to this one.
But this was a non-blocking suggestion, so whatever you'd prefer to do here is fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Gudahtt I created this issue to track this work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description
This PR calls the optional methods
destroy
anddispose
on keyrings that support them (Trezor and Ledger) whenever the reference to the keyring is dropped: when locked and when the last account from a keyring is removed.To avoid introducing one of the two (Trezor or Ledger) keyrings just to be used on tests, I extended the HDKeyring prototype to also present a
destroy
and adispose
method, in order to be spied on.Changes
Keyring.dispose
orKeyring.destroy
methods are called on any keyring reference dropReferences
Checklist