Skip to content

Commit

Permalink
fix: stuck state
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaccoSordo committed Oct 7, 2024
1 parent 2872b8f commit 6169a49
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 61 deletions.
110 changes: 55 additions & 55 deletions packages/beacon-dapp/src/dapp-client/DAppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -1359,9 +1359,9 @@ export class DAppClient extends Client {
logger.time(true, logId)
const res = (await this.checkMakeRequest())
? this.makeRequestV3<
BlockchainRequestV3<string>,
BeaconMessageWrapper<BlockchainResponseV3<string>>
>(request)
BlockchainRequestV3<string>,
BeaconMessageWrapper<BlockchainResponseV3<string>>
>(request)
: this.makeRequestBC<any, any>(request)

res.catch(async (requestError: ErrorResponse) => {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<void> {
this.events
.emit(messageEvents[request.type].success, response)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -2492,9 +2492,9 @@ export class DAppClient extends Client {
request: Optional<T, IgnoredRequestInputProperties>
): Promise<
| {
message: U
connectionInfo: ConnectionContext
}
message: U
connectionInfo: ConnectionContext
}
| undefined
> {
if (!this._transport.isResolved()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})

Expand Down Expand Up @@ -756,7 +756,7 @@ export class WalletConnectCommunicationClient extends CommunicationClient {
'session_update'
)
}
} catch {}
} catch { }
}

private async disconnect(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6169a49

Please sign in to comment.