Skip to content

Commit

Permalink
fix: inconsitent state
Browse files Browse the repository at this point in the history
  • Loading branch information
isordo committed Oct 20, 2023
1 parent 15f48a7 commit a88681f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
25 changes: 19 additions & 6 deletions packages/beacon-dapp/src/dapp-client/DAppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1609,13 +1609,20 @@ export class DAppClient extends Client {
logger.log('makeRequest', 'after init')

const transport = await this.transport
const regexp = new RegExp(/^(\[\])$/)
const pairingMissing = regexp.test(
(await this.storage.get(StorageKey.WC_2_CORE_PAIRING)) ?? '[]'
)
const sessionMissing = regexp.test(
(await this.storage.get(StorageKey.WC_2_CLIENT_SESSION)) ?? '[]'
)

if (
requestInput.type === BeaconMessageType.PermissionRequest &&
transport instanceof WalletConnectTransport &&
(await this.getActiveAccount()) &&
!transport.pairings?.length &&
!transport.sessions?.length
pairingMissing &&
sessionMissing
) {
await this.channelClosedHandler()
throw new Error('No active pairing nor session found')
Expand Down Expand Up @@ -1738,13 +1745,19 @@ export class DAppClient extends Client {
}

const transport = await this.transport
const regexp = new RegExp(/^(\[\])$/)
const pairingMissing = regexp.test(
(await this.storage.get(StorageKey.WC_2_CORE_PAIRING)) ?? '[]'
)
const sessionMissing = regexp.test(
(await this.storage.get(StorageKey.WC_2_CLIENT_SESSION)) ?? '[]'
)

if (
requestInput.type === BeaconMessageType.PermissionRequest &&
transport instanceof WalletConnectTransport &&
(await this.getActiveAccount()) &&
!transport.pairings?.length &&
!transport.sessions?.length
pairingMissing &&
sessionMissing
) {
await this.channelClosedHandler()
throw new Error('No active pairing nor session found')
Expand Down Expand Up @@ -1949,4 +1962,4 @@ export class DAppClient extends Client {

return accountInfo
}
}
}
4 changes: 3 additions & 1 deletion packages/beacon-types/src/types/storage/StorageKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ export enum StorageKey {
MATRIX_PRESERVED_STATE = 'beacon:sdk-matrix-preserved-state',
MATRIX_PEER_ROOM_IDS = 'beacon:matrix-peer-rooms',
MATRIX_SELECTED_NODE = 'beacon:matrix-selected-node',
MULTI_NODE_SETUP_DONE = 'beacon:multi-node-setup'
MULTI_NODE_SETUP_DONE = 'beacon:multi-node-setup',
WC_2_CORE_PAIRING = 'wc@2:core:0.3//pairing',
WC_2_CLIENT_SESSION = 'wc@2:client:0.3//session'
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ export const defaultValues: StorageKeyReturnDefaults = {
[StorageKey.MATRIX_PRESERVED_STATE]: {},
[StorageKey.MATRIX_PEER_ROOM_IDS]: {},
[StorageKey.MATRIX_SELECTED_NODE]: undefined,
[StorageKey.MULTI_NODE_SETUP_DONE]: undefined
[StorageKey.MULTI_NODE_SETUP_DONE]: undefined,
[StorageKey.WC_2_CLIENT_SESSION]: undefined,
[StorageKey.WC_2_CORE_PAIRING]: undefined
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ export interface StorageKeyReturnType {
[StorageKey.MATRIX_PEER_ROOM_IDS]: { [key: string]: string | undefined }
[StorageKey.MATRIX_SELECTED_NODE]: string | undefined
[StorageKey.MULTI_NODE_SETUP_DONE]: boolean | undefined
[StorageKey.WC_2_CLIENT_SESSION]: string | undefined
[StorageKey.WC_2_CORE_PAIRING]: string | undefined
}

0 comments on commit a88681f

Please sign in to comment.