From f180d0580457e1e9bd502293df327dfe138dd422 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 12 Aug 2020 12:41:00 +0530 Subject: remove excessive namespacing, format --- packages/taler-wallet-android/src/index.ts | 76 ++++++++++++++---------------- 1 file changed, 36 insertions(+), 40 deletions(-) (limited to 'packages/taler-wallet-android/src') diff --git a/packages/taler-wallet-android/src/index.ts b/packages/taler-wallet-android/src/index.ts index c949a4773..4430848c3 100644 --- a/packages/taler-wallet-android/src/index.ts +++ b/packages/taler-wallet-android/src/index.ts @@ -21,42 +21,47 @@ import { Wallet, getDefaultNodeWallet, DefaultNodeWalletArgs, - versions, - httpLib, - nodeThreadWorker, - promiseUtil, NodeHttpLib, - walletCoreApi, - walletNotifications, TalerErrorCode, makeErrorDetails, + handleWorkerError, + handleWorkerMessage, + HttpRequestLibrary, + OpenedPromise, + HttpResponse, + HttpRequestOptions, + openPromise, + Headers, + CoreApiEnvelope, + CoreApiResponse, + CoreApiResponseSuccess, + WalletNotification, + WALLET_EXCHANGE_PROTOCOL_VERSION, + WALLET_MERCHANT_PROTOCOL_VERSION, + handleCoreApiRequest, } from "taler-wallet-core"; import fs from "fs"; -export const handleWorkerError = nodeThreadWorker.handleWorkerError; -export const handleWorkerMessage = nodeThreadWorker.handleWorkerMessage; +export { handleWorkerError, handleWorkerMessage }; -export class AndroidHttpLib implements httpLib.HttpRequestLibrary { +export class AndroidHttpLib implements HttpRequestLibrary { useNfcTunnel = false; - private nodeHttpLib: httpLib.HttpRequestLibrary = new NodeHttpLib(); + private nodeHttpLib: HttpRequestLibrary = new NodeHttpLib(); private requestId = 1; private requestMap: { - [id: number]: promiseUtil.OpenedPromise; + [id: number]: OpenedPromise; } = {}; constructor(private sendMessage: (m: string) => void) {} - get( - url: string, - opt?: httpLib.HttpRequestOptions, - ): Promise { + get(url: string, opt?: HttpRequestOptions): Promise { if (this.useNfcTunnel) { const myId = this.requestId++; - const p = promiseUtil.openPromise(); + const p = openPromise(); this.requestMap[myId] = p; const request = { method: "get", @@ -78,11 +83,11 @@ export class AndroidHttpLib implements httpLib.HttpRequestLibrary { postJson( url: string, body: any, - opt?: httpLib.HttpRequestOptions, - ): Promise { + opt?: HttpRequestOptions, + ): Promise { if (this.useNfcTunnel) { const myId = this.requestId++; - const p = promiseUtil.openPromise(); + const p = openPromise(); this.requestMap[myId] = p; const request = { method: "postJson", @@ -106,9 +111,9 @@ export class AndroidHttpLib implements httpLib.HttpRequestLibrary { `no matching request for tunneled HTTP response, id=${myId}`, ); } - const headers = new httpLib.Headers(); + const headers = new Headers(); if (msg.status != 0) { - const resp: httpLib.HttpResponse = { + const resp: HttpResponse = { // FIXME: pass through this URL requestUrl: "", headers, @@ -125,7 +130,7 @@ export class AndroidHttpLib implements httpLib.HttpRequestLibrary { } } -function sendAkonoMessage(ev: walletCoreApi.CoreApiEnvelope): void { +function sendAkonoMessage(ev: CoreApiEnvelope): void { // @ts-ignore const sendMessage = globalThis.__akono_sendMessage; if (typeof sendMessage !== "function") { @@ -142,7 +147,7 @@ function sendAkonoMessage(ev: walletCoreApi.CoreApiEnvelope): void { class AndroidWalletMessageHandler { walletArgs: DefaultNodeWalletArgs | undefined; maybeWallet: Wallet | undefined; - wp = promiseUtil.openPromise(); + wp = openPromise(); httpLib = new NodeHttpLib(); /** @@ -152,10 +157,8 @@ class AndroidWalletMessageHandler { operation: string, id: string, args: any, - ): Promise { - const wrapResponse = ( - result: unknown, - ): walletCoreApi.CoreApiResponseSuccess => { + ): Promise { + const wrapResponse = (result: unknown): CoreApiResponseSuccess => { return { type: "response", id, @@ -166,9 +169,7 @@ class AndroidWalletMessageHandler { switch (operation) { case "init": { this.walletArgs = { - notifyHandler: async ( - notification: walletNotifications.WalletNotification, - ) => { + notifyHandler: async (notification: WalletNotification) => { sendAkonoMessage({ type: "notification", payload: notification }); }, persistentStoragePath: args.persistentStoragePath, @@ -182,8 +183,8 @@ class AndroidWalletMessageHandler { this.wp.resolve(w); return wrapResponse({ supported_protocol_versions: { - exchange: versions.WALLET_EXCHANGE_PROTOCOL_VERSION, - merchant: versions.WALLET_MERCHANT_PROTOCOL_VERSION, + exchange: WALLET_EXCHANGE_PROTOCOL_VERSION, + merchant: WALLET_MERCHANT_PROTOCOL_VERSION, }, }); } @@ -216,7 +217,7 @@ class AndroidWalletMessageHandler { } const wallet = await this.wp.promise; wallet.stop(); - this.wp = promiseUtil.openPromise(); + this.wp = openPromise(); this.maybeWallet = undefined; const w = await getDefaultNodeWallet(this.walletArgs); this.maybeWallet = w; @@ -228,12 +229,7 @@ class AndroidWalletMessageHandler { } default: { const wallet = await this.wp.promise; - return await walletCoreApi.handleCoreApiRequest( - wallet, - operation, - id, - args, - ); + return await handleCoreApiRequest(wallet, operation, id, args); } } } @@ -264,7 +260,7 @@ export function installAndroidWalletListener(): void { ); sendAkonoMessage(respMsg); } catch (e) { - const respMsg: walletCoreApi.CoreApiResponse = { + const respMsg: CoreApiResponse = { type: "error", id, operation, -- cgit v1.2.3