commit c8c5a21abbd6596687c66dfe65db173bc48d9165
parent 63671c3d90fb234d98ff0830319a2a907f6671ff
Author: Florian Dold <dold@taler.net>
Date: Thu, 26 Nov 2026 04:22:55 +0100
wallet-webui: let the demo wallet take back a handed-off payment
The demo offered to continue a payment in this wallet but could not
reclaim it. Return the original transaction to review and debit the
balance only once, even if confirmation is repeated.
Diffstat:
3 files changed, 85 insertions(+), 7 deletions(-)
diff --git a/packages/taler-harness/src/integrationtests/test-wallet-web-ui-demo.ts b/packages/taler-harness/src/integrationtests/test-wallet-web-ui-demo.ts
@@ -180,6 +180,26 @@ export async function runWalletWebUiDemoTest(t: GlobalTestState) {
await page.getByRole("menuitem", { name: "Sample payment" }).click();
await page.getByRole("heading", { name: "Review payment" }).waitFor();
await page.getByText("Museum admission", { exact: true }).waitFor();
+ await page.evaluate(() => {
+ const browser = globalThis as any;
+ browser.dispatchEvent(
+ new browser.PageTransitionEvent("pagehide", { persisted: true }),
+ );
+ browser.dispatchEvent(
+ new browser.PageTransitionEvent("pageshow", { persisted: true }),
+ );
+ });
+ await page
+ .getByRole("button", { name: "Continue with another wallet" })
+ .click();
+ await page
+ .getByRole("dialog")
+ .getByRole("button", { name: "Continue with another wallet" })
+ .click();
+ await page
+ .getByRole("button", { name: "Continue with this wallet" })
+ .click();
+ await page.getByRole("button", { name: "Pay CHF:5.10" }).waitFor();
await page.goto(`${demoUrl}#/transactions`);
await page.getByRole("heading", { name: "History" }).waitFor();
// The seeded demo data already contains a completed City Museum
diff --git a/packages/wallet-webui/src/testing/demo-wallet.ts b/packages/wallet-webui/src/testing/demo-wallet.ts
@@ -1356,15 +1356,48 @@ export class DemoWalletConnection implements WalletConnection {
this.emitTransaction(transaction, oldMajor);
return { talerPayUri } as never;
}
+ case WalletApiOperation.ReclaimPayment: {
+ const transaction = this.findTransaction(String(request.transactionId));
+ if (
+ transaction.type !== TransactionType.Payment ||
+ transaction.txState.major !== TransactionMajorState.Dialog ||
+ transaction.txState.minor !==
+ TransactionMinorState.WaitingForOtherWallet
+ )
+ throw Error("The demo payment is no longer available to reclaim.");
+ delete transaction.unclaimedPayUri;
+ transaction.txState = {
+ major: TransactionMajorState.Dialog,
+ minor: TransactionMinorState.Proposed,
+ };
+ this.emitTransaction(transaction, TransactionMajorState.Dialog);
+ return {} as never;
+ }
case WalletApiOperation.ConfirmPay: {
const transaction = this.findTransaction(String(request.transactionId));
- const oldMajor = transaction.txState.major;
- transaction.txState = { major: TransactionMajorState.Done };
- transaction.txActions = [TransactionAction.Delete];
- (transaction as never as { posConfirmation?: string }).posConfirmation =
- "DEMO-9X2K";
- this.adjust("CHF", -510, transaction.transactionId);
- this.emitTransaction(transaction, oldMajor);
+ if (transaction.type !== TransactionType.Payment)
+ throw Error("Expected a demo payment");
+ if (transaction.txState.major !== TransactionMajorState.Done) {
+ if (
+ typeof request.expectedAmountEffective === "string" &&
+ Amounts.stringify(request.expectedAmountEffective) !==
+ Amounts.stringify(transaction.amountEffective)
+ )
+ throw TalerError.fromDetail(
+ TalerErrorCode.WALLET_CORE_API_BAD_REQUEST,
+ { parameter: "expectedAmountEffective" },
+ );
+ const oldMajor = transaction.txState.major;
+ transaction.txState = { major: TransactionMajorState.Done };
+ transaction.txActions = [TransactionAction.Delete];
+ transaction.posConfirmation = "DEMO-9X2K";
+ this.adjust(
+ Amounts.currencyOf(transaction.amountEffective),
+ -amountCents(transaction.amountEffective),
+ transaction.transactionId,
+ );
+ this.emitTransaction(transaction, oldMajor);
+ }
return {
type: ConfirmPayResultType.Done,
transactionId: transaction.transactionId,
diff --git a/packages/wallet-webui/test/demo-wallet.test.ts b/packages/wallet-webui/test/demo-wallet.test.ts
@@ -54,15 +54,40 @@ test("demo payment mutates balance and emits production notifications", async ()
);
assert.ok(Result.isOk(prepared));
if (Result.isError(prepared)) return;
+ await connection.client.call(WalletApiOperation.UnclaimPayment, {
+ transactionId: prepared.value.transactionId,
+ });
+ await connection.client.call(WalletApiOperation.ReclaimPayment, {
+ transactionId: prepared.value.transactionId,
+ });
+ const review = await connection.client.call(
+ WalletApiOperation.GetTransactionById,
+ { transactionId: prepared.value.transactionId },
+ );
+ assert.ok(review.type === "payment");
+ assert.equal(review.txState.minor, "proposed");
+ assert.equal(review.unclaimedPayUri, undefined);
+ const changed = await connection.client.callForResult(
+ WalletApiOperation.ConfirmPay,
+ {
+ transactionId: prepared.value.transactionId,
+ expectedAmountEffective: "CHF:5",
+ },
+ );
+ assert.ok(Result.isError(changed));
const confirmed = await connection.client.callForResult(
WalletApiOperation.ConfirmPay,
{
transactionId: prepared.value.transactionId,
choiceIndex: 0,
+ expectedAmountEffective: "CHF:5.10",
noWait: true,
},
);
assert.ok(Result.isOk(confirmed));
+ await connection.client.call(WalletApiOperation.ConfirmPay, {
+ transactionId: prepared.value.transactionId,
+ });
const balances = await connection.client.call(
WalletApiOperation.GetBalances,
{},