gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: taler-wallet-embedded: tweak


From: gnunet
Subject: [taler-wallet-core] branch master updated: taler-wallet-embedded: tweak init response, rollup bundling, add test
Date: Sun, 23 Oct 2022 19:06:23 +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 d87f3c242 taler-wallet-embedded: tweak init response, rollup bundling, 
add test
d87f3c242 is described below

commit d87f3c242c59fa347aa13d1c2e398638e09ed42f
Author: Florian Dold <florian@dold.me>
AuthorDate: Sun Oct 23 19:05:46 2022 +0200

    taler-wallet-embedded: tweak init response, rollup bundling, add test
---
 build-system/taler-build-scripts                 |  2 +-
 packages/taler-util/src/notifications.ts         |  2 +
 packages/taler-wallet-core/src/wallet.ts         |  8 ++-
 packages/taler-wallet-embedded/package.json      |  2 +-
 packages/taler-wallet-embedded/rollup.config.js  | 33 ++++++++++++
 packages/taler-wallet-embedded/src/index.ts      |  7 +--
 packages/taler-wallet-embedded/test-embedded.cjs | 68 ++++++++++++++++++++++++
 7 files changed, 113 insertions(+), 9 deletions(-)

diff --git a/build-system/taler-build-scripts b/build-system/taler-build-scripts
index 38c168b11..e3262f44d 160000
--- a/build-system/taler-build-scripts
+++ b/build-system/taler-build-scripts
@@ -1 +1 @@
-Subproject commit 38c168b11eeeab93562ffa74b3e2aff4b596c77a
+Subproject commit e3262f44d5e0947bfef736059e82cd8dbf1f9445
diff --git a/packages/taler-util/src/notifications.ts 
b/packages/taler-util/src/notifications.ts
index 17019237a..c50cc72de 100644
--- a/packages/taler-util/src/notifications.ts
+++ b/packages/taler-util/src/notifications.ts
@@ -145,6 +145,7 @@ export interface WaitingForRetryNotification {
   type: NotificationType.WaitingForRetry;
   numPending: number;
   numGivingLiveness: number;
+  numDue: number;
 }
 
 export interface RefundFinishedNotification {
@@ -222,6 +223,7 @@ export interface ReserveCreatedNotification {
 
 export interface PendingOperationProcessedNotification {
   type: NotificationType.PendingOperationProcessed;
+  id: string;
 }
 
 export interface ProposalRefusedNotification {
diff --git a/packages/taler-wallet-core/src/wallet.ts 
b/packages/taler-wallet-core/src/wallet.ts
index 584129c9c..de7f6f42c 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -84,6 +84,7 @@ import {
   ExchangeTosStatusDetails,
   FeeDescription,
   GetExchangeTosResult,
+  InitResponse,
   j2s,
   KnownBankAccounts,
   KnownBankAccountsInfo,
@@ -415,6 +416,7 @@ async function runTaskLoop(
       ws.notify({
         type: NotificationType.WaitingForRetry,
         numGivingLiveness,
+        numDue,
         numPending: pending.pendingOperations.length,
       });
       // Wait until either the timeout, or we are notified (via the latch)
@@ -434,6 +436,7 @@ async function runTaskLoop(
         });
         ws.notify({
           type: NotificationType.PendingOperationProcessed,
+          id: p.id,
         });
       }
     }
@@ -987,7 +990,10 @@ async function dispatchRequestInternal<Op extends 
WalletApiOperation>(
         await fillDefaults(ws);
       }
       await maybeInitDevMode(ws);
-      return {};
+      const resp: InitResponse = {
+        versionInfo: getVersion(ws),
+      };
+      return resp;
     }
     case WalletApiOperation.WithdrawTestkudos: {
       await withdrawTestBalance(ws, {
diff --git a/packages/taler-wallet-embedded/package.json 
b/packages/taler-wallet-embedded/package.json
index 25cd8f2cc..b57eb10a9 100644
--- a/packages/taler-wallet-embedded/package.json
+++ b/packages/taler-wallet-embedded/package.json
@@ -9,7 +9,7 @@
     "type": "git",
     "url": "git://git.taler.net/wallet-core.git"
   },
-  "main": "dist/taler-wallet-embedded.js",
+  "main": "dist/taler-wallet-embedded.cjs",
   "author": "Florian Dold",
   "license": "GPL-3.0",
   "type": "module",
diff --git a/packages/taler-wallet-embedded/rollup.config.js 
b/packages/taler-wallet-embedded/rollup.config.js
index 821622014..1ebefae9a 100644
--- a/packages/taler-wallet-embedded/rollup.config.js
+++ b/packages/taler-wallet-embedded/rollup.config.js
@@ -4,6 +4,31 @@ import nodeResolve from "@rollup/plugin-node-resolve";
 import json from "@rollup/plugin-json";
 import builtins from "builtin-modules";
 import pkg from "./package.json";
+import walletCorePkg from "../taler-wallet-core/package.json";
+import replace from "@rollup/plugin-replace";
+import fs from "fs";
+import path from "path";
+
+function git_hash() {
+  const rev = fs
+    .readFileSync(path.join(GIT_ROOT, ".git", "HEAD"))
+    .toString()
+    .trim()
+    .split(/.*[: ]/)
+    .slice(-1)[0];
+  if (rev.indexOf("/") === -1) {
+    return rev;
+  } else {
+    return fs.readFileSync(path.join(GIT_ROOT, ".git", rev)).toString().trim();
+  }
+}
+
+const BASE = process.cwd();
+let GIT_ROOT = BASE;
+while (!fs.existsSync(path.join(GIT_ROOT, ".git")) && GIT_ROOT !== "/") {
+  GIT_ROOT = path.join(GIT_ROOT, "../");
+}
+const GIT_HASH = GIT_ROOT === "/" ? undefined : git_hash();
 
 export default {
   input: "lib/index.js",
@@ -18,6 +43,14 @@ export default {
       exportConditions: ["node"],
     }),
 
+    replace({
+      values: {
+        __VERSION__: `"${walletCorePkg.version}"`,
+        __GIT_HASH__: `"${GIT_HASH}"`,
+      },
+      preventAssignment: false,
+    }),
+
     commonjs({
       include: [/node_modules/, /dist/],
       extensions: [".js", ".ts"],
diff --git a/packages/taler-wallet-embedded/src/index.ts 
b/packages/taler-wallet-embedded/src/index.ts
index a4de23151..00716d998 100644
--- a/packages/taler-wallet-embedded/src/index.ts
+++ b/packages/taler-wallet-embedded/src/index.ts
@@ -177,6 +177,7 @@ class NativeWalletMessageHandler {
     let initResponse: any = {};
 
     const reinit = async () => {
+      console.error("in reinit");
       const w = await getDefaultNodeWallet(this.walletArgs);
       this.maybeWallet = w;
       const resp = await w.handleCoreApiRequest(
@@ -203,12 +204,6 @@ class NativeWalletMessageHandler {
         };
         await reinit();
         return wrapResponse({
-          // FIXME: Only for Android compatibility, should be removed
-          // once changed on Android.
-          supported_protocol_versions: {
-            exchange: WALLET_EXCHANGE_PROTOCOL_VERSION,
-            merchant: WALLET_MERCHANT_PROTOCOL_VERSION,
-          },
           ...initResponse,
         });
       }
diff --git a/packages/taler-wallet-embedded/test-embedded.cjs 
b/packages/taler-wallet-embedded/test-embedded.cjs
new file mode 100644
index 000000000..bc5bf9086
--- /dev/null
+++ b/packages/taler-wallet-embedded/test-embedded.cjs
@@ -0,0 +1,68 @@
+/*
+ This file is part of GNU Taler
+ (C) 2022 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+
+// This file demonstrates how to use the single-file embedded wallet.
+
+// Load the embedded wallet
+const embedded = require("./dist/taler-wallet-embedded.cjs");
+
+// Some bookkeeping to correlate requests to responses.
+const requestMap = {};
+let requestCounter = 1;
+
+// Install __native_onMessage in the global namespace.
+// The __native_onMessage handles messages from the host,
+// i.e. it handles wallet-core requests from the host application (UI etc.).
+embedded.installNativeWalletListener();
+
+// The host application must the __native_sendMessage callback
+// to allow wallet-core to respond.
+globalThis.__native_sendMessage = (msgStr) => {
+  const message = JSON.parse(msgStr);
+  if (message.type === "notification") {
+    console.log("got notification:", JSON.stringify(message.payload));
+    return;
+  }
+  if (message.type === "response") {
+    console.log("got response", JSON.parse(msgStr));
+    const msgId = message.id;
+    requestMap[msgId](message);
+    delete requestMap[msgId];
+    return;
+  }
+  throw Error("not reached");
+};
+
+async function makeRequest(operation, payload = {}) {
+  return new Promise((resolve, reject) => {
+    const reqId = `req-${requestCounter++}`;
+    requestMap[reqId] = (x) => resolve(x);
+    __native_onMessage(
+      JSON.stringify({
+        operation,
+        args: payload,
+        id: reqId,
+      }),
+    );
+  });
+}
+
+async function testMain() {
+  const resp = await makeRequest("init");
+  console.log("response from init", JSON.stringify(resp));
+}
+
+testMain();

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]