commit ba921fe8445228dff5f244d1d9b33cd4f5251d3d
parent 9e5f58a48ee203a15115f093544ab312d48d65d0
Author: Florian Dold <dold@taler.net>
Date: Mon, 23 Nov 2026 23:17:29 +0100
wallet: notify clients when balance refresh reports may have changed
A recovery or expiry risk can change while the visible balance stays
the same. Publish BalanceRefreshInfoChanged when the wallet advances
the report generation.
Diffstat:
7 files changed, 48 insertions(+), 5 deletions(-)
diff --git a/packages/taler-util/src/notifications.ts b/packages/taler-util/src/notifications.ts
@@ -42,6 +42,8 @@ import type {
export enum NotificationType {
/** The wallet changed its Donau configuration. Read GetDonau for the current value. */
DonauConfigChanged = "donau-config-changed",
+ /** Inputs to GetBalanceRefreshInfo changed. The balance overview can remain equal. */
+ BalanceRefreshInfoChanged = "balance-refresh-info-changed",
UserAttentionChanged = "user-attention-changed",
ObservationSnapshot = "observation-snapshot",
ObservationError = "observation-error",
@@ -491,6 +493,7 @@ export interface CoinRecoveryProgressNotification {
export type WalletNotification =
| { type: NotificationType.DonauConfigChanged }
+ | { type: NotificationType.BalanceRefreshInfoChanged }
| { 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
@@ -57,7 +57,8 @@ export function coalesceWalletNotifications(
for (const notification of notifications) {
if (
notification.type === NotificationType.UserAttentionChanged ||
- notification.type === NotificationType.DonauConfigChanged
+ notification.type === NotificationType.DonauConfigChanged ||
+ notification.type === NotificationType.BalanceRefreshInfoChanged
) {
if (seen.has(notification.type)) continue;
seen.add(notification.type);
@@ -310,6 +311,7 @@ export async function persistRefreshBalanceInvalidation(
key: ConfigRecordKey.RefreshBalanceGeneration,
value: version,
});
+ tx.notify({ type: NotificationType.BalanceRefreshInfoChanged });
}
/** Scheduling metadata is not an input to exchange summaries or renewal costs. */
diff --git a/packages/taler-wallet-core/src/dev-experiments.ts b/packages/taler-wallet-core/src/dev-experiments.ts
@@ -186,9 +186,10 @@ export async function setRefreshScenario(
tx.scheduleOnCommit(() => {
wex.ws.devExperimentState.refreshScenario = scenario;
wex.ws.observations.invalidate();
- if (first && visibleRisk(previous) !== visibleRisk(scenario))
- wex.ws.notify({ type: NotificationType.BalanceChange });
});
+ tx.notify({ type: NotificationType.BalanceRefreshInfoChanged });
+ if (first && visibleRisk(previous) !== visibleRisk(scenario))
+ tx.notify({ type: NotificationType.BalanceChange });
});
}
diff --git a/packages/taler-wallet-core/src/refreshBalance.test.ts b/packages/taler-wallet-core/src/refreshBalance.test.ts
@@ -248,6 +248,19 @@ for (const makeRunner of runnerFactories) {
assert.deepEqual(report?.risks, []);
events.length = 0;
const warningId = "recovered-group";
+ const recovered = new Promise<void>((resolve) => {
+ const remove = ws.addPublicNotificationListener((n) => {
+ if (
+ n.type === NotificationType.ObservationSnapshot &&
+ n.observationType === ObservationType.BalanceRefreshInfo &&
+ n.observationId === "cost" &&
+ n.snapshot?.recoveries.some((r) => r.warningId === warningId)
+ ) {
+ remove();
+ resolve();
+ }
+ });
+ });
await wex.runWalletDbTx((tx) =>
tx.upsertRefreshGroup({
refreshGroupId: warningId,
@@ -280,6 +293,8 @@ for (const makeRunner of runnerFactories) {
),
[warningId],
);
+ await recovered;
+ assert.deepEqual(changes(), []);
await handleDismissWalletWarning(wex, { warningId });
assert.deepEqual(
(await getBalanceRefreshInfo(wex, { scopeInfo }))?.recoveries,
diff --git a/packages/taler-wallet-core/src/wallet-notifications.test.ts b/packages/taler-wallet-core/src/wallet-notifications.test.ts
@@ -1046,7 +1046,10 @@ for (const makeRunner of runnerFactories) {
assert.deepEqual(await getBalances(f.wex), accepted);
assert.deepEqual(
f.notifications.map((n) => n.type),
- [NotificationType.ExchangeStateTransition],
+ [
+ NotificationType.ExchangeStateTransition,
+ NotificationType.BalanceRefreshInfoChanged,
+ ],
);
} finally {
await f.close();
@@ -1243,8 +1246,15 @@ for (const makeRunner of runnerFactories) {
changes: boolean,
) => {
const before = await f.generation();
+ const count = () =>
+ f.notifications.filter(
+ (n) => n.type === NotificationType.BalanceRefreshInfoChanged,
+ ).length;
+ const beforeCount = count();
await f.wex.runWalletDbTx(fn);
+ await tick();
assert.equal((await f.generation()) !== before, changes);
+ assert.equal(count() - beforeCount, changes ? 1 : 0);
};
await mutate((tx) => tx.upsertPurchase(p), false);
p.purchaseStatus = PurchaseStatus.DialogProposed;
diff --git a/packages/wallet-webui/src/api/notifications.ts b/packages/wallet-webui/src/api/notifications.ts
@@ -14,6 +14,7 @@ export type WalletKeyFamily =
| "mailbox"
| "tokens"
| "donau"
+ | "refresh-info"
| "diagnostics";
export const familyOperations: Record<WalletKeyFamily, readonly string[]> = {
@@ -48,6 +49,7 @@ export const familyOperations: Record<WalletKeyFamily, readonly string[]> = {
WalletApiOperation.ListSubscriptions,
],
donau: [WalletApiOperation.GetDonau],
+ "refresh-info": [WalletApiOperation.GetBalanceRefreshInfo],
diagnostics: [WalletApiOperation.GetDiagnostics],
};
@@ -57,6 +59,8 @@ export function notificationFamilies(
switch (notification.type) {
case NotificationType.DonauConfigChanged:
return ["donau"];
+ case NotificationType.BalanceRefreshInfoChanged:
+ return ["refresh-info"];
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
@@ -46,7 +46,7 @@ test("a user attention change refreshes the badge independently of balances", ()
assert(!ops.has(WalletApiOperation.GetBalances));
});
-test("a Donau configuration change refreshes GetDonau", () => {
+test("Donau and refresh report events revalidate their respective queries", () => {
assert.deepEqual(
[
...operationsForNotification({
@@ -55,4 +55,12 @@ test("a Donau configuration change refreshes GetDonau", () => {
],
[WalletApiOperation.GetDonau],
);
+ assert.deepEqual(
+ [
+ ...operationsForNotification({
+ type: NotificationType.BalanceRefreshInfoChanged,
+ }),
+ ],
+ [WalletApiOperation.GetBalanceRefreshInfo],
+ );
});