[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-wallet-webex] branch master updated: more android he
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-wallet-webex] branch master updated: more android helpers |
Date: |
Tue, 20 Aug 2019 23:37:04 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-webex.
The following commit(s) were added to refs/heads/master by this push:
new d76bc2a0 more android helpers
d76bc2a0 is described below
commit d76bc2a03d3f9ccf9c9cf142bcb03c96bb40ddb5
Author: Florian Dold <address@hidden>
AuthorDate: Tue Aug 20 23:36:56 2019 +0200
more android helpers
---
src/android/index.ts | 73 +++++++++++++++++++++++++++++++------------------
src/headless/helpers.ts | 6 +++-
src/wallet.ts | 1 +
src/walletTypes.ts | 1 +
4 files changed, 54 insertions(+), 27 deletions(-)
diff --git a/src/android/index.ts b/src/android/index.ts
index b8958b41..6d072a83 100644
--- a/src/android/index.ts
+++ b/src/android/index.ts
@@ -18,8 +18,9 @@
* Imports.
*/
import { Wallet } from "../wallet";
-import { getDefaultNodeWallet, withdrawTestBalance } from
"../headless/helpers";
+import { getDefaultNodeWallet, withdrawTestBalance, DefaultNodeWalletArgs }
from "../headless/helpers";
import { openPromise } from "../promiseUtils";
+import fs = require("fs");
export function installAndroidWalletListener() {
// @ts-ignore
@@ -31,7 +32,8 @@ export function installAndroidWalletListener() {
throw new Error(errMsg);
}
let maybeWallet: Wallet | undefined;
- const wp = openPromise<Wallet>();
+ let wp = openPromise<Wallet>();
+ let walletArgs: DefaultNodeWalletArgs | undefined;
const onMessage = async (msgStr: any) => {
if (typeof msgStr !== "string") {
console.error("expected string as message");
@@ -48,35 +50,54 @@ export function installAndroidWalletListener() {
const id = msg.id;
let result;
switch (operation) {
- case "init":
- {
- maybeWallet = await getDefaultNodeWallet({
- notifyHandler: async () => {
- sendMessage(JSON.stringify({ type: "notification" }));
- },
- });
- wp.resolve(maybeWallet);
- result = true;
- }
+ case "init": {
+ walletArgs = {
+ notifyHandler: async () => {
+ sendMessage(JSON.stringify({ type: "notification" }));
+ },
+ persistentStoragePath: msg.args.persistentStoragePath,
+ };
+ maybeWallet = await getDefaultNodeWallet(walletArgs);
+ wp.resolve(maybeWallet);
+ result = true;
break;
- case "getBalances":
- {
- const wallet = await wp.promise;
- result = await wallet.getBalances();
- }
+ }
+ case "getBalances": {
+ const wallet = await wp.promise;
+ result = await wallet.getBalances();
break;
- case "withdrawTestkudos":
- {
- const wallet = await wp.promise;
- result = await withdrawTestBalance(wallet);
- }
+ }
+ case "withdrawTestkudos": {
+ const wallet = await wp.promise;
+ result = await withdrawTestBalance(wallet);
+ break;
+ }
+ case "preparePay": {
+ const wallet = await wp.promise;
+ result = await wallet.preparePay(msg.args.url);
+ break;
+ }
+ case "confirmPay": {
+ const wallet = await wp.promise;
+ result = await wallet.confirmPay(msg.args.proposalId, undefined);
break;
- case "downloadProposal":
- {
- const wallet = await wp.promise;
- result = wallet.downloadProposal(msg.args.url);
+ }
+ case "reset": {
+ const wallet = await wp.promise;
+ wallet.stop()
+ wp = openPromise<Wallet>();
+ if (walletArgs && walletArgs.persistentStoragePath) {
+ try {
+ fs.unlinkSync(walletArgs.persistentStoragePath)
+ } catch (e) {
+ console.error("Error while deleting the wallet db:", e);
+ }
+ // Prevent further storage!
+ walletArgs.persistentStoragePath = undefined;
}
+ maybeWallet = undefined;
break;
+ }
default:
console.error(`operation "${operation}" not understood`);
return;
diff --git a/src/headless/helpers.ts b/src/headless/helpers.ts
index 5636b392..7c4fa877 100644
--- a/src/headless/helpers.ts
+++ b/src/headless/helpers.ts
@@ -106,7 +106,7 @@ export class NodeHttpLib implements HttpRequestLibrary {
}
}
-interface DefaultNodeWalletArgs {
+export interface DefaultNodeWalletArgs {
/**
* Location of the wallet database.
*
@@ -155,6 +155,10 @@ export async function getDefaultNodeWallet(
}
myBackend.afterCommitCallback = async () => {
+ // Allow caller to stop persisting the wallet.
+ if (args.persistentStoragePath === undefined) {
+ return;
+ }
const dbContent = myBackend.exportDump();
fs.writeFileSync(storagePath, JSON.stringify(dbContent, undefined, 2), {
encoding: "utf-8" });
};
diff --git a/src/wallet.ts b/src/wallet.ts
index eda7bfea..50f3ee7e 100644
--- a/src/wallet.ts
+++ b/src/wallet.ts
@@ -762,6 +762,7 @@ export class Wallet {
status: "payment-possible",
contractTerms: proposal.contractTerms,
proposalId: proposal.id!,
+ totalFees: checkResult.coinSelection!.totalFees,
};
}
throw Error("not reached");
diff --git a/src/walletTypes.ts b/src/walletTypes.ts
index e6564b91..a74f8113 100644
--- a/src/walletTypes.ts
+++ b/src/walletTypes.ts
@@ -478,4 +478,5 @@ export interface PreparePayResult {
contractTerms?: ContractTerms;
error?: string;
proposalId?: number;
+ totalFees?: AmountJson;
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [taler-wallet-webex] branch master updated: more android helpers,
gnunet <=