From bd5bfd7e80e49fad4d8e2ccad02da77fffe1cbcd Mon Sep 17 00:00:00 2001 From: kujtimprenkuSQA Date: Mon, 11 Dec 2023 13:17:25 +0100 Subject: [PATCH] Create the modal only once. --- .../src/lib/wallet-connect-client.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/wallet-connect/src/lib/wallet-connect-client.ts b/packages/wallet-connect/src/lib/wallet-connect-client.ts index 8356a73e5..c2c433b83 100644 --- a/packages/wallet-connect/src/lib/wallet-connect-client.ts +++ b/packages/wallet-connect/src/lib/wallet-connect-client.ts @@ -10,6 +10,7 @@ import type { class WalletConnectClient { private client: Client; private emitter: EventEmitterService; + private modal: WalletConnectModal; async init(opts: SignClientTypes.Options) { this.client = await Client.init(opts); @@ -47,11 +48,13 @@ class WalletConnectClient { projectId: string, chainId: string ) { - const walletConnectModal = new WalletConnectModal({ - projectId, - chains: [chainId], - explorerExcludedWalletIds: "ALL", - }); + if (!this.modal) { + this.modal = new WalletConnectModal({ + projectId, + chains: [chainId], + explorerExcludedWalletIds: "ALL", + }); + } return new Promise((resolve, reject) => { this.client @@ -59,11 +62,11 @@ class WalletConnectClient { .then(({ uri, approval }) => { if (uri) { if (qrCodeModal) { - walletConnectModal.openModal({ + this.modal.openModal({ uri, standaloneChains: [chainId], }); - walletConnectModal.subscribeModal(({ open }) => { + this.modal.subscribeModal(({ open }) => { if (!open) { reject(new Error("User cancelled pairing")); } @@ -76,7 +79,7 @@ class WalletConnectClient { approval() .then(resolve) .catch(reject) - .finally(() => walletConnectModal.closeModal()); + .finally(() => this.modal.closeModal()); }) .catch(reject); });