aboutsummaryrefslogtreecommitdiff
path: root/src/android
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-08-19 14:08:14 +0200
committerFlorian Dold <florian.dold@gmail.com>2019-08-19 14:08:14 +0200
commit10df69131f70c63a94247edf38f40ba5a31ae54e (patch)
tree111bcc00eab8a268c7207b2eda28c8517e0641f6 /src/android
parent54fec752796846389ae187834c19e5720a1c43a8 (diff)
downloadwallet-core-10df69131f70c63a94247edf38f40ba5a31ae54e.tar.xz
adhere better to GNU guidlines
Diffstat (limited to 'src/android')
-rw-r--r--src/android/index.ts26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/android/index.ts b/src/android/index.ts
index 3e7eeb645..abf065a8a 100644
--- a/src/android/index.ts
+++ b/src/android/index.ts
@@ -20,14 +20,12 @@
import { Wallet } from "../wallet";
import { getDefaultNodeWallet } from "../headless/helpers";
-
class AndroidWalletHelper {
- wallet: Wallet | undefined;
- constructor (private sendMessage: (m: any) => void) {
- }
+ walletPromise: Promise<Wallet> | undefined;
+ constructor() {}
async init() {
- this.wallet = await getDefaultNodeWallet();
+ this.walletPromise = getDefaultNodeWallet();
}
}
@@ -35,19 +33,25 @@ export function installAndroidWalletListener() {
// @ts-ignore
const sendMessage: (m: any) => void = global.__akono_sendMessage;
if (typeof sendMessage !== "function") {
- const errMsg = "FATAL: cannot install android wallet listener: akono functions missing";
+ const errMsg =
+ "FATAL: cannot install android wallet listener: akono functions missing";
console.error(errMsg);
throw new Error(errMsg);
}
- const walletHelper = new AndroidWalletHelper(sendMessage);
+ const walletHelper = new AndroidWalletHelper();
const onMessage = (msg: any) => {
const operation = msg.operation;
if (typeof operation !== "string") {
- console.error("message to android wallet helper must contain operation of type string");
+ console.error(
+ "message to android wallet helper must contain operation of type string",
+ );
return;
}
+ const id = msg.id;
+ let result;
switch (operation) {
case "init":
+ result = walletHelper.init();
break;
case "getBalances":
break;
@@ -57,7 +61,11 @@ export function installAndroidWalletListener() {
console.error(`operation "${operation}" not understood`);
return;
}
+
+ const respMsg = { result, id };
+ console.log("sending message back", respMsg);
+ sendMessage(respMsg);
};
// @ts-ignore
globalThis.__akono_onMessage = onMessage;
-} \ No newline at end of file
+}