Skip to content

Commit

Permalink
fix: disconnect stuck state
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaccoSordo committed Jul 12, 2024
1 parent 66340e8 commit ecf6d84
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
17 changes: 11 additions & 6 deletions packages/beacon-dapp/src/dapp-client/DAppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,14 +895,19 @@ export class DAppClient extends Client {
this.multiTabChannel.postMessage({
type: 'DISCONNECT'
})
Array.from(this.openRequests.values()).forEach((promise) =>
}
Array.from(this.openRequests.entries())
.filter(([id, _promise]) => id !== 'session_update')
.forEach(([id, promise]) => {
promise.reject({
type: BeaconMessageType.Error,
errorType: BeaconErrorType.ABORTED_ERROR
} as any)
)
this.openRequests.clear()
}
errorType: BeaconErrorType.ABORTED_ERROR,
id,
senderId: '',
version: '1'
})
})
this.openRequests.clear()
this.debounceSetActiveAccount = false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,6 @@ export class WalletConnectCommunicationClient extends CommunicationClient {
this.signClient?.core.pairing.events.removeAllListeners('pairing_expire')
}

private abortErrorBuilder() {
if (!this.messageIds.length) {
return
}

const errorResponse: any = {
type: BeaconMessageType.Disconnect,
id: this.messageIds.pop(),
errorType: BeaconErrorType.ABORTED_ERROR
}
this.session && this.notifyListeners(this.getTopicFromSession(this.session), errorResponse)
this.messageIds = [] // reset
}

async unsubscribeFromEncryptedMessages(): Promise<void> {
this.activeListeners.clear()
this.channelOpeningListeners.clear()
Expand Down Expand Up @@ -700,9 +686,9 @@ export class WalletConnectCommunicationClient extends CommunicationClient {

public async close() {
this.storage.backup()
this.abortErrorBuilder()
await this.closePairings()
this.unsubscribeFromEncryptedMessages()
this.messageIds = []
}

private subscribeToSessionEvents(signClient: Client): void {
Expand Down

0 comments on commit ecf6d84

Please sign in to comment.