taler-typescript-core

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

commit f5979370fd5060e52121242c1a2ab74ad67d3b49
parent 461a0d17a143a88c2f432718fe0bdf21952f6ff6
Author: Florian Dold <dold@taler.net>
Date:   Tue, 10 Nov 2026 16:59:06 +0100

wallet web UI: present peer-credit snapshots and confirmation blockers

Map core confirmation blockers to UI copy and recovery destinations without
recomputing eligibility. Render observed transactions and active AML review
through the shared transaction presentation model.

Diffstat:
Apackages/wallet-webui/src/routes/peer-credit-review-model.ts | 125+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/wallet-webui/src/routes/transaction-model.ts | 46+++++++++++++++++++++++++++++++---------------
Mpackages/wallet-webui/test/observations.test.ts | 44++++++++++++++++++++++++++++++++++++++++++++
Apackages/wallet-webui/test/peer-credit-review-model.test.ts | 123+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 323 insertions(+), 15 deletions(-)

diff --git a/packages/wallet-webui/src/routes/peer-credit-review-model.ts b/packages/wallet-webui/src/routes/peer-credit-review-model.ts @@ -0,0 +1,125 @@ +/* + * This file is part of GNU Taler + * (C) 2026 Taler Systems S.A. + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { TalerErrorCode } from "@gnu-taler/taler-util"; +import type { PeerCreditObservationState } from "../api/observations.js"; +import { i18n } from "../i18n/runtime.js"; +import type { ErrorPresentation } from "../ui/error.js"; +import { exchangeKeyRecoveryFromError } from "./exchange-key-recovery-model.js"; +import { exchangeRouteId } from "./management-model.js"; + +export type PeerCreditConfirmationView = + | { enabled: true } + | { + enabled: false; + reason: string; + recovery?: { label: string; href: string }; + }; + +/** Translate core decisions into presentation; do not recompute eligibility. */ +export function peerCreditConfirmationView( + state: PeerCreditObservationState, + returnTo: string, + actionError?: ErrorPresentation, +): PeerCreditConfirmationView { + switch (state.status) { + case "loading": + return { + enabled: false, + reason: i18n.str`Waiting for current payment information…`, + }; + case "disconnected": + return { + enabled: false, + reason: i18n.str`Waiting for the wallet connection…`, + }; + case "failed": + return { enabled: false, reason: i18n.str`Transaction updates stopped.` }; + case "deleted": + return { + enabled: false, + reason: i18n.str`This peer payment no longer exists.`, + }; + } + const query = `?returnTo=${encodeURIComponent(returnTo)}`; + const exchangeRoute = (url: string, terms = false) => + `/exchange/${exchangeRouteId(url)}${terms ? "/terms" : ""}${query}`; + if (actionError) { + const key = exchangeKeyRecoveryFromError(actionError.detail); + if (key) + return { + enabled: false, + reason: key.message, + recovery: { + label: key.actionLabel, + href: + key.exchangeBaseUrls.length === 1 + ? exchangeRoute(key.exchangeBaseUrls[0]) + : `/exchanges${query}`, + }, + }; + const detail = actionError.detail as + | { code?: unknown; exchangeBaseUrl?: unknown } + | undefined; + if ( + detail?.code === TalerErrorCode.WALLET_EXCHANGE_TOS_NOT_ACCEPTED && + typeof detail.exchangeBaseUrl === "string" + ) + return { + enabled: false, + reason: actionError.message, + recovery: { + label: i18n.str`Review terms`, + href: exchangeRoute(detail.exchangeBaseUrl, true), + }, + }; + // Ordinary request errors remain visible; retrying confirmation is allowed. + } + const url = state.snapshot.transaction.exchangeBaseUrl; + const reason = state.snapshot.confirmation.unavailableReasons[0]; + switch (reason) { + case undefined: + return { enabled: true }; + case "exchange-keys-not-accepted": + return { + enabled: false, + reason: /* Translators: An exchange is a GNU Taler service issuing and redeeming digital cash, not an action that converts one currency into another. */ i18n.str`This exchange changed its signing keys. Verify that change before receiving this payment.`, + recovery: { + label: i18n.str`Verify key change`, + href: exchangeRoute(url), + }, + }; + case "exchange-tos-not-accepted": + return { + enabled: false, + reason: /* Translators: An exchange is a GNU Taler service issuing and redeeming digital cash, not an action that converts one currency into another. */ i18n.str`Review and accept this exchange's terms of service before receiving this payment.`, + recovery: { + label: i18n.str`Review terms`, + href: exchangeRoute(url, true), + }, + }; + case "expired": + return { + enabled: false, + reason: i18n.str`This peer payment has expired.`, + }; + case "not-proposed": + return { + enabled: false, + reason: i18n.str`This peer payment has already been processed.`, + }; + case "kyc-hard-limit": + return { + enabled: false, + reason: i18n.str`This payment exceeds an exchange limit.`, + }; + case "exchange-not-ready": + return { + enabled: false, + reason: i18n.str`Waiting for current payment information…`, + }; + } +} diff --git a/packages/wallet-webui/src/routes/transaction-model.ts b/packages/wallet-webui/src/routes/transaction-model.ts @@ -7,6 +7,7 @@ import { WithdrawalType, assertUnreachable, type Transaction, + type ObservedPeerPushCreditTransaction, } from "@gnu-taler/taler-util"; import { parseTransactionIdentifier } from "@gnu-taler/taler-wallet-core"; import { safeWebUrl } from "./payment-model.js"; @@ -16,6 +17,8 @@ import { depositDestinationView } from "./deposit-model.js"; import { i18n } from "../i18n/runtime.js"; import { walletCoreError, type ErrorPresentation } from "../ui/error.js"; +type PresentedTransaction = Transaction | ObservedPeerPushCreditTransaction; + export type TransactionDirection = "credit" | "debit" | "neutral"; export type TransactionTone = "success" | "warning" | "error" | "neutral"; export type TransactionUiAction = @@ -165,7 +168,7 @@ function host(value: string | undefined): string | undefined { } } -function titleAndSubtitle(transaction: Transaction): { +function titleAndSubtitle(transaction: PresentedTransaction): { title: string; subtitle?: string; } { @@ -253,14 +256,16 @@ function minorLabels(): Partial<Record<TransactionMinorState, string>> { }; } -export function transactionStateView(transaction: Transaction): { +export function transactionStateView(transaction: PresentedTransaction): { label: string; detail: string; tone: TransactionTone; } { - const minor = transaction.txState.minor - ? minorLabels()[transaction.txState.minor] - : undefined; + const minor = transaction.kycAmlReview + ? i18n.str`Waiting for review` + : transaction.txState.minor + ? minorLabels()[transaction.txState.minor] + : undefined; switch (transaction.txState.major) { case TransactionMajorState.Done: return { @@ -356,7 +361,7 @@ export function transactionStateView(transaction: Transaction): { } function timestampView( - transaction: Transaction, + transaction: PresentedTransaction, language?: string, ): { timestamp: string; @@ -376,7 +381,7 @@ function timestampView( /** Preserve the structured reason for any wallet-core transaction failure. */ export function transactionErrorPresentation( - transaction: Transaction, + transaction: PresentedTransaction, fallback?: string, ): ErrorPresentation | undefined { const detail = @@ -388,7 +393,9 @@ export function transactionErrorPresentation( ); } -function fieldsFor(transaction: Transaction): TransactionDetailField[] { +function fieldsFor( + transaction: PresentedTransaction, +): TransactionDetailField[] { const fields: TransactionDetailField[] = []; switch (transaction.type) { case TransactionType.Payment: @@ -653,7 +660,7 @@ function actionPresentations(): Record< } export function transactionHistoryView( - transaction: Transaction, + transaction: PresentedTransaction, language?: string, ): TransactionHistoryView { const presentation = typePresentations()[transaction.type]; @@ -694,7 +701,7 @@ export function transactionHistoryView( } export function transactionDetailView( - transaction: Transaction, + transaction: PresentedTransaction, language?: string, ): TransactionDetailView { const base = transactionHistoryView(transaction, language); @@ -736,9 +743,15 @@ export function transactionDetailView( let externalAction: TransactionDetailView["externalAction"]; if (base.pending && safeWebUrl(transaction.kycUrl)) externalAction = { - heading: i18n.str`Identity verification required`, - description: /* Translators: An exchange is a GNU Taler service issuing and redeeming digital cash, not an action that converts one currency into another. */ i18n.str`Complete the required identity verification on the exchange's website.`, - label: i18n.str`Complete verification`, + heading: transaction.kycAmlReview + ? i18n.str`Waiting for review` + : i18n.str`Identity verification required`, + description: transaction.kycAmlReview + ? i18n.str`The exchange is reviewing your account. Please wait.` + : /* Translators: An exchange is a GNU Taler service issuing and redeeming digital cash, not an action that converts one currency into another. */ i18n.str`Complete the required identity verification on the exchange's website.`, + label: transaction.kycAmlReview + ? i18n.str`View verification details` + : i18n.str`Complete verification`, url: transaction.kycUrl, }; if ( @@ -800,7 +813,7 @@ export function transactionDetailView( ) : undefined; const technicalFields: TransactionDetailField[] = []; - if (transaction.kycPaytoHash) { + if ("kycPaytoHash" in transaction && transaction.kycPaytoHash) { technicalFields.push({ // Translators: KYC is "Know Your Customer"; payto is the name of a URI scheme. label: i18n.str`KYC payto hash`, @@ -867,7 +880,10 @@ export function transactionDetailView( ...(transaction.localTransactionId ? { localId: transaction.localTransactionId } : {}), - statusDetail: state.detail, + statusDetail: + base.pending && transaction.kycAmlReview + ? i18n.str`Waiting for review` + : state.detail, fields: [ ...fieldsFor(transaction), ...(transaction.amountEffectiveFinal !== undefined diff --git a/packages/wallet-webui/test/observations.test.ts b/packages/wallet-webui/test/observations.test.ts @@ -25,6 +25,11 @@ import type { WalletConnection, } from "../src/api/contracts.js"; import { ObservationOwner } from "../src/platform/observation-owner.js"; +import { + DemoWalletConnection, + demoActionUris, +} from "../src/testing/demo-wallet.js"; +import { transactionDetailView } from "../src/routes/transaction-model.js"; const transactionId = "txn:peer-push-credit:test" as TransactionIdStr; const snapshot: PeerPushCreditSnapshot = { @@ -241,3 +246,42 @@ test("extension disconnect cleans up registration that completes after disconnec 1, ); }); + +test("receive preparation, observed detail and completion need no follow-up queries", async () => { + const connection = new DemoWalletConnection(); + const calls: string[] = []; + const call = connection.client.call.bind(connection.client); + connection.client.call = ((op, request) => { + calls.push(op); + return call(op, request); + }) as typeof call; + const prepared = await connection.client.call( + WalletApiOperation.PreparePeerPushCredit, + { talerUri: demoActionUris["peer-receive"] }, + ); + const observer = new PeerCreditObservation( + connection, + prepared.transactionId, + () => {}, + () => "receive", + ); + assert.deepEqual( + currentSnapshot(observer)?.confirmation.unavailableReasons, + [], + ); + await connection.client.call(WalletApiOperation.ConfirmPeerPushCredit, { + transactionId: prepared.transactionId, + }); + const view = transactionDetailView(currentSnapshot(observer)!.transaction); + assert.equal(view.state, "Completed"); + assert.equal(calls.includes(WalletApiOperation.GetTransactionById), false); + assert.equal(calls.includes(WalletApiOperation.ListExchanges), false); + observer.dispose(); + connection.close(); +}); + +test("AML review uses waiting copy and a details link, not an instruction to complete KYC", () => { + const view = transactionDetailView(snapshot.transaction); + assert.equal(view.statusDetail, "Waiting for review"); + assert.equal(view.externalAction?.label, "View verification details"); +}); diff --git a/packages/wallet-webui/test/peer-credit-review-model.test.ts b/packages/wallet-webui/test/peer-credit-review-model.test.ts @@ -0,0 +1,123 @@ +/* + * This file is part of GNU Taler + * (C) 2026 Taler Systems S.A. + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import assert from "node:assert/strict"; +import test from "node:test"; +import { + TransactionMajorState, + TransactionType, + TalerErrorCode, + type PeerPushCreditSnapshot, + type TransactionIdStr, +} from "@gnu-taler/taler-util"; +import { peerCreditConfirmationView } from "../src/routes/peer-credit-review-model.js"; +import type { PeerCreditObservationState } from "../src/api/observations.js"; + +const snapshot: PeerPushCreditSnapshot = { + transaction: { + type: TransactionType.PeerPushCredit, + transactionId: "txn:peer-push-credit:test" as TransactionIdStr, + timestamp: { t_s: 1 }, + scopes: [], + txState: { major: TransactionMajorState.Dialog }, + txActions: [], + amountRaw: "CHF:5", + amountEffective: "CHF:4.8", + info: { summary: "Lunch", expiration: undefined, iconId: undefined }, + exchangeBaseUrl: "https://exchange.example/", + }, + exchange: null, + confirmation: { unavailableReasons: [] }, +}; +const returnTo = "/peer-receive/inbox"; +test("only a ready snapshot can enable confirmation", () => { + for (const state of [ + { status: "loading" }, + { status: "loading", snapshot }, + { status: "disconnected" }, + { status: "disconnected", snapshot }, + { status: "failed", error: Error("failed"), snapshot }, + { status: "deleted" }, + ] satisfies PeerCreditObservationState[]) + assert.equal(peerCreditConfirmationView(state, returnTo).enabled, false); + assert.deepEqual( + peerCreditConfirmationView({ status: "ready", snapshot }, returnTo), + { enabled: true }, + ); +}); +test("core blockers retain their order and supply recovery destinations", () => { + for (const reason of [ + "expired", + "not-proposed", + "kyc-hard-limit", + "exchange-not-ready", + "exchange-keys-not-accepted", + "exchange-tos-not-accepted", + ] as const) { + const view = peerCreditConfirmationView( + { + status: "ready", + snapshot: { + ...snapshot, + confirmation: { unavailableReasons: [reason] }, + }, + }, + returnTo, + ); + assert.equal(view.enabled, false); + if (view.enabled) throw Error("unexpected enabled"); + assert.ok(view.reason); + if ( + reason === "exchange-keys-not-accepted" || + reason === "exchange-tos-not-accepted" + ) { + assert.ok(view.recovery); + assert.ok(view.recovery.href.includes(encodeURIComponent(returnTo))); + assert.equal( + view.recovery.href.includes("/terms?"), + reason === "exchange-tos-not-accepted", + ); + } else assert.equal(view.recovery, undefined); + } + const view = peerCreditConfirmationView( + { + status: "ready", + snapshot: { + ...snapshot, + confirmation: { + unavailableReasons: ["expired", "exchange-tos-not-accepted"], + }, + }, + }, + returnTo, + ); + assert.deepEqual(view, { + enabled: false, + reason: "This peer payment has expired.", + }); +}); +test("confirmation RPC failures preserve their recovery information", () => { + for (const code of [ + TalerErrorCode.WALLET_EXCHANGE_TOS_NOT_ACCEPTED, + TalerErrorCode.WALLET_EXCHANGE_KEYS_NOT_ACCEPTED, + ]) { + const view = peerCreditConfirmationView( + { status: "ready", snapshot }, + returnTo, + { + message: "Rejected", + detail: { code, exchangeBaseUrl: "https://different.example/" }, + }, + ); + assert.equal(view.enabled, false); + if (view.enabled) throw Error("unexpected enabled"); + assert.ok( + view.recovery?.href.includes( + encodeURIComponent("https://different.example/"), + ), + ); + } +});