From 50210ed4bea17ccecdf7ea9ae8f0b1ee37e5731b Mon Sep 17 00:00:00 2001 From: Isacco Date: Thu, 21 Sep 2023 11:53:31 +0200 Subject: [PATCH] fix: aligned fix with previous flow --- .../beacon-dapp/src/dapp-client/DAppClient.ts | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/packages/beacon-dapp/src/dapp-client/DAppClient.ts b/packages/beacon-dapp/src/dapp-client/DAppClient.ts index e103503e1..c25266dce 100644 --- a/packages/beacon-dapp/src/dapp-client/DAppClient.ts +++ b/packages/beacon-dapp/src/dapp-client/DAppClient.ts @@ -982,15 +982,6 @@ export class DAppClient extends Client { this.analytics.track('event', 'DAppClient', 'Permission requested') - await this.init() - - const transport = await this.transport - - if (transport instanceof WalletConnectTransport && !transport.pairings?.length) { - await this.channelClosedHandler() - throw new Error('Pairing expired.') - } - const { message, connectionInfo } = await this.makeRequest< PermissionRequest, PermissionResponse @@ -1560,6 +1551,17 @@ export class DAppClient extends Client { logger.timeLog(messageId, 'init done') logger.log('makeRequest', 'after init') + const transport = await this.transport + + if ( + requestInput.type === BeaconMessageType.PermissionRequest && + transport instanceof WalletConnectTransport && + !transport.pairings?.length + ) { + await this.channelClosedHandler() + throw new Error('Pairing expired.') + } + if (await this.addRequestAndCheckIfRateLimited()) { this.events .emit(BeaconEvent.LOCAL_RATE_LIMIT_REACHED) @@ -1607,7 +1609,7 @@ export class DAppClient extends Client { logger.log('makeRequest', 'sending message', request) logger.timeLog('makeRequest', messageId, 'sending') try { - await (await this.transport).send(payload, peer) + await transport.send(payload, peer) } catch (sendError) { this.events.emit(BeaconEvent.INTERNAL_ERROR, { text: 'Unable to send message. If this problem persists, please reset the connection and pair your wallet again.', @@ -1676,6 +1678,17 @@ export class DAppClient extends Client { throw new Error('rate limit reached') } + const transport = await this.transport + + if ( + requestInput.type === BeaconMessageType.PermissionRequest && + transport instanceof WalletConnectTransport && + !transport.pairings?.length + ) { + await this.channelClosedHandler() + throw new Error('Pairing expired.') + } + // if (!(await this.checkPermissions(requestInput.type as BeaconMessageType))) { // this.events.emit(BeaconEvent.NO_PERMISSIONS).catch((emitError) => console.warn(emitError)) @@ -1714,7 +1727,7 @@ export class DAppClient extends Client { logger.log('makeRequest', 'sending message', request) logger.timeLog('makeRequest', messageId, 'sending') try { - await (await this.transport).send(payload, peer) + await transport.send(payload, peer) } catch (sendError) { this.events.emit(BeaconEvent.INTERNAL_ERROR, { text: 'Unable to send message. If this problem persists, please reset the connection and pair your wallet again.',