Skip to content

Commit

Permalink
fix: broken state
Browse files Browse the repository at this point in the history
  • Loading branch information
isordo committed Oct 23, 2023
1 parent 74f6042 commit aec0b54
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/beacon-core/src/transports/clients/ClientEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export const enum ClientEvents {
CLOSE_ALERT = 'CLOSE_ALERT',
RESET_STATE = 'RESET_STATE',
WC_ACK_NOTIFICATION = 'WC_ACK_NOTIFICATION',
UPDATE_ACCOUNT = 'UPDATE_ACCOUNT'
UPDATE_ACCOUNT = 'UPDATE_ACCOUNT',
CLEAR_WC_STORAGE = 'CLEAR_WC_STORAGE'
}
17 changes: 17 additions & 0 deletions packages/beacon-dapp/src/dapp-client/DAppClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,23 @@ export class DAppClient extends Client {
ClientEvents.UPDATE_ACCOUNT,
this.updateActiveAccountHandler.bind(this)
)
this.walletConnectTransport.setEventHandler(
ClientEvents.CLEAR_WC_STORAGE,
this.resetWCSnapshot.bind(this)
)
}

private async resetWCSnapshot() {
await Promise.all([
this.storage.delete(StorageKey.WC_2_CLIENT_SESSION),
this.storage.delete(StorageKey.WC_2_CORE_PAIRING),
this.storage.delete(StorageKey.WC_2_CORE_KEYCHAIN),
this.storage.delete(StorageKey.WC_2_CORE_MESSAGES),
this.storage.delete(StorageKey.WC_2_CLIENT_PROPOSAL),
this.storage.delete(StorageKey.WC_2_CORE_SUBSCRIPTION),
this.storage.delete(StorageKey.WC_2_CORE_HISTORY),
this.storage.delete(StorageKey.WC_2_CORE_EXPIRER)
])
}

private async updateActiveAccountHandler(address?: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,8 @@ export class WalletConnectCommunicationClient extends CommunicationClient {
for (let pairing of pairings) {
await signClient.core.pairing.disconnect({ topic: pairing.topic })
}
const fun = this.eventHandlers.get(ClientEvents.CLEAR_WC_STORAGE)
fun && (await fun())
}

private async closeSessions() {
Expand Down
8 changes: 7 additions & 1 deletion packages/beacon-types/src/types/storage/StorageKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ export enum StorageKey {
MATRIX_SELECTED_NODE = 'beacon:matrix-selected-node',
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'
WC_2_CLIENT_SESSION = 'wc@2:client:0.3//session',
WC_2_CORE_KEYCHAIN = 'wc@2:core:0.3//keychain',
WC_2_CORE_MESSAGES = 'wc@2:core:0.3//messages',
WC_2_CLIENT_PROPOSAL = 'wc@2:client:0.3//proposal',
WC_2_CORE_SUBSCRIPTION = 'wc@2:core:0.3//subscription',
WC_2_CORE_HISTORY = 'wc@2:core:0.3//history',
WC_2_CORE_EXPIRER = 'wc@2:core:0.3//expirer'
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@ export const defaultValues: StorageKeyReturnDefaults = {
[StorageKey.MATRIX_SELECTED_NODE]: undefined,
[StorageKey.MULTI_NODE_SETUP_DONE]: undefined,
[StorageKey.WC_2_CLIENT_SESSION]: undefined,
[StorageKey.WC_2_CORE_PAIRING]: undefined
[StorageKey.WC_2_CORE_PAIRING]: undefined,
[StorageKey.WC_2_CORE_KEYCHAIN]: undefined,
[StorageKey.WC_2_CORE_MESSAGES]: undefined,
[StorageKey.WC_2_CLIENT_PROPOSAL]: undefined,
[StorageKey.WC_2_CORE_SUBSCRIPTION]: undefined,
[StorageKey.WC_2_CORE_HISTORY]: undefined,
[StorageKey.WC_2_CORE_EXPIRER]: undefined,
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,11 @@ export interface StorageKeyReturnType {
[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
[StorageKey.WC_2_CORE_PAIRING]: string | undefined,
[StorageKey.WC_2_CORE_KEYCHAIN]: string | undefined,
[StorageKey.WC_2_CORE_MESSAGES]: string | undefined,
[StorageKey.WC_2_CLIENT_PROPOSAL]: string | undefined,
[StorageKey.WC_2_CORE_SUBSCRIPTION]: string | undefined,
[StorageKey.WC_2_CORE_HISTORY]: string | undefined,
[StorageKey.WC_2_CORE_EXPIRER]: string | undefined,
}

0 comments on commit aec0b54

Please sign in to comment.