Skip to content

Commit

Permalink
handle account disconnected in evm injected provider
Browse files Browse the repository at this point in the history
  • Loading branch information
tanguyenvn committed Oct 12, 2024
1 parent f71a18e commit 1c89f22
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/adapters/default-evm-adapter/src/injectedEvmAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,18 @@ class InjectedEvmAdapter extends BaseEvmAdapter<void> {
}
}
this.status = ADAPTER_STATUS.CONNECTED;
const disconnectHandler = () => {
// ready to be connected again
const chainDisconnectHandler = () => {
this.disconnect();
this.injectedProvider?.removeListener("disconnect", disconnectHandler);
this.injectedProvider?.removeListener("disconnect", chainDisconnectHandler);
};
this.injectedProvider.on("disconnect", disconnectHandler);
this.injectedProvider.on("disconnect", chainDisconnectHandler);
const accountDisconnectHandler = (accounts: string[]) => {
if (accounts.length === 0) {
this.disconnect();
this.injectedProvider?.removeListener("accountsChanged", accountDisconnectHandler);
}
};
this.injectedProvider.on("accountsChanged", accountDisconnectHandler);
this.emit(ADAPTER_EVENTS.CONNECTED, {
adapter: this.name,
reconnected: this.rehydrated,
Expand Down

0 comments on commit 1c89f22

Please sign in to comment.