commit 9e5f58a48ee203a15115f093544ab312d48d65d0
parent ec618c8c9146c76daa571d6dd42e58b60fa5d11f
Author: Florian Dold <dold@taler.net>
Date: Mon, 23 Nov 2026 23:17:21 +0100
wallet: notify clients when Donau settings change
Publish one DonauConfigChanged event per commit so clients can read
the current configuration. The event carries no taxpayer data.
Diffstat:
7 files changed, 70 insertions(+), 15 deletions(-)
diff --git a/packages/taler-util/src/notifications.ts b/packages/taler-util/src/notifications.ts
@@ -40,6 +40,8 @@ import type {
} from "./types-taler-wallet-observations.js";
export enum NotificationType {
+ /** The wallet changed its Donau configuration. Read GetDonau for the current value. */
+ DonauConfigChanged = "donau-config-changed",
UserAttentionChanged = "user-attention-changed",
ObservationSnapshot = "observation-snapshot",
ObservationError = "observation-error",
@@ -488,6 +490,7 @@ export interface CoinRecoveryProgressNotification {
}
export type WalletNotification =
+ | { type: NotificationType.DonauConfigChanged }
| { type: NotificationType.UserAttentionChanged }
| ObservationSnapshotNotification
| ObservationErrorNotification
diff --git a/packages/taler-wallet-core/src/db/shared.ts b/packages/taler-wallet-core/src/db/shared.ts
@@ -53,11 +53,14 @@ export function coalesceWalletNotifications(
): WalletNotification[] {
const result: WalletNotification[] = [];
const balances = new Map<string | undefined, BalanceChangeNotification>();
- let attentionChanged = false;
+ const seen = new Set<NotificationType>();
for (const notification of notifications) {
- if (notification.type === NotificationType.UserAttentionChanged) {
- if (attentionChanged) continue;
- attentionChanged = true;
+ if (
+ notification.type === NotificationType.UserAttentionChanged ||
+ notification.type === NotificationType.DonauConfigChanged
+ ) {
+ if (seen.has(notification.type)) continue;
+ seen.add(notification.type);
}
if (notification.type !== NotificationType.BalanceChange) {
result.push(notification);
diff --git a/packages/taler-wallet-core/src/donau.ts b/packages/taler-wallet-core/src/donau.ts
@@ -352,6 +352,7 @@ export async function handleSetDonau(
donauTaxIdHash: encodeCrock(saltedId),
},
});
+ tx.notify({ type: NotificationType.DonauConfigChanged });
});
return {};
}
diff --git a/packages/taler-wallet-core/src/observe-transaction.test.ts b/packages/taler-wallet-core/src/observe-transaction.test.ts
@@ -60,6 +60,7 @@ import {
} from "./observe-transaction.js";
import { PeerPushCreditTransactionContext } from "./pay-peer-push-credit.js";
import { dispatchRequestInternal } from "./requests.js";
+import { handleSetDonau } from "./donau.js";
import { WalletDbTransaction } from "./db/transaction.js";
import { WithdrawTransactionContext } from "./withdraw.js";
import { RefundTransactionContext } from "./pay-merchant.js";
@@ -1176,17 +1177,10 @@ for (const makeRunner of runnerFactories) {
!JSON.stringify(payment.snapshot).includes('"contractTerms"'),
);
nextPayment = f.nextSnapshot("txn:payment:payment");
- await f.wex.runWalletDbTx((tx) =>
- tx.upsertConfig({
- key: R.ConfigRecordKey.DonauConfig,
- value: {
- donauBaseUrl: "https://donau.example/",
- donauTaxId: "tax-id",
- donauTaxIdHash: master,
- donauSalt: master,
- },
- }),
- );
+ await handleSetDonau(f.wex, {
+ donauBaseUrl: "https://donau.example/",
+ taxPayerId: "tax-id",
+ });
await f.settle();
await nextPayment;
const configured = latestPayment();
diff --git a/packages/taler-wallet-core/src/wallet-notifications.test.ts b/packages/taler-wallet-core/src/wallet-notifications.test.ts
@@ -67,6 +67,8 @@ import {
markAllUserAttentionRead,
updateAttention,
} from "./user-attention.js";
+import type { WalletDbTransaction } from "./db/transaction.js";
+import { handleSetDonau } from "./donau.js";
import { applyDevExperiment } from "./dev-experiments.js";
import { recordConflictingCoinHistory } from "./coin-history.js";
import type {
@@ -981,6 +983,43 @@ for (const makeRunner of runnerFactories) {
}
});
+ test(`${makeRunner.name}: Donau changes commit once and are public without an observation`, async () => {
+ const f = await fixture(makeRunner);
+ const req = { donauBaseUrl: "https://donau.example/", taxPayerId: "first" };
+ const changes = () =>
+ f.notifications.filter(
+ (n) => n.type === NotificationType.DonauConfigChanged,
+ );
+ try {
+ const setInTx = (tx: WalletDbTransaction, taxPayerId: string) =>
+ handleSetDonau(
+ { ...f.wex, runWalletDbTx: (fn) => fn(tx) },
+ { ...req, taxPayerId },
+ );
+ await assert.rejects(
+ f.wex.runWalletDbTx(async (tx) => {
+ await setInTx(tx, "rolled-back");
+ throw Error("rollback");
+ }),
+ /rollback/,
+ );
+ await tick();
+ assert.deepEqual(changes(), []);
+ await f.wex.runWalletDbTx(async (tx) => {
+ await setInTx(tx, "initial");
+ await setInTx(tx, req.taxPayerId);
+ });
+ await tick();
+ await handleSetDonau(f.wex, req);
+ await tick();
+ assert.deepEqual(changes(), [
+ { type: NotificationType.DonauConfigChanged },
+ ]);
+ } finally {
+ await f.close();
+ }
+ });
+
test(`${makeRunner.name}: marking an exchange used after accepting its terms preserves the visible balance`, async () => {
const f = await fixture(makeRunner);
try {
diff --git a/packages/wallet-webui/src/api/notifications.ts b/packages/wallet-webui/src/api/notifications.ts
@@ -13,6 +13,7 @@ export type WalletKeyFamily =
| "contacts"
| "mailbox"
| "tokens"
+ | "donau"
| "diagnostics";
export const familyOperations: Record<WalletKeyFamily, readonly string[]> = {
@@ -46,6 +47,7 @@ export const familyOperations: Record<WalletKeyFamily, readonly string[]> = {
WalletApiOperation.ListDiscounts,
WalletApiOperation.ListSubscriptions,
],
+ donau: [WalletApiOperation.GetDonau],
diagnostics: [WalletApiOperation.GetDiagnostics],
};
@@ -53,6 +55,8 @@ export function notificationFamilies(
notification: WalletNotification,
): readonly WalletKeyFamily[] {
switch (notification.type) {
+ case NotificationType.DonauConfigChanged:
+ return ["donau"];
case NotificationType.UserAttentionChanged:
return ["user-attention"];
case NotificationType.BalanceChange:
diff --git a/packages/wallet-webui/test/notifications.test.ts b/packages/wallet-webui/test/notifications.test.ts
@@ -45,3 +45,14 @@ test("a user attention change refreshes the badge independently of balances", ()
assert(ops.has(WalletApiOperation.GetUserAttentionSummary));
assert(!ops.has(WalletApiOperation.GetBalances));
});
+
+test("a Donau configuration change refreshes GetDonau", () => {
+ assert.deepEqual(
+ [
+ ...operationsForNotification({
+ type: NotificationType.DonauConfigChanged,
+ }),
+ ],
+ [WalletApiOperation.GetDonau],
+ );
+});