taler-typescript-core

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

commit 344de802fe773c4305f1524524ab71adbbd97966
parent 69220e06d04da55bf62f5245a651146df0edb73e
Author: Florian Dold <dold@taler.net>
Date:   Tue, 24 Nov 2026 17:06:34 +0100

wallet web UI: show abort refunds after payment deletion

Recent activity and transaction history hid refunds from aborted
payments even after the payment entry disappeared. Show the refund on
its own once the original payment is gone.

Issue: https://bugs.taler.net/n/10663

Diffstat:
Mpackages/taler-util/src/types-taler-wallet-observations.ts | 3+++
Mpackages/taler-util/src/types-taler-wallet-transactions.ts | 2++
Mpackages/taler-wallet-core/src/observe-transaction.test.ts | 1+
Mpackages/taler-wallet-core/src/pay-merchant.test.ts | 8++++++++
Mpackages/taler-wallet-core/src/pay-merchant.ts | 1+
Mpackages/wallet-webui/src/routes/App.tsx | 5+++--
Mpackages/wallet-webui/src/routes/transaction-model.ts | 11+++++++++++
Mpackages/wallet-webui/test/transaction-observation-routes.test.tsx | 109++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
8 files changed, 124 insertions(+), 16 deletions(-)

diff --git a/packages/taler-util/src/types-taler-wallet-observations.ts b/packages/taler-util/src/types-taler-wallet-observations.ts @@ -206,6 +206,8 @@ export interface ObservedPeerPullDebitTransaction extends ObservedTransactionCom } export interface ObservedRefundTransaction extends ObservedTransactionCommon { + /** True when the original payment record is absent from this wallet. */ + paymentMissing?: boolean; amountUncollected?: AmountString; type: TransactionType.Refund; refundedTransactionId: string; @@ -488,6 +490,7 @@ export function observedTransaction( refundedTransactionId: transaction.refundedTransactionId, paymentInfo: transaction.paymentInfo, isAbortRecovery: transaction.isAbortRecovery, + paymentMissing: transaction.paymentMissing, amountUncollected: transaction.amountUncollected, }; case TransactionType.Refresh: diff --git a/packages/taler-util/src/types-taler-wallet-transactions.ts b/packages/taler-util/src/types-taler-wallet-transactions.ts @@ -925,6 +925,8 @@ export interface RefundPaymentInfo { } export interface TransactionRefund extends TransactionCommon { + /** True when the original payment record is absent from this wallet. */ + paymentMissing?: boolean; /** Face value of items still unconfirmed when collection stopped. */ amountUncollected?: AmountString; /** Recovery already included in the unsuccessful payment's final cost. */ diff --git a/packages/taler-wallet-core/src/observe-transaction.test.ts b/packages/taler-wallet-core/src/observe-transaction.test.ts @@ -1693,6 +1693,7 @@ for (const makeRunner of runnerFactories) { await f.wex.runWalletDbTx((tx) => tx.deleteCoin(coinPub)); const audited = await read(); assert.ok(audited?.type === TransactionType.Refund); + assert.equal(audited.transaction.paymentMissing, true); assert.deepEqual(audited.transaction.scopes, [ { type: ScopeType.Auditor, currency, url: auditorUrl }, ]); diff --git a/packages/taler-wallet-core/src/pay-merchant.test.ts b/packages/taler-wallet-core/src/pay-merchant.test.ts @@ -729,6 +729,13 @@ for (const makeRunner of runnerFactories) { ); await paymentCtx.updateTransactionMeta(tx); }); + const attached = await getTransactionById(wex, { + transactionId: refundCtx.transactionId, + }); + assert.ok( + attached.type === TransactionType.Refund && attached.isAbortRecovery, + ); + assert.equal(attached.paymentMissing, false); await paymentCtx.userDeleteTransaction(); assert.strictEqual( @@ -764,6 +771,7 @@ for (const makeRunner of runnerFactories) { assert.strictEqual(refundDetails.paymentInfo?.summary, "Refund test"); assert.strictEqual(refundDetails.isAbortRecovery, true); + assert.equal(refundDetails.paymentMissing, true); await refundCtx.userDeleteTransaction(); assert.strictEqual( await runner.runReadWriteTx((tx) => tx.getPurchase(proposalId)), diff --git a/packages/taler-wallet-core/src/pay-merchant.ts b/packages/taler-wallet-core/src/pay-merchant.ts @@ -984,6 +984,7 @@ export class RefundTransactionContext implements TransactionContext { ), } : {}), + paymentMissing: !(await tx.getPurchase(refundRecord.proposalId)), refundedTransactionId: constructTransactionIdentifier({ tag: TransactionType.Payment, proposalId: refundRecord.proposalId, diff --git a/packages/wallet-webui/src/routes/App.tsx b/packages/wallet-webui/src/routes/App.tsx @@ -134,6 +134,7 @@ import { transactionDetailView, transactionErrorPresentation, transactionHistoryView, + visibleInTransactionHistory, transactionStateView, type TransactionUiAction, } from "./transaction-model.js"; @@ -861,7 +862,7 @@ function BalanceRoute() { : i18n.str`Estimated history reconstructed from retained completed transactions; deleted activity is unavailable.` } recentTransactions={recent.data?.transactions - .filter((t) => t.type !== TransactionType.Refund || !t.isAbortRecovery) + .filter(visibleInTransactionHistory) .map((transaction) => transactionHistoryView(transaction, language))} pendingTransactions={pending.data?.transactions.map((transaction) => transactionHistoryView(transaction, language), @@ -4566,7 +4567,7 @@ function TransactionsRoute() { { limit: -100, ...(supportedScope ? { scopeInfo: supportedScope } : {}) }, ); const transactions = query.data?.transactions - .filter((t) => t.type !== TransactionType.Refund || !t.isAbortRecovery) + .filter(visibleInTransactionHistory) .map((transaction) => transactionHistoryView(transaction, language)); return ( <TransactionScreen diff --git a/packages/wallet-webui/src/routes/transaction-model.ts b/packages/wallet-webui/src/routes/transaction-model.ts @@ -667,6 +667,17 @@ function actionPresentations(): Record< }; } +/** Attached abort recoveries are already represented by their payment. */ +export function visibleInTransactionHistory( + transaction: ObservedTransaction, +): boolean { + return ( + transaction.type !== TransactionType.Refund || + !transaction.isAbortRecovery || + transaction.paymentMissing === true + ); +} + export function transactionHistoryView( transaction: ObservedTransaction, language?: string, diff --git a/packages/wallet-webui/test/transaction-observation-routes.test.tsx b/packages/wallet-webui/test/transaction-observation-routes.test.tsx @@ -16,8 +16,11 @@ import { TransactionMinorState, TransactionType, observedTransaction, + type GetTransactionsV2Request, type ObserveTransactionRequest, type StopObservationRequest, + type TransactionIdStr, + type TransactionRefund, type TransactionSnapshot, type WalletNotification, } from "@gnu-taler/taler-util"; @@ -37,20 +40,8 @@ register( import.meta.url, ); -async function harness( - kind: - | "payment-done" - | "payment-details" - | "payment-claim" - | "payment-review" - | "payment-review-details" - | "invoice" - | "withdrawal" - | "withdrawal-new" - | "bank-withdrawal", - fulfillmentUrl?: string, -) { - const dom = new Window({ url: "https://wallet.example/" }); +function installRouteDom(path = "") { + const dom = new Window({ url: `https://wallet.example/${path}` }); for (const key of [ "window", "document", @@ -80,6 +71,23 @@ async function harness( writable: true, value: dom[key].bind(dom), }); + return dom; +} + +async function harness( + kind: + | "payment-done" + | "payment-details" + | "payment-claim" + | "payment-review" + | "payment-review-details" + | "invoice" + | "withdrawal" + | "withdrawal-new" + | "bank-withdrawal", + fulfillmentUrl?: string, +) { + const dom = installRouteDom(); const { render, cleanup, act } = await import("@testing-library/preact"); const { SWRConfig } = await import("swr"); const { App } = await import("../src/routes/App.js"); @@ -414,6 +422,79 @@ async function harness( }; } +for (const [route, list] of [ + ["#/", "recent activity"], + ["#/transactions", "transaction history"], +]) { + test(`${list} shows an abort refund when its payment is gone`, async () => { + const dom = installRouteDom(route); + const { cleanup, render } = await import("@testing-library/preact"); + const { SWRConfig } = await import("swr"); + const { App } = await import("../src/routes/App.js"); + const services = createDemoServices(); + const refunds: TransactionRefund[] = [ + { + name: "Attached recovery", + isAbortRecovery: true, + paymentMissing: false, + }, + { + name: "Detached recovery", + isAbortRecovery: true, + paymentMissing: true, + }, + { + name: "Ordinary refund", + isAbortRecovery: false, + paymentMissing: false, + }, + ].map(({ name, isAbortRecovery, paymentMissing }, index) => ({ + type: TransactionType.Refund, + transactionId: `txn:refund:${index}` as TransactionIdStr, + refundedTransactionId: `txn:payment:${index}`, + timestamp: { t_s: 1700000000 }, + txState: { major: TransactionMajorState.Done }, + amountRaw: "CHF:1", + amountEffective: "CHF:1", + scopes: [], + stId: 1, + txActions: [], + paymentInfo: { merchant: { name }, summary: "Refund" }, + isAbortRecovery, + paymentMissing, + })); + const call = services.connection.client.call; + services.connection.client.call = async (operation, request) => { + if (operation === WalletApiOperation.GetTransactionsV2) { + const { filterByState } = request as GetTransactionsV2Request; + return { + transactions: filterByState === "nonfinal" ? [] : refunds, + } as never; + } + return call(operation, request); + }; + try { + const view = render( + <SWRConfig value={{ provider: () => new Map() }}> + <App {...services} /> + </SWRConfig>, + ); + await view.findAllByRole("button", { name: /Ordinary refund/ }); + assert.ok( + view.getAllByRole("button", { name: /Detached recovery/ }).length, + ); + assert.equal( + view.queryByRole("button", { name: /Attached recovery/ }), + null, + ); + } finally { + cleanup(); + services.connection.close(); + await dom.happyDOM.abort(); + } + }); +} + for (const url of ["https://merchant.example/fulfilled", undefined]) { test(`reopened browser checkout uses observed fulfillment without waiting for its contract: ${url}`, async () => { const h = await harness("payment-done", url);