taler-wallet-embedded: tweak init response, rollup bundling, add test
This commit is contained in:
parent
1ab63a1840
commit
d87f3c242c
@ -1 +1 @@
|
|||||||
Subproject commit 38c168b11eeeab93562ffa74b3e2aff4b596c77a
|
Subproject commit e3262f44d5e0947bfef736059e82cd8dbf1f9445
|
@ -145,6 +145,7 @@ export interface WaitingForRetryNotification {
|
|||||||
type: NotificationType.WaitingForRetry;
|
type: NotificationType.WaitingForRetry;
|
||||||
numPending: number;
|
numPending: number;
|
||||||
numGivingLiveness: number;
|
numGivingLiveness: number;
|
||||||
|
numDue: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RefundFinishedNotification {
|
export interface RefundFinishedNotification {
|
||||||
@ -222,6 +223,7 @@ export interface ReserveCreatedNotification {
|
|||||||
|
|
||||||
export interface PendingOperationProcessedNotification {
|
export interface PendingOperationProcessedNotification {
|
||||||
type: NotificationType.PendingOperationProcessed;
|
type: NotificationType.PendingOperationProcessed;
|
||||||
|
id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProposalRefusedNotification {
|
export interface ProposalRefusedNotification {
|
||||||
|
@ -84,6 +84,7 @@ import {
|
|||||||
ExchangeTosStatusDetails,
|
ExchangeTosStatusDetails,
|
||||||
FeeDescription,
|
FeeDescription,
|
||||||
GetExchangeTosResult,
|
GetExchangeTosResult,
|
||||||
|
InitResponse,
|
||||||
j2s,
|
j2s,
|
||||||
KnownBankAccounts,
|
KnownBankAccounts,
|
||||||
KnownBankAccountsInfo,
|
KnownBankAccountsInfo,
|
||||||
@ -415,6 +416,7 @@ async function runTaskLoop(
|
|||||||
ws.notify({
|
ws.notify({
|
||||||
type: NotificationType.WaitingForRetry,
|
type: NotificationType.WaitingForRetry,
|
||||||
numGivingLiveness,
|
numGivingLiveness,
|
||||||
|
numDue,
|
||||||
numPending: pending.pendingOperations.length,
|
numPending: pending.pendingOperations.length,
|
||||||
});
|
});
|
||||||
// Wait until either the timeout, or we are notified (via the latch)
|
// Wait until either the timeout, or we are notified (via the latch)
|
||||||
@ -434,6 +436,7 @@ async function runTaskLoop(
|
|||||||
});
|
});
|
||||||
ws.notify({
|
ws.notify({
|
||||||
type: NotificationType.PendingOperationProcessed,
|
type: NotificationType.PendingOperationProcessed,
|
||||||
|
id: p.id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -987,7 +990,10 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
|
|||||||
await fillDefaults(ws);
|
await fillDefaults(ws);
|
||||||
}
|
}
|
||||||
await maybeInitDevMode(ws);
|
await maybeInitDevMode(ws);
|
||||||
return {};
|
const resp: InitResponse = {
|
||||||
|
versionInfo: getVersion(ws),
|
||||||
|
};
|
||||||
|
return resp;
|
||||||
}
|
}
|
||||||
case WalletApiOperation.WithdrawTestkudos: {
|
case WalletApiOperation.WithdrawTestkudos: {
|
||||||
await withdrawTestBalance(ws, {
|
await withdrawTestBalance(ws, {
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git://git.taler.net/wallet-core.git"
|
"url": "git://git.taler.net/wallet-core.git"
|
||||||
},
|
},
|
||||||
"main": "dist/taler-wallet-embedded.js",
|
"main": "dist/taler-wallet-embedded.cjs",
|
||||||
"author": "Florian Dold",
|
"author": "Florian Dold",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
@ -4,6 +4,31 @@ import nodeResolve from "@rollup/plugin-node-resolve";
|
|||||||
import json from "@rollup/plugin-json";
|
import json from "@rollup/plugin-json";
|
||||||
import builtins from "builtin-modules";
|
import builtins from "builtin-modules";
|
||||||
import pkg from "./package.json";
|
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 {
|
export default {
|
||||||
input: "lib/index.js",
|
input: "lib/index.js",
|
||||||
@ -18,6 +43,14 @@ export default {
|
|||||||
exportConditions: ["node"],
|
exportConditions: ["node"],
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
replace({
|
||||||
|
values: {
|
||||||
|
__VERSION__: `"${walletCorePkg.version}"`,
|
||||||
|
__GIT_HASH__: `"${GIT_HASH}"`,
|
||||||
|
},
|
||||||
|
preventAssignment: false,
|
||||||
|
}),
|
||||||
|
|
||||||
commonjs({
|
commonjs({
|
||||||
include: [/node_modules/, /dist/],
|
include: [/node_modules/, /dist/],
|
||||||
extensions: [".js", ".ts"],
|
extensions: [".js", ".ts"],
|
||||||
|
@ -177,6 +177,7 @@ class NativeWalletMessageHandler {
|
|||||||
let initResponse: any = {};
|
let initResponse: any = {};
|
||||||
|
|
||||||
const reinit = async () => {
|
const reinit = async () => {
|
||||||
|
console.error("in reinit");
|
||||||
const w = await getDefaultNodeWallet(this.walletArgs);
|
const w = await getDefaultNodeWallet(this.walletArgs);
|
||||||
this.maybeWallet = w;
|
this.maybeWallet = w;
|
||||||
const resp = await w.handleCoreApiRequest(
|
const resp = await w.handleCoreApiRequest(
|
||||||
@ -203,12 +204,6 @@ class NativeWalletMessageHandler {
|
|||||||
};
|
};
|
||||||
await reinit();
|
await reinit();
|
||||||
return wrapResponse({
|
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,
|
...initResponse,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
68
packages/taler-wallet-embedded/test-embedded.cjs
Normal file
68
packages/taler-wallet-embedded/test-embedded.cjs
Normal file
@ -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();
|
Loading…
Reference in New Issue
Block a user