[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] branch master updated: fix Android response, stronge
From: |
gnunet |
Subject: |
[taler-wallet-core] branch master updated: fix Android response, stronger typing |
Date: |
Wed, 29 Jul 2020 19:23:22 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-core.
The following commit(s) were added to refs/heads/master by this push:
new dfe5e95b fix Android response, stronger typing
dfe5e95b is described below
commit dfe5e95bc8537e13c482fff42cfefeb090eb2e09
Author: Florian Dold <florian.dold@gmail.com>
AuthorDate: Wed Jul 29 22:53:17 2020 +0530
fix Android response, stronger typing
---
src/android/index.ts | 32 +++++++++++++++++++++++---------
src/walletCoreApiHandler.ts | 30 +++++++++++++++++++++++++++---
2 files changed, 50 insertions(+), 12 deletions(-)
diff --git a/src/android/index.ts b/src/android/index.ts
index b9131a6d..82d8309b 100644
--- a/src/android/index.ts
+++ b/src/android/index.ts
@@ -20,7 +20,6 @@
import { Wallet } from "../wallet";
import {
getDefaultNodeWallet,
- withdrawTestBalance,
DefaultNodeWalletArgs,
} from "../headless/helpers";
import { openPromise, OpenedPromise } from "../util/promiseUtils";
@@ -37,8 +36,11 @@ import {
WALLET_EXCHANGE_PROTOCOL_VERSION,
WALLET_MERCHANT_PROTOCOL_VERSION,
} from "../operations/versions";
-import { Amounts } from "../util/amounts";
-import { handleCoreApiRequest } from "../walletCoreApiHandler";
+import {
+ handleCoreApiRequest,
+ CoreApiResponseSuccess,
+ CoreApiResponse,
+} from "../walletCoreApiHandler";
// @ts-ignore: special built-in module
//import akono = require("akono");
@@ -144,7 +146,20 @@ class AndroidWalletMessageHandler {
/**
* Handle a request from the Android wallet.
*/
- async handleMessage(operation: string, id: string, args: any): Promise<any> {
+ async handleMessage(
+ operation: string,
+ id: string,
+ args: any,
+ ): Promise<CoreApiResponse> {
+ const wrapResponse = (result: unknown): CoreApiResponseSuccess => {
+ return {
+ type: "response",
+ isError: false,
+ id,
+ operation,
+ result,
+ };
+ };
switch (operation) {
case "init": {
this.walletArgs = {
@@ -162,15 +177,15 @@ class AndroidWalletMessageHandler {
console.error("Error during wallet retry loop", e);
});
this.wp.resolve(w);
- return {
+ return wrapResponse({
supported_protocol_versions: {
exchange: WALLET_EXCHANGE_PROTOCOL_VERSION,
merchant: WALLET_MERCHANT_PROTOCOL_VERSION,
},
- };
+ });
}
case "getHistory": {
- return [];
+ return wrapResponse({ history: [] });
}
case "startTunnel": {
// this.httpLib.useNfcTunnel = true;
@@ -206,13 +221,12 @@ class AndroidWalletMessageHandler {
console.error("Error during wallet retry loop", e);
});
this.wp.resolve(w);
- return {};
+ return wrapResponse({});
}
default: {
const wallet = await this.wp.promise;
return await handleCoreApiRequest(wallet, operation, id, args);
}
-
}
}
}
diff --git a/src/walletCoreApiHandler.ts b/src/walletCoreApiHandler.ts
index 3c1bf007..02b916af 100644
--- a/src/walletCoreApiHandler.ts
+++ b/src/walletCoreApiHandler.ts
@@ -249,6 +249,28 @@ async function dispatchRequestInternal(
);
}
+export type CoreApiResponse =
+ | CoreApiResponseSuccess
+ | CoreApiResponseError;
+
+export interface CoreApiResponseSuccess {
+ // To distinguish the message from notifications
+ type: "response";
+ isError: false,
+ operation: string,
+ id: string;
+ result: unknown;
+}
+
+export interface CoreApiResponseError {
+ // To distinguish the message from notifications
+ type: "response";
+ isError: true,
+ operation: string,
+ id: string;
+ error: unknown;
+}
+
/**
* Handle a request to the wallet-core API.
*/
@@ -257,16 +279,16 @@ export async function handleCoreApiRequest(
operation: string,
id: string,
payload: unknown,
-): Promise<unknown> {
+): Promise<CoreApiResponse> {
try {
const result = await dispatchRequestInternal(w, operation, payload);
- const respMsg = {
+ return {
isError: false,
operation,
id,
result,
+ type: "response",
};
- return respMsg;
} catch (e) {
if (
e instanceof OperationFailedError ||
@@ -277,6 +299,7 @@ export async function handleCoreApiRequest(
operation,
id,
error: e.operationError,
+ type: "response",
};
} else {
return {
@@ -288,6 +311,7 @@ export async function handleCoreApiRequest(
`unexpected exception: ${e}`,
{},
),
+ type: "response",
};
}
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-wallet-core] branch master updated: fix Android response, stronger typing,
gnunet <=