From 56ece296e0e13de3c796a4ac317c6ce9e4fd7c28 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 23 Jul 2020 19:24:00 +0530 Subject: implement common wallet-core API handler --- src/android/index.ts | 115 ++++----------------------------------------------- 1 file changed, 7 insertions(+), 108 deletions(-) (limited to 'src/android') diff --git a/src/android/index.ts b/src/android/index.ts index d7a5897a1..b9131a6df 100644 --- a/src/android/index.ts +++ b/src/android/index.ts @@ -38,6 +38,7 @@ import { WALLET_MERCHANT_PROTOCOL_VERSION, } from "../operations/versions"; import { Amounts } from "../util/amounts"; +import { handleCoreApiRequest } from "../walletCoreApiHandler"; // @ts-ignore: special built-in module //import akono = require("akono"); @@ -168,88 +169,8 @@ class AndroidWalletMessageHandler { }, }; } - case "getTransactions": { - const wallet = await this.wp.promise; - return await wallet.getTransactions(args); - } - case "abortProposal": { - const wallet = await this.wp.promise; - if (typeof args.proposalId !== "string") { - throw Error("propsalId must be a string"); - } - return await wallet.refuseProposal(args.proposalId); - } - case "getBalances": { - const wallet = await this.wp.promise; - return await wallet.getBalances(); - } - case "getPendingOperations": { - const wallet = await this.wp.promise; - return await wallet.getPendingOperations(); - } - case "listExchanges": { - const wallet = await this.wp.promise; - return await wallet.getExchanges(); - } - case "addExchange": { - const wallet = await this.wp.promise; - await wallet.updateExchangeFromUrl(args.exchangeBaseUrl); - return {}; - } - case "getWithdrawalDetailsForAmount": { - const wallet = await this.wp.promise; - return await wallet.getWithdrawalDetailsForAmount( - args.exchangeBaseUrl, - args.amount, - ); - } - case "withdrawTestkudos": { - const wallet = await this.wp.promise; - try { - await withdrawTestBalance(wallet); - } catch (e) { - console.log("error during withdrawTestBalance", e); - } - return {}; - } case "getHistory": { - const wallet = await this.wp.promise; - return await wallet.getHistory(); - } - case "getExchangeTos": { - const wallet = await this.wp.promise; - const exchangeBaseUrl = args.exchangeBaseUrl; - return wallet.getExchangeTos(exchangeBaseUrl); - } - case "setExchangeTosAccepted": { - const wallet = await this.wp.promise; - await wallet.acceptExchangeTermsOfService( - args.exchangeBaseUrl, - args.acceptedEtag, - ); - return {}; - } - case "retryPendingNow": { - const wallet = await this.wp.promise; - await wallet.runPending(true); - return {}; - } - case "preparePay": { - const wallet = await this.wp.promise; - return await wallet.preparePayForUri(args.url); - break; - } - case "confirmPay": { - const wallet = await this.wp.promise; - return await wallet.confirmPay(args.proposalId, args.sessionId); - } - case "acceptManualWithdrawal": { - const wallet = await this.wp.promise; - const res = await wallet.acceptManualWithdrawal( - args.exchangeBaseUrl, - Amounts.parseOrThrow(args.amount), - ); - return res; + return []; } case "startTunnel": { // this.httpLib.useNfcTunnel = true; @@ -263,31 +184,6 @@ class AndroidWalletMessageHandler { // httpLib.handleTunnelResponse(msg.args); throw Error("not implemented"); } - case "getWithdrawDetailsForUri": { - const wallet = await this.wp.promise; - return await wallet.getWithdrawDetailsForUri( - args.talerWithdrawUri, - args.selectedExchange, - ); - } - case "applyRefund": { - const wallet = await this.wp.promise; - return await wallet.applyRefund(args.talerRefundUri); - } - case "acceptExchangeTermsOfService": { - const wallet = await this.wp.promise; - return await wallet.acceptExchangeTermsOfService( - args.exchangeBaseUrl, - args.etag, - ); - } - case "acceptWithdrawal": { - const wallet = await this.wp.promise; - return await wallet.acceptWithdrawal( - args.talerWithdrawUri, - args.selectedExchange, - ); - } case "reset": { const oldArgs = this.walletArgs; this.walletArgs = { ...oldArgs }; @@ -312,8 +208,11 @@ class AndroidWalletMessageHandler { this.wp.resolve(w); return {}; } - default: - throw Error(`operation "${operation}" not understood`); + default: { + const wallet = await this.wp.promise; + return await handleCoreApiRequest(wallet, operation, id, args); + } + } } } -- cgit v1.2.3