From 0db45b0bde7aae21c3768cf919b8b59970c9e813 Mon Sep 17 00:00:00 2001 From: IsaccoSordo Date: Sat, 27 Jul 2024 07:20:33 +0200 Subject: [PATCH] fix: p2p sendOperation failure --- .../beacon-dapp/src/dapp-client/DAppClient.ts | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/beacon-dapp/src/dapp-client/DAppClient.ts b/packages/beacon-dapp/src/dapp-client/DAppClient.ts index ef6067219..bc34af09e 100644 --- a/packages/beacon-dapp/src/dapp-client/DAppClient.ts +++ b/packages/beacon-dapp/src/dapp-client/DAppClient.ts @@ -1071,6 +1071,16 @@ export class DAppClient extends Client { }) } + private async checkMakeRequest() { + return ( + !this._transport.isResolved() || + (this._transport.isResolved() && + (!((await this.transport) instanceof WalletConnectTransport) || + ((await this.transport) instanceof WalletConnectTransport && + this.multiTabChannel.isLeader()))) + ) + } + /** * Will remove the account from the local storage and set a new active account if necessary. * @@ -1359,7 +1369,7 @@ export class DAppClient extends Client { const logId = `makeRequestV3 ${Date.now()}` logger.time(true, logId) - const res = this.multiTabChannel.isLeader() + const res = (await this.checkMakeRequest()) ? this.makeRequestV3< BlockchainRequestV3, BeaconMessageWrapper> @@ -1428,9 +1438,7 @@ export class DAppClient extends Client { logger.time(true, logId) const res = - this.multiTabChannel.isLeader() || - !this._activeAccount.isResolved() || - !(await this.getActiveAccount()) + (await this.checkMakeRequest()) || !(await this.getActiveAccount()) ? this.makeRequest(request) : this.makeRequestBC(request) @@ -1508,7 +1516,7 @@ export class DAppClient extends Client { this.sendMetrics('performance-metrics/save', await this.buildPayload('message', 'start')) const logId = `makeRequest ${Date.now()}` logger.time(true, logId) - const res = this.multiTabChannel.isLeader() + const res = (await this.checkMakeRequest()) ? this.makeRequest(request) : this.makeRequestBC(request) @@ -1575,7 +1583,7 @@ export class DAppClient extends Client { const logId = `makeRequest ${Date.now()}` logger.time(true, logId) - const res = this.multiTabChannel.isLeader() + const res = (await this.checkMakeRequest()) ? this.makeRequest< SimulatedProofOfEventChallengeRequest, SimulatedProofOfEventChallengeResponse @@ -1675,7 +1683,7 @@ export class DAppClient extends Client { this.sendMetrics('performance-metrics/save', await this.buildPayload('message', 'start')) const logId = `makeRequest ${Date.now()}` logger.time(true, logId) - const res = this.multiTabChannel.isLeader() + const res = (await this.checkMakeRequest()) ? this.makeRequest(request) : this.makeRequestBC(request) @@ -1791,7 +1799,7 @@ export class DAppClient extends Client { const logId = `makeRequest ${Date.now()}` logger.time(true, logId) - const res = this.multiTabChannel.isLeader() + const res = (await this.checkMakeRequest()) ? this.makeRequest(request) : this.makeRequestBC(request) @@ -1851,7 +1859,7 @@ export class DAppClient extends Client { this.sendMetrics('performance-metrics/save', await this.buildPayload('message', 'start')) const logId = `makeRequest ${Date.now()}` logger.time(true, logId) - const res = this.multiTabChannel.isLeader() + const res = (await this.checkMakeRequest()) ? this.makeRequest(request) : this.makeRequestBC(request)