taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 7f4e2cad0d4201ea2c6d5c7e173457520d8330dd
parent 340231965e15267e551da79503f0ce7b8e173350
Author: Florian Dold <dold@taler.net>
Date:   Mon, 23 Nov 2026 19:50:13 +0100

wallet-core: add experiments to show and clear sample inbox items

Diffstat:
Mdoc/wallet-observations.md | 6++++++
Mpackages/taler-wallet-core/src/dev-experiments.ts | 8+++++++-
Mpackages/taler-wallet-core/src/user-attention.ts | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-wallet-core/src/wallet-notifications.test.ts | 26++++++++++++++++++++++++++
4 files changed, 89 insertions(+), 1 deletion(-)

diff --git a/doc/wallet-observations.md b/doc/wallet-observations.md @@ -190,3 +190,9 @@ exchange terms, pass the displayed ETag as `expectedEtag` to read and dismissible. Read condition-based warnings stay visible until their conditions resolve. Each operation returns `{}` and emits one `user-attention-changed` event when it changes the inbox. + +In developer mode, open `taler://dev-experiment/show-user-attention` to +create four sample items. Three start unread and the sample coin conflict +expires after one minute. Run it again to reset the samples, or open +`taler://dev-experiment/clear-user-attention` to remove them. Both +experiments preserve genuine items and the refresh setting. diff --git a/packages/taler-wallet-core/src/dev-experiments.ts b/packages/taler-wallet-core/src/dev-experiments.ts @@ -89,7 +89,7 @@ import { } from "./requests.js"; import { WalletExecutionContext } from "./wallet.js"; import { WithdrawTransactionContext } from "./withdraw.js"; -import { setRefreshBlocked } from "./user-attention.js"; +import { setRefreshBlocked, setAttentionSamples } from "./user-attention.js"; import { WalletApiOperation } from "./wallet-api-types.js"; const logger = new Logger("dev-experiments.ts"); @@ -221,6 +221,12 @@ export async function applyDevExperiment( ); return; } + case "show-user-attention": + case "clear-user-attention": + return setAttentionSamples( + wex, + parsedUri.devExperimentId === "show-user-attention", + ); case "start-block-refresh": { await setRefreshBlocked(wex, true); return; diff --git a/packages/taler-wallet-core/src/user-attention.ts b/packages/taler-wallet-core/src/user-attention.ts @@ -401,3 +401,53 @@ export async function initializeAttention(tx: WalletDbTransaction) { blocked ? { type: "refresh-blocked-for-debugging" } : undefined, ); } + +export async function setAttentionSamples( + wex: WalletExecutionContext, + show: boolean, +) { + await wex.runWalletDbTx(async (tx) => { + const samples = (await tx.listUserAttention()).filter( + (row) => row.item.isSample, + ); + for (const row of samples) await tx.deleteUserAttention(row.sourceKey); + if (show) { + const exchangeBaseUrl = "https://exchange.example/"; + const details: UserAttentionDetails[] = [ + { + type: "coin-double-spent", + exchangeBaseUrls: [exchangeBaseUrl], + amountSpentElsewhere: "KUDOS:5", + }, + { + type: "exchange-tos-changed", + exchangeBaseUrl, + acceptedEtag: "v1", + currentEtag: "v2", + }, + { + type: "exchange-master-key-changed", + exchangeBaseUrl, + previousMasterPub: "SAMPLE-A", + currentMasterPub: "SAMPLE-B", + }, + { type: "refresh-blocked-for-debugging" }, + ]; + for (const info of details) { + const item = newItem(info); + item.isSample = true; + if (info.type === "coin-double-spent") + item.expiresAt = TalerPreciseTimestamp.fromMilliseconds( + nowMs() + 60000, + ); + if (info.type === "exchange-master-key-changed") + item.readAt = item.createdAt; + await save(tx, "sample:" + info.type, item); + } + } + if (show || samples.length) { + changed(tx); + await scheduleAttentionExpirations(wex, tx); + } + }); +} diff --git a/packages/taler-wallet-core/src/wallet-notifications.test.ts b/packages/taler-wallet-core/src/wallet-notifications.test.ts @@ -66,6 +66,7 @@ import { markAllUserAttentionRead, updateAttention, } from "./user-attention.js"; +import { applyDevExperiment } from "./dev-experiments.js"; import { recordConflictingCoinHistory } from "./coin-history.js"; import type { CoinHistoryResponse, @@ -301,6 +302,31 @@ async function fixture(makeRunner: (typeof runnerFactories)[number]) { } for (const makeRunner of runnerFactories) { + test(`${makeRunner.name}: replacing inbox samples creates new occurrences`, async () => { + const f = await fixture(makeRunner); + try { + const show = () => + applyDevExperiment(f.wex, "taler://dev-experiment/show-user-attention"); + await assert.rejects(show(), /unless devmode is active/); + f.wex.ws.config.testing.devModeActive = true; + await show(); + const previous = (await getUserAttention(f.wex)).items.filter( + (i) => i.isSample, + ); + assert.ok(previous.length > 0); + await show(); + const current = (await getUserAttention(f.wex)).items; + assert.deepEqual( + current.map((i) => i.type).sort(), + previous.map((i) => i.type).sort(), + ); + const oldIds = new Set(previous.map((i) => i.attentionId)); + assert.ok(current.every((i) => !oldIds.has(i.attentionId))); + } finally { + await f.close(); + } + }); + test(`${makeRunner.name}: bulk attention updates skip expired items and emit one change per effective operation`, async () => { const f = await fixture(makeRunner); try {