Skip to content

Commit

Permalink
Merge branch 'feat/transport-kukai-wc2' into fix/wc_issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasGassmann committed Nov 3, 2023
2 parents 60563e7 + 8418778 commit 489f9c4
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 56 deletions.
2 changes: 1 addition & 1 deletion packages/beacon-core/src/managers/AccountManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class AccountManager {
}

public async getAccounts(): Promise<AccountInfo[]> {
return await this.storageManager.getAll() ?? []
return (await this.storageManager.getAll()) ?? []
}

public async getAccount(accountIdentifier: string): Promise<AccountInfo | undefined> {
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-core/src/managers/AppMetadataManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class AppMetadataManager {
}

public async getAppMetadataList(): Promise<AppMetadata[]> {
return await this.storageManager.getAll() ?? []
return (await this.storageManager.getAll()) ?? []
}

public async getAppMetadata(senderId: string): Promise<AppMetadata | undefined> {
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-core/src/managers/PeerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class PeerManager<
}

public async getPeers(): Promise<StorageKeyReturnType[T]> {
return await this.storageManager.getAll() ?? []
return (await this.storageManager.getAll()) ?? []
}

public async getPeer(publicKey: string): Promise<ArrayElem<StorageKeyReturnType[T]> | undefined> {
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-core/src/managers/StorageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class StorageManager<
}

public async getAll(): Promise<StorageKeyReturnType[T]> {
return await this.storage.get(this.storageKey) ?? []
return (await this.storage.get(this.storageKey)) ?? []
}

public async getOne(
Expand Down
6 changes: 4 additions & 2 deletions packages/beacon-core/src/storage/LocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
return Promise.resolve(Boolean(typeof window !== 'undefined') && Boolean(window.localStorage))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,5 @@ export abstract class CommunicationClient {
abstract unsubscribeFromEncryptedMessages(): Promise<void>
abstract unsubscribeFromEncryptedMessage(senderPublicKey: string): Promise<void>
// abstract send(message: string, recipient?: string): Promise<void>
public abstract sendMessage(
message: string,
peer?: PeerInfoType
): Promise<void>
public abstract sendMessage(message: string, peer?: PeerInfoType): Promise<void>
}
12 changes: 10 additions & 2 deletions packages/beacon-core/src/transports/clients/MessageBasedClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export abstract class MessageBasedClient extends CommunicationClient {
*/
protected abstract readonly activeListeners: Map<string, unknown>

constructor(protected readonly name: string, keyPair: KeyPair) {
constructor(
protected readonly name: string,
keyPair: KeyPair
) {
super(keyPair)
this.init().catch(console.error)
}
Expand Down Expand Up @@ -51,7 +54,12 @@ export abstract class MessageBasedClient extends CommunicationClient {
public async getPairingResponseInfo(
request: PostMessagePairingRequest
): Promise<PostMessagePairingResponse> {
return new PostMessagePairingResponse(request.id, this.name, await this.getPublicKey(), request.version)
return new PostMessagePairingResponse(
request.id,
this.name,
await this.getPublicKey(),
request.version
)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-dapp/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ const showNoPermissionAlert = async (): Promise<void> => {
}

/**
* Show a
* Show a
*/
const showInvalidActiveAccountState = async (): Promise<void> => {
await openAlert({
Expand Down Expand Up @@ -849,4 +849,4 @@ export class BeaconEventHandler {
}
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.`)
Expand Down Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<keyof MatrixState | 'all', OnStateChangedListener> =
new Map()

/**
* A promise that resolves once the client is ready
*/
private waitReadyPromise: Promise<void> = new Promise<void>(async (resolve, reject) => {
try {
await this.initFromStorage()
resolve()
} catch (error) {
reject(error)
}
})

constructor(private readonly storage: Storage) {}
private waitReadyPromise: Promise<void>

constructor(private readonly storage: Storage) {
this.waitReadyPromise = new Promise<void>(async (resolve, reject) => {
try {
await this.initFromStorage()
resolve()
} catch (error) {
reject(error)
}
})
}

/**
* Get an item from the state
Expand Down
5 changes: 4 additions & 1 deletion packages/beacon-transport-walletconnect/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
14 changes: 7 additions & 7 deletions packages/beacon-types/src/types/storage/StorageKeyReturnType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion packages/beacon-ui/src/components/pair-other/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
align-items: center;
justify-content: center;
color: #b5b8be;
}
}
2 changes: 1 addition & 1 deletion packages/beacon-ui/src/ui/toast/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 489f9c4

Please sign in to comment.