From 79baaea03a2e0b36c43c10313c182158277d1e11 Mon Sep 17 00:00:00 2001 From: web3max Date: Fri, 12 Apr 2024 11:27:14 +0800 Subject: [PATCH] fix: optimize. --- src/lib/wallets/WalletConnectorHandler/UnisatConnector.ts | 8 ++------ .../WalletEventListenerHandler/TronLinkEventListener.ts | 3 +++ src/lib/wallets/index.ts | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/lib/wallets/WalletConnectorHandler/UnisatConnector.ts b/src/lib/wallets/WalletConnectorHandler/UnisatConnector.ts index 9c39504..a6bcbbb 100644 --- a/src/lib/wallets/WalletConnectorHandler/UnisatConnector.ts +++ b/src/lib/wallets/WalletConnectorHandler/UnisatConnector.ts @@ -42,12 +42,8 @@ export class UnisatConnector extends WalletConnector { } async switchNetwork(chainId: string): Promise { - try { - const { provider } = this.context - await provider.switchNetwork(chainId) - } catch (err) { - console.error(err) - } + const { provider } = this.context + await provider.switchNetwork(chainId) } async signData(data: SignDataType): Promise { diff --git a/src/lib/wallets/WalletEventListenerHandler/TronLinkEventListener.ts b/src/lib/wallets/WalletEventListenerHandler/TronLinkEventListener.ts index 27c8f9f..ed2bd40 100644 --- a/src/lib/wallets/WalletEventListenerHandler/TronLinkEventListener.ts +++ b/src/lib/wallets/WalletEventListenerHandler/TronLinkEventListener.ts @@ -26,6 +26,7 @@ export class TronLinkEventListener extends WalletEventListener { const isAuth = event.data?.message?.data?.data?.isAuth if (!_chainId || !isAuth || eventTabReplyDebounce) { + // shim disconnect if (_chainId && isAuth === false) { this.removeEvents() this.context.address = undefined @@ -37,6 +38,7 @@ export class TronLinkEventListener extends WalletEventListener { return } + // switch network check eventTabReplyDebounce = true globalThis.setTimeout(() => { eventTabReplyDebounce = false @@ -129,6 +131,7 @@ export class TronLinkEventListener extends WalletEventListener { } if (event.data?.message?.action === 'disconnect') { + // shim disconnect this.removeEvents() this.context.address = undefined this.context.chainId = undefined diff --git a/src/lib/wallets/index.ts b/src/lib/wallets/index.ts index 886d431..3129feb 100644 --- a/src/lib/wallets/index.ts +++ b/src/lib/wallets/index.ts @@ -180,7 +180,7 @@ class WalletSDK { async sendTransaction(data: ISendTrxParams): Promise { const isInit = await this.initWallet() - if (!isInit) { + if (!isInit && !this.walletTransaction) { // eslint-disable-next-line lingui/no-unlocalized-strings throw new CustomError(errno.failedToInitializeWallet, 'sendTransaction: Please initialize wallet first') }