summaryrefslogtreecommitdiff
path: root/packages/taler-harness/src/harness/harness.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-harness/src/harness/harness.ts')
-rw-r--r--packages/taler-harness/src/harness/harness.ts32
1 files changed, 31 insertions, 1 deletions
diff --git a/packages/taler-harness/src/harness/harness.ts b/packages/taler-harness/src/harness/harness.ts
index 7b2f980cc..1120eae84 100644
--- a/packages/taler-harness/src/harness/harness.ts
+++ b/packages/taler-harness/src/harness/harness.ts
@@ -41,17 +41,21 @@ import {
Logger,
MerchantReserveCreateConfirmation,
MerchantTemplateAddDetails,
+ NotificationType,
parsePaytoUri,
stringToBytes,
TalerError,
TalerProtocolDuration,
+ TransactionMajorState,
WalletNotification,
} from "@gnu-taler/taler-util";
import {
BankApi,
BankServiceHandle,
HarnessExchangeBankAccount,
+ OpenedPromise,
openPromise,
+ WalletApiOperation,
WalletCoreApiClient,
WalletCoreRequestType,
WalletCoreResponseType,
@@ -934,7 +938,12 @@ export class FakebankService
);
await this.pingUntilAvailable();
for (const acc of this.accounts) {
- await BankApi.registerAccount(this, acc.accountName, acc.accountPassword, {});
+ await BankApi.registerAccount(
+ this,
+ acc.accountName,
+ acc.accountPassword,
+ {},
+ );
}
}
@@ -2246,9 +2255,26 @@ export interface WalletClientArgs {
onNotification?(n: WalletNotification): void;
}
+export type CancelFn = () => void;
+export type NotificationHandler = (n: WalletNotification) => void;
+
+/**
+ * Convenience wrapper around a (remote) wallet handle.
+ */
export class WalletClient {
remoteWallet: RemoteWallet | undefined = undefined;
private waiter: WalletNotificationWaiter = makeNotificationWaiter();
+ notificationHandlers: NotificationHandler[] = [];
+
+ addNotificationListener(f: NotificationHandler): CancelFn {
+ this.notificationHandlers.push(f);
+ return () => {
+ const idx = this.notificationHandlers.indexOf(f);
+ if (idx >= 0) {
+ this.notificationHandlers.splice(idx, 1);
+ }
+ };
+ }
async call<Op extends keyof WalletOperations>(
operation: Op,
@@ -2260,6 +2286,7 @@ export class WalletClient {
const client = getClientFromRemoteWallet(this.remoteWallet);
return client.call(operation, payload);
}
+
constructor(private args: WalletClientArgs) {}
async connect(): Promise<void> {
@@ -2272,6 +2299,9 @@ export class WalletClient {
walletClient.args.onNotification(n);
}
waiter.notify(n);
+ for (const h of walletClient.notificationHandlers) {
+ h(n);
+ }
},
});
this.remoteWallet = w;