Skip to content

Commit 4930d04

Browse files
committed
fix plugin disconnect issue
1 parent 757efcc commit 4930d04

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

packages/no-modal/src/noModal.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp
365365

366366
log.debug("disconnected", this.status, this.connectedConnectorName);
367367
await Promise.all(
368-
Object.values(this.plugins).map((plugin) => {
368+
Object.values(this.plugins).map(async (plugin) => {
369+
if (!plugin.SUPPORTED_CONNECTORS.includes("all") && !plugin.SUPPORTED_CONNECTORS.includes(connector.name)) return;
370+
if (plugin.status === PLUGIN_STATUS.CONNECTED) return;
369371
return plugin.disconnect().catch((error: Web3AuthError) => {
370372
// swallow error if connector doesn't supports this plugin.
371373
if (error.code === 5211) {

packages/no-modal/src/plugins/wallet-services-plugin/plugin.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class WalletServicesPlugin extends SafeEventEmitter implements IPlugin {
4141
private isInitialized = false;
4242

4343
get proxyProvider(): SafeEventEmitterProvider | null {
44-
return this.wsEmbedInstance.provider ? (this.wsEmbedInstance.provider as unknown as SafeEventEmitterProvider) : null;
44+
return this.wsEmbedInstance?.provider ? (this.wsEmbedInstance.provider as unknown as SafeEventEmitterProvider) : null;
4545
}
4646

4747
async initWithWeb3Auth(web3auth: IWeb3AuthCore, _whiteLabel?: WhiteLabelData): Promise<void> {
@@ -101,32 +101,32 @@ export class WalletServicesPlugin extends SafeEventEmitter implements IPlugin {
101101
}
102102

103103
async showWalletConnectScanner(showWalletConnectParams?: BaseEmbedControllerState["showWalletConnect"]): Promise<void> {
104-
if (!this.wsEmbedInstance.isLoggedIn) throw WalletServicesPluginError.walletPluginNotConnected();
104+
if (!this.wsEmbedInstance?.isLoggedIn) throw WalletServicesPluginError.walletPluginNotConnected();
105105
return this.wsEmbedInstance.showWalletConnectScanner(showWalletConnectParams);
106106
}
107107

108108
async showCheckout(showCheckoutParams?: BaseEmbedControllerState["showCheckout"]): Promise<void> {
109-
if (!this.wsEmbedInstance.isLoggedIn) throw WalletServicesPluginError.walletPluginNotConnected();
109+
if (!this.wsEmbedInstance?.isLoggedIn) throw WalletServicesPluginError.walletPluginNotConnected();
110110
return this.wsEmbedInstance.showCheckout(showCheckoutParams);
111111
}
112112

113113
async showWalletUi(showWalletUiParams?: BaseEmbedControllerState["showWalletUi"]): Promise<void> {
114-
if (!this.wsEmbedInstance.isLoggedIn) throw WalletServicesPluginError.walletPluginNotConnected();
114+
if (!this.wsEmbedInstance?.isLoggedIn) throw WalletServicesPluginError.walletPluginNotConnected();
115115
return this.wsEmbedInstance.showWalletUi(showWalletUiParams);
116116
}
117117

118118
async showSwap(showSwapParams?: BaseEmbedControllerState["showSwap"]): Promise<void> {
119-
if (!this.wsEmbedInstance.isLoggedIn) throw WalletServicesPluginError.walletPluginNotConnected();
119+
if (!this.wsEmbedInstance?.isLoggedIn) throw WalletServicesPluginError.walletPluginNotConnected();
120120
return this.wsEmbedInstance.showSwap(showSwapParams);
121121
}
122122

123123
async cleanup(): Promise<void> {
124-
return this.wsEmbedInstance.cleanUp();
124+
return this.wsEmbedInstance?.cleanUp();
125125
}
126126

127127
async disconnect(): Promise<void> {
128128
// if web3auth is being used and connected to unsupported connector throw error
129-
if (this.wsEmbedInstance.isLoggedIn) {
129+
if (this.wsEmbedInstance?.isLoggedIn) {
130130
await this.wsEmbedInstance.logout();
131131
this.emit(PLUGIN_EVENTS.DISCONNECTED);
132132
this.status = PLUGIN_STATUS.DISCONNECTED;

0 commit comments

Comments
 (0)