From 64e4263462b6fdd6c785952d13eb1f146cc4613c Mon Sep 17 00:00:00 2001 From: Isacco Date: Thu, 26 Oct 2023 11:03:03 +0200 Subject: [PATCH 1/4] fix: extends --- packages/beacon-core/src/storage/LocalStorage.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/beacon-core/src/storage/LocalStorage.ts b/packages/beacon-core/src/storage/LocalStorage.ts index a83066f0e..9af62fbd1 100644 --- a/packages/beacon-core/src/storage/LocalStorage.ts +++ b/packages/beacon-core/src/storage/LocalStorage.ts @@ -5,8 +5,10 @@ import { Storage, StorageKey, StorageKeyReturnType, defaultValues } from '@airga * * A storage that can be used in the browser */ -export class LocalStorage implements Storage { - constructor(private readonly prefix?: string) {} +export class LocalStorage extends Storage { + constructor(private readonly prefix?: string) { + super() + } public static async isSupported(): Promise { return Promise.resolve(Boolean(typeof window !== 'undefined') && Boolean(window.localStorage)) } From 6d99b1762adde5add1f7bdc3895e1f50979d9aa6 Mon Sep 17 00:00:00 2001 From: Isacco Date: Thu, 26 Oct 2023 11:32:21 +0200 Subject: [PATCH 2/4] fix: race condition --- .../src/matrix-client/MatrixClientStore.ts | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/beacon-transport-matrix/src/matrix-client/MatrixClientStore.ts b/packages/beacon-transport-matrix/src/matrix-client/MatrixClientStore.ts index 155b8f324..edfa6020a 100644 --- a/packages/beacon-transport-matrix/src/matrix-client/MatrixClientStore.ts +++ b/packages/beacon-transport-matrix/src/matrix-client/MatrixClientStore.ts @@ -52,24 +52,24 @@ export class MatrixClientStore { /** * Listeners that will be called when the state changes */ - private readonly onStateChangedListeners: Map< - keyof MatrixState | 'all', - OnStateChangedListener - > = new Map() + private readonly onStateChangedListeners: Map = + new Map() /** * A promise that resolves once the client is ready */ - private waitReadyPromise: Promise = new Promise(async (resolve, reject) => { - try { - await this.initFromStorage() - resolve() - } catch (error) { - reject(error) - } - }) - - constructor(private readonly storage: Storage) {} + private waitReadyPromise: Promise + + constructor(private readonly storage: Storage) { + this.waitReadyPromise = new Promise(async (resolve, reject) => { + try { + await this.initFromStorage() + resolve() + } catch (error) { + reject(error) + } + }) + } /** * Get an item from the state From 5d61cd543e5d384aba4a93b6c56b37ada9b5a704 Mon Sep 17 00:00:00 2001 From: Andreas Gassmann Date: Fri, 3 Nov 2023 14:56:17 +0100 Subject: [PATCH 3/4] chore: run prettier --- .../src/managers/AccountManager.ts | 2 +- .../src/managers/AppMetadataManager.ts | 2 +- .../beacon-core/src/managers/PeerManager.ts | 2 +- .../src/managers/StorageManager.ts | 2 +- .../transports/clients/CommunicationClient.ts | 5 +--- .../transports/clients/MessageBasedClient.ts | 12 +++++++-- packages/beacon-dapp/src/events.ts | 6 +++-- .../P2PCommunicationClient.ts | 25 ++++++++++--------- .../src/error.ts | 5 +++- .../src/components/pair-other/styles.css | 2 +- packages/beacon-ui/src/ui/alert/index.tsx | 10 +++----- packages/beacon-ui/src/ui/toast/index.tsx | 2 +- packages/beacon-ui/src/utils/platform.ts | 6 +++-- 13 files changed, 46 insertions(+), 35 deletions(-) diff --git a/packages/beacon-core/src/managers/AccountManager.ts b/packages/beacon-core/src/managers/AccountManager.ts index 7f0dba95b..1d6f85744 100644 --- a/packages/beacon-core/src/managers/AccountManager.ts +++ b/packages/beacon-core/src/managers/AccountManager.ts @@ -15,7 +15,7 @@ export class AccountManager { } public async getAccounts(): Promise { - return await this.storageManager.getAll() ?? [] + return (await this.storageManager.getAll()) ?? [] } public async getAccount(accountIdentifier: string): Promise { diff --git a/packages/beacon-core/src/managers/AppMetadataManager.ts b/packages/beacon-core/src/managers/AppMetadataManager.ts index 8c42c67e1..a77d4b2cd 100644 --- a/packages/beacon-core/src/managers/AppMetadataManager.ts +++ b/packages/beacon-core/src/managers/AppMetadataManager.ts @@ -14,7 +14,7 @@ export class AppMetadataManager { } public async getAppMetadataList(): Promise { - return await this.storageManager.getAll() ?? [] + return (await this.storageManager.getAll()) ?? [] } public async getAppMetadata(senderId: string): Promise { diff --git a/packages/beacon-core/src/managers/PeerManager.ts b/packages/beacon-core/src/managers/PeerManager.ts index 1fa4283a2..45cb49a26 100644 --- a/packages/beacon-core/src/managers/PeerManager.ts +++ b/packages/beacon-core/src/managers/PeerManager.ts @@ -25,7 +25,7 @@ export class PeerManager< } public async getPeers(): Promise { - return await this.storageManager.getAll() ?? [] + return (await this.storageManager.getAll()) ?? [] } public async getPeer(publicKey: string): Promise | undefined> { diff --git a/packages/beacon-core/src/managers/StorageManager.ts b/packages/beacon-core/src/managers/StorageManager.ts index 7f9aa80f4..a1890fdcd 100644 --- a/packages/beacon-core/src/managers/StorageManager.ts +++ b/packages/beacon-core/src/managers/StorageManager.ts @@ -35,7 +35,7 @@ export class StorageManager< } public async getAll(): Promise { - return await this.storage.get(this.storageKey) ?? [] + return (await this.storage.get(this.storageKey)) ?? [] } public async getOne( diff --git a/packages/beacon-core/src/transports/clients/CommunicationClient.ts b/packages/beacon-core/src/transports/clients/CommunicationClient.ts index f045ee740..5e4bc2d81 100644 --- a/packages/beacon-core/src/transports/clients/CommunicationClient.ts +++ b/packages/beacon-core/src/transports/clients/CommunicationClient.ts @@ -81,8 +81,5 @@ export abstract class CommunicationClient { abstract unsubscribeFromEncryptedMessages(): Promise abstract unsubscribeFromEncryptedMessage(senderPublicKey: string): Promise // abstract send(message: string, recipient?: string): Promise - public abstract sendMessage( - message: string, - peer?: PeerInfoType - ): Promise + public abstract sendMessage(message: string, peer?: PeerInfoType): Promise } diff --git a/packages/beacon-core/src/transports/clients/MessageBasedClient.ts b/packages/beacon-core/src/transports/clients/MessageBasedClient.ts index 291e610d1..75f0f178d 100644 --- a/packages/beacon-core/src/transports/clients/MessageBasedClient.ts +++ b/packages/beacon-core/src/transports/clients/MessageBasedClient.ts @@ -21,7 +21,10 @@ export abstract class MessageBasedClient extends CommunicationClient { */ protected abstract readonly activeListeners: Map - constructor(protected readonly name: string, keyPair: KeyPair) { + constructor( + protected readonly name: string, + keyPair: KeyPair + ) { super(keyPair) this.init().catch(console.error) } @@ -51,7 +54,12 @@ export abstract class MessageBasedClient extends CommunicationClient { public async getPairingResponseInfo( request: PostMessagePairingRequest ): Promise { - return new PostMessagePairingResponse(request.id, this.name, await this.getPublicKey(), request.version) + return new PostMessagePairingResponse( + request.id, + this.name, + await this.getPublicKey(), + request.version + ) } /** diff --git a/packages/beacon-dapp/src/events.ts b/packages/beacon-dapp/src/events.ts index 41280a929..36cb149c5 100644 --- a/packages/beacon-dapp/src/events.ts +++ b/packages/beacon-dapp/src/events.ts @@ -305,7 +305,7 @@ const showNoPermissionAlert = async (): Promise => { } /** - * Show a + * Show a */ const showInvalidActiveAccountState = async (): Promise => { await openAlert({ @@ -744,7 +744,9 @@ export class BeaconEventHandler { [BeaconEvent.NO_PERMISSIONS]: [defaultEventCallbacks.NO_PERMISSIONS], [BeaconEvent.ACTIVE_ACCOUNT_SET]: [defaultEventCallbacks.ACTIVE_ACCOUNT_SET], [BeaconEvent.ACTIVE_TRANSPORT_SET]: [defaultEventCallbacks.ACTIVE_TRANSPORT_SET], - [BeaconEvent.INVALID_ACTIVE_ACCOUNT_STATE]: [defaultEventCallbacks.INVALID_ACTIVE_ACCOUNT_STATE], + [BeaconEvent.INVALID_ACTIVE_ACCOUNT_STATE]: [ + defaultEventCallbacks.INVALID_ACTIVE_ACCOUNT_STATE + ], [BeaconEvent.SHOW_PREPARE]: [defaultEventCallbacks.SHOW_PREPARE], [BeaconEvent.HIDE_UI]: [defaultEventCallbacks.HIDE_UI], [BeaconEvent.PAIR_INIT]: [defaultEventCallbacks.PAIR_INIT], diff --git a/packages/beacon-transport-matrix/src/communication-client/P2PCommunicationClient.ts b/packages/beacon-transport-matrix/src/communication-client/P2PCommunicationClient.ts index de2ec08d1..7843f45ed 100644 --- a/packages/beacon-transport-matrix/src/communication-client/P2PCommunicationClient.ts +++ b/packages/beacon-transport-matrix/src/communication-client/P2PCommunicationClient.ts @@ -634,9 +634,12 @@ export class P2PCommunicationClient extends CommunicationClient { logger.log(`Waiting for join... Try: ${retry}`) return new Promise((resolve) => { - setTimeout(async () => { - resolve(this.waitForJoin(roomId, retry + 1)) - }, 100 * (retry > 50 ? 10 : 1)) // After the initial 5 seconds, retry only once per second + setTimeout( + async () => { + resolve(this.waitForJoin(roomId, retry + 1)) + }, + 100 * (retry > 50 ? 10 : 1) + ) // After the initial 5 seconds, retry only once per second }) } else { throw new Error(`No one joined after ${retry} tries.`) @@ -710,17 +713,15 @@ export class P2PCommunicationClient extends CommunicationClient { ? new PeerManager(this.storage, StorageKey.TRANSPORT_P2P_PEERS_DAPP) : new PeerManager(this.storage, StorageKey.TRANSPORT_P2P_PEERS_WALLET) const peers = await manager.getPeers() - const promiseArray = peers.map( - async (peer) => { - const hash = `@${await getHexHash(Buffer.from(peer.publicKey, 'hex'))}` - if (hash === senderHash) { - if (peer.relayServer !== relayServer) { - peer.relayServer = relayServer - await manager.addPeer(peer as ExtendedP2PPairingResponse) - } + const promiseArray = peers.map(async (peer) => { + const hash = `@${await getHexHash(Buffer.from(peer.publicKey, 'hex'))}` + if (hash === senderHash) { + if (peer.relayServer !== relayServer) { + peer.relayServer = relayServer + await manager.addPeer(peer as ExtendedP2PPairingResponse) } } - ) + }) await Promise.all(promiseArray) } diff --git a/packages/beacon-transport-walletconnect/src/error.ts b/packages/beacon-transport-walletconnect/src/error.ts index 151998f0c..b667fb44b 100644 --- a/packages/beacon-transport-walletconnect/src/error.ts +++ b/packages/beacon-transport-walletconnect/src/error.ts @@ -90,7 +90,10 @@ export class ActiveAccountUnspecified extends Error { export class InvalidNetworkOrAccount extends Error { name = 'InvalidNetworkOrAccount' - constructor(public network: string, public pkh: string) { + constructor( + public network: string, + public pkh: string + ) { super( `No permission. The combinaison "${network}" and "${pkh}" is not part of the active session.` ) diff --git a/packages/beacon-ui/src/components/pair-other/styles.css b/packages/beacon-ui/src/components/pair-other/styles.css index 79c865e8e..c488692ce 100644 --- a/packages/beacon-ui/src/components/pair-other/styles.css +++ b/packages/beacon-ui/src/components/pair-other/styles.css @@ -4,4 +4,4 @@ align-items: center; justify-content: center; color: #b5b8be; -} \ No newline at end of file +} diff --git a/packages/beacon-ui/src/ui/alert/index.tsx b/packages/beacon-ui/src/ui/alert/index.tsx index affceea42..d64d2e97e 100644 --- a/packages/beacon-ui/src/ui/alert/index.tsx +++ b/packages/beacon-ui/src/ui/alert/index.tsx @@ -618,12 +618,10 @@ const openAlert = async (config: AlertConfig): Promise => { } description={ hasExtension() - ? `Please connect below to use your ${ - currentWallet()?.name - } Wallet browser extension.` - : `To connect your ${ - currentWallet()?.name - } Wallet, install the browser extension.` + ? `Please connect below to use your ${currentWallet() + ?.name} Wallet browser extension.` + : `To connect your ${currentWallet() + ?.name} Wallet, install the browser extension.` } buttons={ hasExtension() diff --git a/packages/beacon-ui/src/ui/toast/index.tsx b/packages/beacon-ui/src/ui/toast/index.tsx index 0235fff8b..f2f185a1c 100644 --- a/packages/beacon-ui/src/ui/toast/index.tsx +++ b/packages/beacon-ui/src/ui/toast/index.tsx @@ -39,7 +39,7 @@ let globalTimeout: NodeJS.Timeout const createToast = (config: ToastConfig) => { const shadowRootEl = document.createElement('div') if (document.getElementById('beacon-toast-wrapper')) { - (document.getElementById('beacon-toast-wrapper') as HTMLElement).remove() + ;(document.getElementById('beacon-toast-wrapper') as HTMLElement).remove() } shadowRootEl.setAttribute('id', 'beacon-toast-wrapper') shadowRootEl.style.height = '0px' diff --git a/packages/beacon-ui/src/utils/platform.ts b/packages/beacon-ui/src/utils/platform.ts index 1e9ca66ff..1ebde27d1 100644 --- a/packages/beacon-ui/src/utils/platform.ts +++ b/packages/beacon-ui/src/utils/platform.ts @@ -35,9 +35,11 @@ const isIpad = (win: Window): boolean => { export const isPrivacyBrowser = (win: Window): boolean => testUserAgent(win, /Mobile DuckDuckGo/i) -export const isIOS = (win: Window): boolean => isPrivacyBrowser(win) || testUserAgent(win, /iPhone|iPod|Mobile DuckDuckGo/i) || isIpad(win) +export const isIOS = (win: Window): boolean => + isPrivacyBrowser(win) || testUserAgent(win, /iPhone|iPod|Mobile DuckDuckGo/i) || isIpad(win) -export const isAndroid = (win: Window): boolean => !isPrivacyBrowser(win) && testUserAgent(win, /android|sink/i) +export const isAndroid = (win: Window): boolean => + !isPrivacyBrowser(win) && testUserAgent(win, /android|sink/i) export const isTwBrowser = (win: Window): boolean => win && (win as any).ethereum?.isTrust == true From 8418778792b44cf9d9fa29163527501a7cfa5cde Mon Sep 17 00:00:00 2001 From: Andreas Gassmann Date: Fri, 3 Nov 2023 15:06:52 +0100 Subject: [PATCH 4/4] chore: run prettier --- .../src/transports/clients/ClientEvents.ts | 2 +- packages/beacon-dapp/src/events.ts | 2 +- .../src/types/storage/StorageKeyReturnDefaults.ts | 10 +++++----- .../src/types/storage/StorageKeyReturnType.ts | 14 +++++++------- packages/beacon-ui/src/utils/wallets.ts | 8 ++++---- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/beacon-core/src/transports/clients/ClientEvents.ts b/packages/beacon-core/src/transports/clients/ClientEvents.ts index 37a57a121..cd9a4cde0 100644 --- a/packages/beacon-core/src/transports/clients/ClientEvents.ts +++ b/packages/beacon-core/src/transports/clients/ClientEvents.ts @@ -2,5 +2,5 @@ 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' } diff --git a/packages/beacon-dapp/src/events.ts b/packages/beacon-dapp/src/events.ts index c7ebc3a8a..1e6733aae 100644 --- a/packages/beacon-dapp/src/events.ts +++ b/packages/beacon-dapp/src/events.ts @@ -849,4 +849,4 @@ export class BeaconEventHandler { } }) } -} \ No newline at end of file +} diff --git a/packages/beacon-types/src/types/storage/StorageKeyReturnDefaults.ts b/packages/beacon-types/src/types/storage/StorageKeyReturnDefaults.ts index eab8ab8fb..2c60dc048 100644 --- a/packages/beacon-types/src/types/storage/StorageKeyReturnDefaults.ts +++ b/packages/beacon-types/src/types/storage/StorageKeyReturnDefaults.ts @@ -30,9 +30,9 @@ export const defaultValues: StorageKeyReturnDefaults = { [StorageKey.WC_2_CLIENT_SESSION]: 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, + [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 } diff --git a/packages/beacon-types/src/types/storage/StorageKeyReturnType.ts b/packages/beacon-types/src/types/storage/StorageKeyReturnType.ts index a5d847386..8294500e1 100644 --- a/packages/beacon-types/src/types/storage/StorageKeyReturnType.ts +++ b/packages/beacon-types/src/types/storage/StorageKeyReturnType.ts @@ -40,11 +40,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_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, + [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 } diff --git a/packages/beacon-ui/src/utils/wallets.ts b/packages/beacon-ui/src/utils/wallets.ts index da0f87dea..aeb4f3c73 100644 --- a/packages/beacon-ui/src/utils/wallets.ts +++ b/packages/beacon-ui/src/utils/wallets.ts @@ -59,7 +59,7 @@ function setWallet(newWallet: MergedWallet, type: string, link: string) { choice = OSLink.DESKTOP } - newWallet.links[choice] = link; + newWallet.links[choice] = link } export function arrangeTopWallets(arr: MergedWallet[], walletIds: string[]): MergedWallet[] { @@ -108,7 +108,7 @@ export function mergeWallets(wallets: Wallet[]): MergedWallet[] { console.error('There should be a wallet') } if (!mergedWallets[index].descriptions.includes(wallet.description)) { - setWallet(mergedWallets[index], wallet.type, wallet.link); + setWallet(mergedWallets[index], wallet.type, wallet.link) mergedWallets[index].descriptions.push(wallet.description) } mergedWallets[index].types.push(wallet.type) @@ -124,8 +124,8 @@ export function mergeWallets(wallets: Wallet[]): MergedWallet[] { types: [wallet.type], firefoxId: wallet.key.includes('firefox') ? wallet.id : undefined } - - setWallet(newWallet, wallet.type, wallet.link); + + setWallet(newWallet, wallet.type, wallet.link) mergedWallets.push(newWallet) }