diff --git a/packages/beacon-dapp/src/dapp-client/DAppClient.ts b/packages/beacon-dapp/src/dapp-client/DAppClient.ts index 2742fa493..9071d4494 100644 --- a/packages/beacon-dapp/src/dapp-client/DAppClient.ts +++ b/packages/beacon-dapp/src/dapp-client/DAppClient.ts @@ -341,8 +341,8 @@ export class DAppClient extends Client { connectionInfo.origin === Origin.P2P ? this.p2pTransport : connectionInfo.origin === Origin.WALLETCONNECT - ? this.walletConnectTransport - : this.postMessageTransport ?? (await this.transport) + ? this.walletConnectTransport + : this.postMessageTransport ?? (await this.transport) if (relevantTransport) { const peers: ExtendedPeerInfo[] = await relevantTransport.getPeers() @@ -439,8 +439,8 @@ export class DAppClient extends Client { res.status === 426 ? console.error('Metrics are no longer supported for this version, please upgrade.') : console.warn( - 'Network error encountered. Metrics sharing have been automatically disabled.' - ) + 'Network error encountered. Metrics sharing have been automatically disabled.' + ) } this.enableMetrics = res.ok this.storage.set(StorageKey.ENABLE_METRICS, res.ok) @@ -497,7 +497,7 @@ export class DAppClient extends Client { } private async prepareRequest({ data }: any, isV3 = false) { - if (!this.multiTabChannel.isLeader()) { + if (!(await this.multiTabChannel.isLeader())) { return } @@ -794,7 +794,7 @@ export class DAppClient extends Client { this.postMessageTransport = this.walletConnectTransport = this.p2pTransport = - undefined + undefined this._activeAccount.isResolved() && this.clearActiveAccount() this._initPromise = undefined }, @@ -1064,7 +1064,7 @@ export class DAppClient extends Client { private async checkMakeRequest() { const isResolved = this._transport.isResolved() const isWCInstance = isResolved && (await this.transport) instanceof WalletConnectTransport - const isLeader = this.multiTabChannel.isLeader() + const isLeader = await this.multiTabChannel.isLeader() return !isResolved || !isWCInstance || isLeader || isMobileOS(window) } @@ -1359,9 +1359,9 @@ export class DAppClient extends Client { logger.time(true, logId) const res = (await this.checkMakeRequest()) ? this.makeRequestV3< - BlockchainRequestV3, - BeaconMessageWrapper> - >(request) + BlockchainRequestV3, + BeaconMessageWrapper> + >(request) : this.makeRequestBC(request) res.catch(async (requestError: ErrorResponse) => { @@ -1573,13 +1573,13 @@ export class DAppClient extends Client { const res = (await this.checkMakeRequest()) ? this.makeRequest< - SimulatedProofOfEventChallengeRequest, - SimulatedProofOfEventChallengeResponse - >(request) + SimulatedProofOfEventChallengeRequest, + SimulatedProofOfEventChallengeResponse + >(request) : this.makeRequestBC< - SimulatedProofOfEventChallengeRequest, - SimulatedProofOfEventChallengeResponse - >(request) + SimulatedProofOfEventChallengeRequest, + SimulatedProofOfEventChallengeResponse + >(request) res.catch(async (requestError: ErrorResponse) => { requestError.errorType === BeaconErrorType.ABORTED_ERROR @@ -2043,50 +2043,50 @@ export class DAppClient extends Client { request: BeaconRequestInputMessage, response: | { - account: AccountInfo - output: PermissionResponseOutput - blockExplorer: BlockExplorer - connectionContext: ConnectionContext - walletInfo: WalletInfo - } + account: AccountInfo + output: PermissionResponseOutput + blockExplorer: BlockExplorer + connectionContext: ConnectionContext + walletInfo: WalletInfo + } | { - account: AccountInfo - output: ProofOfEventChallengeResponse - blockExplorer: BlockExplorer - connectionContext: ConnectionContext - walletInfo: WalletInfo - } + account: AccountInfo + output: ProofOfEventChallengeResponse + blockExplorer: BlockExplorer + connectionContext: ConnectionContext + walletInfo: WalletInfo + } | { - account: AccountInfo - output: SimulatedProofOfEventChallengeResponse - blockExplorer: BlockExplorer - connectionContext: ConnectionContext - walletInfo: WalletInfo - } + account: AccountInfo + output: SimulatedProofOfEventChallengeResponse + blockExplorer: BlockExplorer + connectionContext: ConnectionContext + walletInfo: WalletInfo + } | { - account: AccountInfo - output: OperationResponseOutput - blockExplorer: BlockExplorer - connectionContext: ConnectionContext - walletInfo: WalletInfo - } + account: AccountInfo + output: OperationResponseOutput + blockExplorer: BlockExplorer + connectionContext: ConnectionContext + walletInfo: WalletInfo + } | { - output: SignPayloadResponseOutput - connectionContext: ConnectionContext - walletInfo: WalletInfo - } + output: SignPayloadResponseOutput + connectionContext: ConnectionContext + walletInfo: WalletInfo + } // | { // output: EncryptPayloadResponseOutput // connectionContext: ConnectionContext // walletInfo: WalletInfo // } | { - network: Network - output: BroadcastResponseOutput - blockExplorer: BlockExplorer - connectionContext: ConnectionContext - walletInfo: WalletInfo - } + network: Network + output: BroadcastResponseOutput + blockExplorer: BlockExplorer + connectionContext: ConnectionContext + walletInfo: WalletInfo + } ): Promise { this.events .emit(messageEvents[request.type].success, response) @@ -2328,7 +2328,7 @@ export class DAppClient extends Client { logger.log('makeRequest', 'sending message', request) try { - ;(await this.transport).send(payload, peer) + ; (await this.transport).send(payload, peer) if ( request.type !== BeaconMessageType.PermissionRequest || (this._activeAccount.isResolved() && (await this._activeAccount.promise)) @@ -2445,7 +2445,7 @@ export class DAppClient extends Client { logger.log('makeRequest', 'sending message', request) try { - ;(await this.transport).send(payload, peer) + ; (await this.transport).send(payload, peer) if ( request.message.type !== BeaconMessageType.PermissionRequest || (this._activeAccount.isResolved() && (await this._activeAccount.promise)) @@ -2492,9 +2492,9 @@ export class DAppClient extends Client { request: Optional ): Promise< | { - message: U - connectionInfo: ConnectionContext - } + message: U + connectionInfo: ConnectionContext + } | undefined > { if (!this._transport.isResolved()) { diff --git a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts index e68a64b97..56b53e0d6 100644 --- a/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts +++ b/packages/beacon-transport-walletconnect/src/communication-client/WalletConnectCommunicationClient.ts @@ -636,9 +636,9 @@ export class WalletConnectCommunicationClient extends CommunicationClient { this.notifyListeners(_pairingTopic, errorResponse) } }) - .then(() => { - if (!this.isMobileOS() && !this.isLeader()) { - this.clearState() + .then(async () => { + if (!this.isMobileOS() && !(await this.isLeader())) { + this.signClient = undefined } }) @@ -756,7 +756,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient { 'session_update' ) } - } catch {} + } catch { } } private async disconnect( @@ -796,8 +796,8 @@ export class WalletConnectCommunicationClient extends CommunicationClient { this.session?.pairingTopic === topic ? this.session : signClient.session - .getAll() - .find((session: SessionTypes.Struct) => session.pairingTopic === topic) + .getAll() + .find((session: SessionTypes.Struct) => session.pairingTopic === topic) if (!session) { return undefined