Skip to content

Commit

Permalink
fix: p2p sendOperation failure
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaccoSordo committed Jul 27, 2024
1 parent fc45a36 commit 0db45b0
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions packages/beacon-dapp/src/dapp-client/DAppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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<string>,
BeaconMessageWrapper<BlockchainResponseV3<string>>
Expand Down Expand Up @@ -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<PermissionRequest, PermissionResponse>(request)
: this.makeRequestBC<PermissionRequest, PermissionResponse>(request)

Expand Down Expand Up @@ -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<ProofOfEventChallengeRequest, ProofOfEventChallengeResponse>(request)
: this.makeRequestBC<ProofOfEventChallengeRequest, ProofOfEventChallengeResponse>(request)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<SignPayloadRequest, SignPayloadResponse>(request)
: this.makeRequestBC<SignPayloadRequest, SignPayloadResponse>(request)

Expand Down Expand Up @@ -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<OperationRequest, OperationResponse>(request)
: this.makeRequestBC<OperationRequest, OperationResponse>(request)

Expand Down Expand Up @@ -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<BroadcastRequest, BroadcastResponse>(request)
: this.makeRequestBC<BroadcastRequest, BroadcastResponse>(request)

Expand Down

0 comments on commit 0db45b0

Please sign in to comment.