From b2a8567e4dc1b96cdc6c907c9bd57fc7481fff38 Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Fri, 20 Dec 2024 16:56:16 +0100 Subject: [PATCH] fix: signClient.connect connection hanged --- packages/beacon-core/src/constants.ts | 4 ++-- .../WalletConnectCommunicationClient.ts | 21 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/beacon-core/src/constants.ts b/packages/beacon-core/src/constants.ts index f6958928b..a6abf4c88 100644 --- a/packages/beacon-core/src/constants.ts +++ b/packages/beacon-core/src/constants.ts @@ -1,5 +1,5 @@ -export const SDK_VERSION: string = '4.3.1' -export const BEACON_VERSION: string = '3' +export const SDK_VERSION: string = '4.3.2-beta.0' +export const BEACON_VERSION: string = '4' export const NOTIFICATION_ORACLE_URL: string = 'https://beacon-notification-oracle.dev.gke.papers.tech' diff --git a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts index 1a8f2177a..a05c08d76 100644 --- a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts +++ b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts @@ -625,11 +625,16 @@ export class WalletConnectCommunicationClient extends CommunicationClient { } } - const { uri, approval } = await signClient.connect(connectParams).catch((error) => { - logger.error(`Init error: ${error.message}`) - localStorage && localStorage.setItem(StorageKey.WC_INIT_ERROR, error.message) - throw new Error(error.message) - }) + const { uri, approval }: { uri: string, approval: () => Promise } = + await Promise.race([ + signClient.connect(connectParams), + new Promise((_, reject) => setTimeout(() => reject(new Error('The connection timed out.')), 60000)) + ]) + .catch((error) => { + logger.error(`Init error: ${error.message}`) + localStorage && localStorage.setItem(StorageKey.WC_INIT_ERROR, error.message) + throw new Error(error.message) + }) // Extract topic from uri. Format is wc:topic@2... const topic = getStringBetween(uri, ':', '@') @@ -1043,7 +1048,11 @@ export class WalletConnectCommunicationClient extends CommunicationClient { try { logger.debug('connect', [pairingTopic]) - const { approval } = await signClient.connect(connectParams) + const { approval }: { approval: () => Promise } = + await Promise.race([ + signClient.connect(connectParams), + new Promise((_, reject) => setTimeout(() => reject(new Error('The connection timed out.')), 60000)) + ]) logger.debug('before await approal', [pairingTopic]) const session = await approval() logger.debug('after await approal, have session', [pairingTopic])