commit 994fba1681aa22d632d7c80609836657681eedb4
parent 6b51c999beb732e39b0b62a4d92ff3451d0234e8
Author: Florian Dold <dold@taler.net>
Date: Tue, 10 Nov 2026 16:59:30 +0100
wallet web UI: observe peer-credit transaction details directly
Give peer-credit details their own observation route and share transaction
actions with queried details. Retain the last snapshot during failures, offer
update retry, and document the consumer lifecycle. Verify that receive and
detail updates need no transaction or exchange follow-up queries.
Diffstat:
4 files changed, 323 insertions(+), 58 deletions(-)
diff --git a/doc/wallet-observations.md b/doc/wallet-observations.md
@@ -143,3 +143,49 @@ availability when its purse expires.
Invalidation covers peer credits, their withdrawal groups, retries, reserves,
exchange details, contract summaries, currency/scope information and settled
amount inputs. This does not depend on public state-transition notifications.
+
+## Web UI consumer
+
+The receive route owns preparation and its progress/errors. Once push preparation
+returns a transaction ID, it mounts an observed review keyed by that ID. Full
+contract terms stay with preparation for document use. The review waits for its
+first snapshot and never falls back to preparation amounts, summary, expiration,
+or exchange data. Peer-pull review continues using its preparation response.
+Both reviews share confirmation state, error handling, the storage durability
+check, and successful navigation/inbox completion through
+`usePeerPaymentConfirmation`. Each review supplies its own typed API call;
+push confirmation retains progress and cancellation support.
+
+Peer-credit transaction details have a dedicated observation-based route. Other
+transaction types retain their query-based route; both share presentation and
+transaction-action handling. No observation is adapted into a query result.
+
+`usePeerCreditObservation(connection, transactionId)` requires an ID and returns
+`{ state, retry }`. Its explicit subscription states are `loading`, `ready`,
+`disconnected`, `failed`, and `deleted`. A ready state contains a snapshot;
+loading, disconnected, and failed states may retain the last snapshot. Failed
+states also carry an error. Deleted is terminal and contains no snapshot.
+
+```typescript
+const { state, retry } = usePeerCreditObservation(connection, transactionId);
+const canConfirm =
+ state.status === "ready" &&
+ state.snapshot.confirmation.unavailableReasons.length === 0;
+```
+
+These are subscription states; payment state remains `transaction.txState`.
+The receive presentation translates core's blockers in their supplied order,
+with key/terms recovery links and authoritative confirmation-request errors.
+It does not reconstruct eligibility from raw exchange fields. Loading, connection
+loss, failure, and deletion are visible even when no amount is available.
+
+The helper installs the listener before registration and stops on unmount,
+including registration races. Reconnection registers a fresh ID and retains
+any previous snapshot while waiting for a new one; confirmation stays disabled
+until ready. Observation failures offer explicit retry. Changing connection or
+transaction ID discards the previous target's value and rejects late deliveries.
+Extension ports clean up their registrations on disconnect; the PWA uses a
+dedicated worker.
+
+No transaction or exchange query is needed to reconstruct ordinary updates.
+Full documents and diagnostic payloads remain on-demand data.
diff --git a/packages/wallet-webui/src/routes/App.tsx b/packages/wallet-webui/src/routes/App.tsx
@@ -31,7 +31,10 @@ import type {
TransactionPeerPullCredit,
TransactionPeerPushDebit,
} from "@gnu-taler/taler-util";
-import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
+import {
+ WalletApiOperation,
+ parseTransactionIdentifier,
+} from "@gnu-taler/taler-wallet-core";
import { useCallback, useEffect, useMemo, useState } from "preact/hooks";
import { useRef } from "preact/hooks";
import jsQR, * as jsQrTypes from "jsqr";
@@ -4971,17 +4974,154 @@ function TransactionsRoute() {
);
}
+function useTransactionActions(transactionId: TransactionIdStr) {
+ const { connection } = useServices();
+ const [, navigate] = useLocation();
+ const callMutation = useWalletMutation(connection);
+ const durability = useDurability();
+ const [workingAction, setWorkingAction] = useState<TransactionUiAction>();
+ const [error, setError] = useState<ErrorPresentation>();
+ const [message, setMessage] = useState<string>();
+ const runAction = async (action: TransactionUiAction) => {
+ if (
+ (action === "retry" || action === "resume" || action === "refund") &&
+ !(await durability.guardValueOperation())
+ )
+ return;
+ setWorkingAction(action);
+ setError(undefined);
+ setMessage(undefined);
+ try {
+ const operation =
+ action === "retry"
+ ? WalletApiOperation.RetryTransaction
+ : action === "suspend"
+ ? WalletApiOperation.SuspendTransaction
+ : action === "resume"
+ ? WalletApiOperation.ResumeTransaction
+ : action === "abort"
+ ? WalletApiOperation.AbortTransaction
+ : action === "fail"
+ ? WalletApiOperation.FailTransaction
+ : action === "delete"
+ ? WalletApiOperation.DeleteTransaction
+ : WalletApiOperation.StartRefundQuery;
+ const result = await callMutation(operation, { transactionId }, [
+ "balances",
+ "transactions",
+ ]);
+ if (Result.isError(result)) {
+ setError(
+ walletErrorHint(
+ result.detail,
+ /* Translators: wallet-core is the background wallet engine; keep the component name unchanged. */ i18n.str`Wallet-core rejected this transaction action.`,
+ ),
+ );
+ } else if (action === "delete") {
+ navigate("/transactions");
+ } else {
+ setMessage(
+ action === "refund"
+ ? i18n.str`The wallet is collecting the available refund.`
+ : /* Translators: The wallet accepted the requested control action; the financial transaction may still be processing. */ i18n.str`Transaction action accepted.`,
+ );
+ }
+ } catch (cause) {
+ setError(errorFromException(cause, i18n.str`Transaction action failed`));
+ } finally {
+ setWorkingAction(undefined);
+ }
+ };
+ return { workingAction, error, setError, message, setMessage, runAction };
+}
+
function TransactionDetailRoute() {
+ const [, params] = useRoute("/transaction/:transactionId");
+ const transactionId = (params?.transactionId ?? "") as TransactionIdStr;
+ return parseTransactionIdentifier(transactionId)?.tag ===
+ TransactionType.PeerPushCredit ? (
+ <PeerPushCreditDetailRoute
+ key={transactionId}
+ transactionId={transactionId}
+ />
+ ) : (
+ <QueriedTransactionDetailRoute
+ key={transactionId}
+ transactionId={transactionId}
+ />
+ );
+}
+
+function PeerPushCreditDetailRoute({
+ transactionId,
+}: {
+ transactionId: TransactionIdStr;
+}) {
+ const { connection, platform } = useServices();
+ const { language } = useLanguage();
+ const [, navigate] = useLocation();
+ const { state, retry } = usePeerCreditObservation(connection, transactionId);
+ const snapshot = state.status === "deleted" ? undefined : state.snapshot;
+ const actions = useTransactionActions(transactionId);
+ const recovery =
+ exchangeKeyRecoveryFromError(actions.error?.detail) ??
+ exchangeKeyRecoveryFromError(snapshot?.transaction.error);
+ const observationError =
+ state.status === "failed"
+ ? errorFromException(state.error, i18n.str`Transaction updates stopped.`)
+ : state.status === "disconnected"
+ ? localError(i18n.str`Waiting for the wallet connection…`)
+ : state.status === "deleted"
+ ? localError(i18n.str`This peer payment no longer exists.`)
+ : undefined;
+ return (
+ <TransactionDetailScreen
+ transaction={
+ snapshot
+ ? transactionDetailView(snapshot.transaction, language)
+ : undefined
+ }
+ loading={state.status === "loading" && !snapshot}
+ error={actions.error ?? observationError}
+ message={
+ state.status === "loading" && snapshot
+ ? i18n.str`Waiting for current payment information…`
+ : actions.message
+ }
+ onRetryObservation={state.status === "failed" ? retry : undefined}
+ workingAction={actions.workingAction}
+ onBack={() => navigate("/transactions")}
+ onAction={(action) => void actions.runAction(action)}
+ onOpenExternal={(url) => void platform.openExternal(url)}
+ recoveryActionLabel={recovery?.actionLabel}
+ onRecoveryAction={
+ recovery
+ ? () =>
+ navigate(
+ exchangeRecoveryRoute(
+ recovery,
+ `/transaction/${transactionId}`,
+ ),
+ )
+ : undefined
+ }
+ />
+ );
+}
+
+function QueriedTransactionDetailRoute({
+ transactionId,
+}: {
+ transactionId: TransactionIdStr;
+}) {
const { connection, platform } = useServices();
const { language } = useLanguage();
- const [, params] = useRoute("/transaction/:transactionId");
const [, navigate] = useLocation();
const callMutation = useWalletMutation(connection);
const { controller: unclaimRequest } = useWalletProgress(connection, {
visible: false,
});
const durability = useDurability();
- const transactionId = (params?.transactionId ?? "") as TransactionIdStr;
const query = useWalletQuery(
connection,
WalletApiOperation.GetTransactionById,
@@ -5010,9 +5150,8 @@ function TransactionDetailRoute() {
{},
{ enabled: paymentDialog !== undefined },
);
- const [workingAction, setWorkingAction] = useState<TransactionUiAction>();
- const [error, setError] = useState<ErrorPresentation>();
- const [message, setMessage] = useState<string>();
+ const { workingAction, error, setError, message, setMessage, runAction } =
+ useTransactionActions(transactionId);
const [continuingTransfer, setContinuingTransfer] = useState(false);
const [selectedPaymentChoice, setSelectedPaymentChoice] = useState<number>();
const [useDonau, setUseDonau] = useState(false);
@@ -5023,7 +5162,6 @@ function TransactionDetailRoute() {
const handoffTarget = useRef<"other" | "current">("other");
const reclaimingPaymentRef = useRef(false);
useEffect(() => {
- setWorkingAction(undefined);
setError(undefined);
setMessage(undefined);
setContinuingTransfer(false);
@@ -5201,56 +5339,6 @@ function TransactionDetailRoute() {
}
if (reclaimAfterward) await reclaimPayment();
};
- const runAction = async (action: TransactionUiAction) => {
- if (
- (action === "retry" || action === "resume" || action === "refund") &&
- !(await durability.guardValueOperation())
- )
- return;
- setWorkingAction(action);
- setError(undefined);
- setMessage(undefined);
- try {
- const operation =
- action === "retry"
- ? WalletApiOperation.RetryTransaction
- : action === "suspend"
- ? WalletApiOperation.SuspendTransaction
- : action === "resume"
- ? WalletApiOperation.ResumeTransaction
- : action === "abort"
- ? WalletApiOperation.AbortTransaction
- : action === "fail"
- ? WalletApiOperation.FailTransaction
- : action === "delete"
- ? WalletApiOperation.DeleteTransaction
- : WalletApiOperation.StartRefundQuery;
- const result = await callMutation(operation, { transactionId }, [
- "balances",
- "transactions",
- ]);
- if (Result.isError(result)) {
- setError(
- walletErrorHint(
- result.detail,
- /* Translators: wallet-core is the background wallet engine; keep the component name unchanged. */ i18n.str`Wallet-core rejected this transaction action.`,
- ),
- );
- } else if (action === "delete") {
- navigate("/transactions");
- } else {
- setMessage(
- action === "refund"
- ? i18n.str`The wallet is collecting the available refund.`
- : /* Translators: The wallet accepted the requested control action; the financial transaction may still be processing. */ i18n.str`Transaction action accepted.`,
- );
- }
- } catch (cause) {
- setError(errorFromException(cause, i18n.str`Transaction action failed`));
- } finally {
- setWorkingAction(undefined);
- }
- };
if (continuingTransfer && query.data?.type === TransactionType.Withdrawal) {
const current = transactionDetailView(query.data, language);
const outcome = current.pending
diff --git a/packages/wallet-webui/src/screens/TransactionDetailScreen.tsx b/packages/wallet-webui/src/screens/TransactionDetailScreen.tsx
@@ -46,6 +46,7 @@ export function TransactionDetailScreen(props: {
transaction?: TransactionDetailView;
loading: boolean;
error?: ErrorPresentation;
+ onRetryObservation?: () => void;
message?: string;
workingAction?: TransactionUiAction;
onBack: () => void;
@@ -90,7 +91,13 @@ export function TransactionDetailScreen(props: {
</button>
<ErrorCard
error={props.error ?? { message: i18n.str`Transaction not found.` }}
- />
+ >
+ {props.onRetryObservation && (
+ <Button
+ onClick={props.onRetryObservation}
+ >{i18n.str`Retry updates`}</Button>
+ )}
+ </ErrorCard>
</div>
);
const transaction = props.transaction;
@@ -202,6 +209,11 @@ export function TransactionDetailScreen(props: {
)}
{props.error && (
<ErrorCard error={props.error}>
+ {props.onRetryObservation && (
+ <Button
+ onClick={props.onRetryObservation}
+ >{i18n.str`Retry updates`}</Button>
+ )}
{props.onRecoveryAction && (
<div class="mt-4">
<Button onClick={props.onRecoveryAction}>
diff --git a/packages/wallet-webui/test/peer-credit-observation.test.tsx b/packages/wallet-webui/test/peer-credit-observation.test.tsx
@@ -24,6 +24,8 @@ import {
type PeerPushCreditSnapshotNotification,
type WalletNotification,
ObservationType,
+ TransactionType,
+ TransactionMajorState,
Result,
TalerError,
TalerErrorCode,
@@ -259,6 +261,41 @@ async function harness(
};
}
+test("incoming push receive and detail use snapshots without transaction/exchange fetches", async () => {
+ const h = await harness("paste");
+ try {
+ await h.waitFor(() => {
+ const button = h.view.getByRole("button", {
+ name: "Receive money",
+ }) as HTMLButtonElement;
+ assert.equal(button.disabled, false);
+ });
+ await h.act(async () =>
+ h.view.getByRole("button", { name: "Receive money" }).click(),
+ );
+ await h.waitFor(() => assert(h.view.getAllByText("Completed").length > 0));
+ assert.equal(h.counts().prepares, 1);
+ assert.equal(h.counts().confirms, 1);
+ assert.equal(
+ h.calls.includes(WalletApiOperation.GetTransactionById),
+ false,
+ );
+ assert.equal(h.calls.includes(WalletApiOperation.ListExchanges), false);
+ assert.equal(
+ h.calls.filter((op) => op === WalletApiOperation.ObservePeerPushCredit)
+ .length,
+ 2,
+ );
+ assert(h.calls.includes(WalletApiOperation.StopObservation));
+ assert.equal(
+ await h.services.platform.actionInbox.get(h.entry.id),
+ undefined,
+ );
+ } finally {
+ await h.close();
+ }
+});
+
test("preparation values stay hidden until the first snapshot, and deletion never restores them", async () => {
const h = await harness("paste", "snapshot-delayed");
try {
@@ -346,6 +383,88 @@ test("cancelling a prepared receipt aborts the transaction and stops observation
}
});
+test("peer-credit detail retains its value after failure and offers observation retry", async () => {
+ const h = await harness("paste");
+ try {
+ await h.waitFor(() =>
+ assert(h.view.getByRole("button", { name: "Receive money" })),
+ );
+ await h.act(async () =>
+ h.view.getByRole("button", { name: "Receive money" }).click(),
+ );
+ await h.waitFor(() => assert(h.view.getAllByText("Completed").length));
+ await h.act(async () => h.failObserved());
+ await h.waitFor(() =>
+ assert(h.view.getByRole("button", { name: "Retry updates" })),
+ );
+ assert(h.view.getAllByText("Completed").length);
+ await h.act(async () =>
+ h.view.getByRole("button", { name: "Retry updates" }).click(),
+ );
+ await h.waitFor(() =>
+ assert.equal(
+ h.view.queryByRole("button", { name: "Retry updates" }),
+ null,
+ ),
+ );
+ assert.equal(
+ h.calls.filter((op) => op === WalletApiOperation.ObservePeerPushCredit)
+ .length,
+ 3,
+ );
+ } finally {
+ await h.close();
+ }
+});
+
+for (const kind of ["peer", "queried"] as const)
+ test(`${kind} detail uses the shared delete action`, async () => {
+ const h = await harness("paste");
+ try {
+ await h.waitFor(() =>
+ assert(h.view.getByRole("button", { name: "Receive money" })),
+ );
+ if (kind === "peer") {
+ await h.act(async () =>
+ h.view.getByRole("button", { name: "Receive money" }).click(),
+ );
+ } else {
+ const history = await h.services.connection.client.call(
+ WalletApiOperation.GetTransactionsV2,
+ {},
+ );
+ const payment = history.transactions.find(
+ (t) =>
+ t.type === TransactionType.Payment &&
+ t.txState.major === TransactionMajorState.Done,
+ );
+ assert.ok(payment);
+ await h.act(async () => {
+ h.dom.location.hash = `#/transaction/${payment.transactionId}`;
+ });
+ }
+ await h.waitFor(() =>
+ assert(h.view.getByRole("button", { name: "Delete record" })),
+ );
+ await h.act(async () =>
+ h.view.getByRole("button", { name: "Delete record" }).click(),
+ );
+ await h.waitFor(() => assert(h.view.getByRole("dialog")));
+ await h.act(async () =>
+ h.view.getByRole("button", { name: "Confirm", exact: true }).click(),
+ );
+ await h.waitFor(() =>
+ assert(
+ h.dom.location.hash.startsWith("#/transactions"),
+ h.dom.location.hash,
+ ),
+ );
+ assert(h.mutations.includes(WalletApiOperation.DeleteTransaction));
+ } finally {
+ await h.close();
+ }
+ });
+
test("peer-pull review keeps using its preparation response without an observation", async () => {
const h = await harness("paste", "pull");
try {