Closed lucia-w closed 9 months ago
Thanks for the PR. I'm not sure I understand the sequence of events here though.
Generally, we add one listener on connect, and when the wallet emits the disconnect event, or we disconnect it ourselves, the first thing we do is remove the event listener for that event, and then proceed to tear down the adapter's internal state. Since this occurs synchronously, it shouldn't be possible for this event to be handled multiple times.
Can you explain in what conditions you're seeing this issue?
Issue: if the wallet emits the disconnect event more than once, the
_disconnected
method will be added multiple times as an event listener. This might lead to unexpected issues.Fix: Added
_onDisconnectBound
to store the bound_disconnected
method. In the connect method, the_disconnected
method is bound and set to_onDisconnectBound
only if it hasn't been set already. This prevents multiple bindings of the same event handler.