Skip to content

Commit ba6e1e1

Browse files
committed
fix issue of switching custom chains in injected wallet
1 parent bb9120e commit ba6e1e1

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

packages/adapters/default-evm-adapter/src/injectedEvmAdapter.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class InjectedEvmAdapter extends BaseEvmAdapter<void> {
7171
async connect(): Promise<IProvider | null> {
7272
super.checkConnectionRequirements();
7373
if (!this.injectedProvider) throw WalletLoginError.connectionError("Injected provider is not available");
74+
if (!this.chainConfig) throw WalletLoginError.connectionError("Chain config is not available");
7475
this.status = ADAPTER_STATUS.CONNECTING;
7576
this.emit(ADAPTER_EVENTS.CONNECTING, { adapter: this.name });
7677
try {
@@ -85,15 +86,10 @@ class InjectedEvmAdapter extends BaseEvmAdapter<void> {
8586
}
8687
}
8788
this.status = ADAPTER_STATUS.CONNECTED;
88-
const chainDisconnectHandler = () => {
89-
this.disconnect();
90-
if (this.injectedProvider.removeListener) this.injectedProvider.removeListener("disconnect", chainDisconnectHandler);
91-
};
92-
this.injectedProvider.on("disconnect", chainDisconnectHandler);
9389
const accountDisconnectHandler = (accounts: string[]) => {
9490
if (accounts.length === 0) {
9591
this.disconnect();
96-
if (this.injectedProvider.removeListener) this.injectedProvider.removeListener("accountsChanged", accountDisconnectHandler);
92+
if (this.injectedProvider?.removeListener) this.injectedProvider.removeListener("accountsChanged", accountDisconnectHandler);
9793
}
9894
};
9995
this.injectedProvider.on("accountsChanged", accountDisconnectHandler);
@@ -114,6 +110,7 @@ class InjectedEvmAdapter extends BaseEvmAdapter<void> {
114110
}
115111

116112
async disconnect(options: { cleanup: boolean } = { cleanup: false }): Promise<void> {
113+
if (!this.injectedProvider) throw WalletLoginError.connectionError("Injected provider is not available");
117114
await super.disconnectSession();
118115
if (typeof this.injectedProvider?.removeAllListeners !== "undefined") this.injectedProvider?.removeAllListeners();
119116
try {

0 commit comments

Comments
 (0)