aboutsummaryrefslogtreecommitdiff
path: root/src/android
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-07-31 22:46:23 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-07-31 22:46:23 +0530
commitb37c98346d407c749a5cd971f798428c42b248c3 (patch)
tree4abbcd3152915ed1c8a4703d7b6892b4d603eb13 /src/android
parent3db00d9d73c7fcd88f8450330c01639a6b171df9 (diff)
use message envelope as documentedv0.7.1-dev.18
Diffstat (limited to 'src/android')
-rw-r--r--src/android/index.ts44
1 files changed, 24 insertions, 20 deletions
diff --git a/src/android/index.ts b/src/android/index.ts
index 9e58fc8a6..389a081b7 100644
--- a/src/android/index.ts
+++ b/src/android/index.ts
@@ -40,7 +40,10 @@ import {
handleCoreApiRequest,
CoreApiResponseSuccess,
CoreApiResponse,
+ CoreApiEnvelope,
} from "../walletCoreApiHandler";
+import { makeErrorDetails } from "../operations/errors";
+import { TalerErrorCode } from "../TalerErrorCode";
// @ts-ignore: special built-in module
//import akono = require("akono");
@@ -132,9 +135,18 @@ export class AndroidHttpLib implements HttpRequestLibrary {
}
}
-function sendAkonoMessage(m: string): void {
+function sendAkonoMessage(ev: CoreApiEnvelope): void {
// @ts-ignore
- globalThis.__akono_sendMessage(m);
+ const sendMessage = globalThis.__akono_sendMessage;
+ if (typeof sendMessage !== "function") {
+ const errMsg =
+ "FATAL: cannot install android wallet listener: akono functions missing";
+ console.error(errMsg);
+ throw new Error(errMsg);
+ }
+ const m = JSON.stringify(ev);
+ // @ts-ignore
+ sendMessage(m);
}
class AndroidWalletMessageHandler {
@@ -154,7 +166,6 @@ class AndroidWalletMessageHandler {
const wrapResponse = (result: unknown): CoreApiResponseSuccess => {
return {
type: "response",
- isError: false,
id,
operation,
result,
@@ -164,9 +175,7 @@ class AndroidWalletMessageHandler {
case "init": {
this.walletArgs = {
notifyHandler: async (notification: WalletNotification) => {
- sendAkonoMessage(
- JSON.stringify({ type: "notification", payload: notification }),
- );
+ sendAkonoMessage({ type: "notification", payload: notification });
},
persistentStoragePath: args.persistentStoragePath,
httpLib: this.httpLib,
@@ -232,14 +241,6 @@ class AndroidWalletMessageHandler {
}
export function installAndroidWalletListener(): void {
- // @ts-ignore
- const sendMessage: (m: string) => void = globalThis.__akono_sendMessage;
- if (typeof sendMessage !== "function") {
- const errMsg =
- "FATAL: cannot install android wallet listener: akono functions missing";
- console.error(errMsg);
- throw new Error(errMsg);
- }
const handler = new AndroidWalletMessageHandler();
const onMessage = async (msgStr: any): Promise<void> => {
if (typeof msgStr !== "string") {
@@ -262,16 +263,19 @@ export function installAndroidWalletListener(): void {
console.log(
`android listener: sending success response for ${operation} (${id})`,
);
- sendMessage(JSON.stringify(respMsg));
+ sendAkonoMessage(respMsg);
} catch (e) {
- const respMsg = {
- type: "response",
+ const respMsg: CoreApiResponse = {
+ type: "error",
id,
operation,
- isError: true,
- result: { message: e.toString() },
+ error: makeErrorDetails(
+ TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION,
+ "unexpected exception",
+ {},
+ ),
};
- sendMessage(JSON.stringify(respMsg));
+ sendAkonoMessage(respMsg);
return;
}
};