diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 087765315..984fcedc0 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,33 +1,33 @@ // For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at // https://github.com/microsoft/vscode-dev-containers/tree/master/containers/typescript-node-12 { - "name": "Node.js 12 Custom", - "dockerFile": "Dockerfile", - // - // Use 'settings' to set *default* container specific settings.json values on container create. - // You can edit these settings after create using File > Preferences > Settings > Remote. - "settings": { - "terminal.integrated.shell.linux": "/bin/zsh" - }, - // - // Use 'appPort' to create a container with published ports. If the port isn't working, be sure - // your server accepts connections from all interfaces (0.0.0.0 or '*'), not just localhost. - // "appPort": [], - // - // Uncomment the next line to run commands after the container is created. - // "postCreateCommand": "yarn install", - // - // Uncomment the next line to have VS Code connect as an existing non-root user in the container. - // On Linux, by default, the container user's UID/GID will be updated to match your local user. See - // https://aka.ms/vscode-remote/containers/non-root for details on adding a non-root user if none exist. - // "remoteUser": "node", - // - // Add the IDs of extensions you want installed when the container is created in the array below. - "extensions": [ - "dbaeumer.vscode-eslint", - // TSLint is included for backwards compatibility, but is deprecated. - // See https://github.com/palantir/tslint/issues/4534 - "ms-vscode.vscode-typescript-tslint-plugin", - "esbenp.prettier-vscode" - ] -} \ No newline at end of file + "name": "Node.js 12 Custom", + "dockerFile": "Dockerfile", + // + // Use 'settings' to set *default* container specific settings.json values on container create. + // You can edit these settings after create using File > Preferences > Settings > Remote. + "settings": { + "terminal.integrated.shell.linux": "/bin/zsh" + }, + // + // Use 'appPort' to create a container with published ports. If the port isn't working, be sure + // your server accepts connections from all interfaces (0.0.0.0 or '*'), not just localhost. + // "appPort": [], + // + // Uncomment the next line to run commands after the container is created. + // "postCreateCommand": "yarn install", + // + // Uncomment the next line to have VS Code connect as an existing non-root user in the container. + // On Linux, by default, the container user's UID/GID will be updated to match your local user. See + // https://aka.ms/vscode-remote/containers/non-root for details on adding a non-root user if none exist. + // "remoteUser": "node", + // + // Add the IDs of extensions you want installed when the container is created in the array below. + "extensions": [ + "dbaeumer.vscode-eslint", + // TSLint is included for backwards compatibility, but is deprecated. + // See https://github.com/palantir/tslint/issues/4534 + "ms-vscode.vscode-typescript-tslint-plugin", + "esbenp.prettier-vscode" + ] +} diff --git a/src/P2PCommunicationClient.ts b/src/P2PCommunicationClient.ts index e9249e1ba..8129d6918 100644 --- a/src/P2PCommunicationClient.ts +++ b/src/P2PCommunicationClient.ts @@ -30,7 +30,7 @@ export class P2PCommunicationClient { private readonly keyPair: sodium.KeyPair, public readonly replicationCount: number, private readonly debug: boolean = false - ) { } + ) {} public getHandshakeInfo(): { name: string; pubKey: string; relayServer: string } { return { diff --git a/src/clients/dapp-client/DAppClient.ts b/src/clients/dapp-client/DAppClient.ts index 4e1d08c85..0edfa9187 100644 --- a/src/clients/dapp-client/DAppClient.ts +++ b/src/clients/dapp-client/DAppClient.ts @@ -359,7 +359,10 @@ export class DAppClient extends Client { ...requestInput } - const exposed = new ExposedPromise<{ message: BeaconMessage; connectionInfo: ConnectionContext }, BeaconErrorMessage>() + const exposed = new ExposedPromise< + { message: BeaconMessage; connectionInfo: ConnectionContext }, + BeaconErrorMessage + >() this.addOpenRequest(request.id, exposed) const payload = await new Serializer().serialize(request) diff --git a/src/events.ts b/src/events.ts index f87e74e93..0d9552f84 100644 --- a/src/events.ts +++ b/src/events.ts @@ -90,11 +90,11 @@ const showQrCode = async ( await openAlert(alertConfig) } -const emptyHandler = (eventType: BeaconEvent): BeaconEventHandlerFunction => - async (data?: unknown): Promise => { - logger.log('emptyHandler', eventType, data) - - } +const emptyHandler = (eventType: BeaconEvent): BeaconEventHandlerFunction => async ( + data?: unknown +): Promise => { + logger.log('emptyHandler', eventType, data) +} export type BeaconEventHandlerFunction = (data: T) => void | Promise @@ -122,22 +122,22 @@ export class BeaconEventHandler { private readonly callbackMap: { [key in BeaconEvent]: BeaconEventHandlerFunction[] } = { - [BeaconEvent.PERMISSION_REQUEST_SENT]: [defaultEventCallbacks.PERMISSION_REQUEST_SENT], - [BeaconEvent.PERMISSION_REQUEST_ERROR]: [defaultEventCallbacks.PERMISSION_REQUEST_ERROR], - [BeaconEvent.OPERATION_REQUEST_SENT]: [defaultEventCallbacks.OPERATION_REQUEST_SENT], - [BeaconEvent.OPERATION_REQUEST_ERROR]: [defaultEventCallbacks.OPERATION_REQUEST_ERROR], - [BeaconEvent.SIGN_REQUEST_SENT]: [defaultEventCallbacks.SIGN_REQUEST_SENT], - [BeaconEvent.SIGN_REQUEST_ERROR]: [defaultEventCallbacks.SIGN_REQUEST_ERROR], - [BeaconEvent.BROADCAST_REQUEST_SENT]: [defaultEventCallbacks.BROADCAST_REQUEST_SENT], - [BeaconEvent.BROADCAST_REQUEST_ERROR]: [defaultEventCallbacks.BROADCAST_REQUEST_ERROR], - [BeaconEvent.LOCAL_RATE_LIMIT_REACHED]: [defaultEventCallbacks.LOCAL_RATE_LIMIT_REACHED], - [BeaconEvent.NO_PERMISSIONS]: [defaultEventCallbacks.NO_PERMISSIONS], - [BeaconEvent.ACTIVE_ACCOUNT_SET]: [defaultEventCallbacks.ACTIVE_ACCOUNT_SET], - [BeaconEvent.ACTIVE_TRANSPORT_SET]: [defaultEventCallbacks.ACTIVE_TRANSPORT_SET], - [BeaconEvent.P2P_CHANNEL_CONNECT_SUCCESS]: [defaultEventCallbacks.P2P_CHANNEL_CONNECT_SUCCESS], - [BeaconEvent.P2P_LISTEN_FOR_CHANNEL_OPEN]: [defaultEventCallbacks.P2P_LISTEN_FOR_CHANNEL_OPEN], - [BeaconEvent.UNKNOWN]: [defaultEventCallbacks.UNKNOWN] - } + [BeaconEvent.PERMISSION_REQUEST_SENT]: [defaultEventCallbacks.PERMISSION_REQUEST_SENT], + [BeaconEvent.PERMISSION_REQUEST_ERROR]: [defaultEventCallbacks.PERMISSION_REQUEST_ERROR], + [BeaconEvent.OPERATION_REQUEST_SENT]: [defaultEventCallbacks.OPERATION_REQUEST_SENT], + [BeaconEvent.OPERATION_REQUEST_ERROR]: [defaultEventCallbacks.OPERATION_REQUEST_ERROR], + [BeaconEvent.SIGN_REQUEST_SENT]: [defaultEventCallbacks.SIGN_REQUEST_SENT], + [BeaconEvent.SIGN_REQUEST_ERROR]: [defaultEventCallbacks.SIGN_REQUEST_ERROR], + [BeaconEvent.BROADCAST_REQUEST_SENT]: [defaultEventCallbacks.BROADCAST_REQUEST_SENT], + [BeaconEvent.BROADCAST_REQUEST_ERROR]: [defaultEventCallbacks.BROADCAST_REQUEST_ERROR], + [BeaconEvent.LOCAL_RATE_LIMIT_REACHED]: [defaultEventCallbacks.LOCAL_RATE_LIMIT_REACHED], + [BeaconEvent.NO_PERMISSIONS]: [defaultEventCallbacks.NO_PERMISSIONS], + [BeaconEvent.ACTIVE_ACCOUNT_SET]: [defaultEventCallbacks.ACTIVE_ACCOUNT_SET], + [BeaconEvent.ACTIVE_TRANSPORT_SET]: [defaultEventCallbacks.ACTIVE_TRANSPORT_SET], + [BeaconEvent.P2P_CHANNEL_CONNECT_SUCCESS]: [defaultEventCallbacks.P2P_CHANNEL_CONNECT_SUCCESS], + [BeaconEvent.P2P_LISTEN_FOR_CHANNEL_OPEN]: [defaultEventCallbacks.P2P_LISTEN_FOR_CHANNEL_OPEN], + [BeaconEvent.UNKNOWN]: [defaultEventCallbacks.UNKNOWN] + } public async on( event: K, diff --git a/src/transports/P2PTransport.ts b/src/transports/P2PTransport.ts index dc4c46bc7..e5045eda6 100644 --- a/src/transports/P2PTransport.ts +++ b/src/transports/P2PTransport.ts @@ -139,9 +139,7 @@ export class P2PTransport extends Transport { public async send(message: string): Promise { const knownPeers = await this.storage.get(StorageKey.TRANSPORT_P2P_PEERS) - const promises = knownPeers.map((peer) => { - return this.client.sendMessage(peer.pubKey, message) - }) + const promises = knownPeers.map((peer) => this.client.sendMessage(peer.pubKey, message)) return (await Promise.all(promises))[0] } diff --git a/src/utils/check-permissions.ts b/src/utils/check-permissions.ts index 27390d83d..b478c733c 100644 --- a/src/utils/check-permissions.ts +++ b/src/utils/check-permissions.ts @@ -1,4 +1,4 @@ -import { BeaconMessageType, PermissionScope } from ".." +import { BeaconMessageType, PermissionScope } from '..' export const checkPermissions = async ( type: BeaconMessageType, @@ -15,4 +15,4 @@ export const checkPermissions = async ( default: return false } -} \ No newline at end of file +} diff --git a/src/utils/exposed-promise.ts b/src/utils/exposed-promise.ts index fb3483ca1..d13d73732 100644 --- a/src/utils/exposed-promise.ts +++ b/src/utils/exposed-promise.ts @@ -43,27 +43,25 @@ export class ExposedPromise { } constructor() { - this._promise = new Promise( - (innerResolve: Resolve, innerReject: Reject): void => { - this._resolve = async (value?: T | PromiseLike): Promise => { - this._status = ExposedPromiseStatus.PENDING - try { - this._promiseResult = await value - } catch (innerReason) { - return innerReject(innerReason) - } - this._status = ExposedPromiseStatus.RESOLVED - - return innerResolve(value) + this._promise = new Promise((innerResolve: Resolve, innerReject: Reject): void => { + this._resolve = async (value?: T | PromiseLike): Promise => { + this._status = ExposedPromiseStatus.PENDING + try { + this._promiseResult = await value + } catch (innerReason) { + return innerReject(innerReason) } - this._reject = async (reason?: U | PromiseLike): Promise => { - this._status = ExposedPromiseStatus.REJECTED - this._promiseError = await reason + this._status = ExposedPromiseStatus.RESOLVED - return innerReject(reason) - } + return innerResolve(value) + } + this._reject = async (reason?: U | PromiseLike): Promise => { + this._status = ExposedPromiseStatus.REJECTED + this._promiseError = await reason + + return innerReject(reason) } - ) + }) } public isPending(): boolean { diff --git a/src/utils/get-account-identifier.ts b/src/utils/get-account-identifier.ts index 8dfe0eec4..c562188b8 100644 --- a/src/utils/get-account-identifier.ts +++ b/src/utils/get-account-identifier.ts @@ -1,4 +1,4 @@ -import { Network } from ".." +import { Network } from '..' export const getAccountIdentifier = async (pubkey: string, network: Network): Promise => { const data: string[] = [pubkey, network.type] @@ -10,4 +10,4 @@ export const getAccountIdentifier = async (pubkey: string, network: Network): Pr } return data.join('-') -} \ No newline at end of file +} diff --git a/src/utils/is-extension-installed.ts b/src/utils/is-extension-installed.ts index d6d7f37e5..7194c0333 100644 --- a/src/utils/is-extension-installed.ts +++ b/src/utils/is-extension-installed.ts @@ -1,3 +1,3 @@ -import { PostMessageTransport } from "../transports/PostMessageTransport" +import { PostMessageTransport } from '../transports/PostMessageTransport' export const isChromeExtensionInstalled = PostMessageTransport.isAvailable()