commit 71c39f0ab41c83c6f5490c5604e706d007912e6b
parent 5a47c08088f7fe0ab9b334eea877d9c83515332e
Author: Florian Dold <dold@taler.net>
Date: Thu, 26 Nov 2026 04:14:58 +0100
wallet-webui: keep the withdrawal amount and exchange when editing
Going back from withdrawal review reset the form to its defaults.
Restore the draft with the chosen amount and exchange, including the age
restriction when the exchange stays the same.
Diffstat:
3 files changed, 87 insertions(+), 14 deletions(-)
diff --git a/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-withdrawal.ts b/packages/taler-harness/src/integrationtests/test-wallet-web-ui-pwa-withdrawal.ts
@@ -357,7 +357,9 @@ async function runPwaWithdrawalTest(
const input = page.getByLabel("Wallet link");
await input.fill("not a Taler link");
await page.getByRole("button", { name: "Open link" }).click();
- await page.getByText("Enter a valid taler:// or payto:// link.").waitFor();
+ await page
+ .getByText("Enter a valid taler:// or payto:// link.")
+ .waitFor();
await input.fill("taler://withdraw/bank.example/operation");
await input.press("Enter");
await page.getByRole("heading", { name: "Wallet action" }).waitFor();
@@ -442,6 +444,10 @@ async function runPwaWithdrawalTest(
);
}
await page.getByLabel("Edit withdrawal").click();
+ const edited = page.getByLabel("Amount to withdraw in TESTKUDOS");
+ await edited.waitFor();
+ if ((await edited.inputValue()) !== "2")
+ throw Error("editing lost the reviewed withdrawal amount");
await page.getByRole("button", { name: "Cancel" }).click();
});
@@ -507,6 +513,30 @@ async function runPwaWithdrawalTest(
if (await page.getByRole("menu").count()) {
throw Error("payto copy menu stayed open after selection");
}
+ // This browser context is disposable. The following navigation resets the override.
+ await page.evaluate(`Object.defineProperty(navigator, "clipboard", { configurable: true, value: {
+ writeText: () => Promise.reject(new DOMException("Clipboard write denied", "NotAllowedError"))
+ } })`);
+ const reference = page
+ .locator("dt", { hasText: /^Payment reference$/ })
+ .first()
+ .locator("xpath=following-sibling::dd[1]");
+ const referenceText = await reference.locator("span").innerText();
+ await reference
+ .getByRole("button", { name: "Copy", exact: true })
+ .click();
+ const fallback = page.getByRole("textbox", { name: /could not copy/i });
+ await fallback.waitFor();
+ if (
+ (await fallback.inputValue()) !== referenceText ||
+ (await reference
+ .getByRole("button", { name: "Copied", exact: true })
+ .count())
+ ) {
+ throw Error(
+ "clipboard rejection failed to offer the exact mandatory transfer reference",
+ );
+ }
});
await stage.step("continue from transaction details", async (page) => {
diff --git a/packages/wallet-webui/src/routes/App.tsx b/packages/wallet-webui/src/routes/App.tsx
@@ -2874,6 +2874,7 @@ function WithdrawalRoute(
const [prepared, setPrepared] = useState<WithdrawalPreparation | undefined>(
() => loadWithdrawalGateDraft(returnTo),
);
+ const [editDraft, setEditDraft] = useState<WithdrawalPreparation>();
let providers: WithdrawalProviderView[] | undefined;
if (props.exchangeAction) {
providers = [props.exchangeAction.provider];
@@ -3052,6 +3053,7 @@ function WithdrawalRoute(
onConfirm={() => void accept()}
onBack={() => {
clearWithdrawalGateDraft();
+ setEditDraft(prepared);
setPrepared(undefined);
setError(undefined);
}}
@@ -3085,11 +3087,16 @@ function WithdrawalRoute(
}
initialProviderUrl={
props.exchangeAction?.provider.exchangeBaseUrl ??
+ editDraft?.provider.exchangeBaseUrl ??
requestedExchange ??
providers?.find((provider) => provider.currency === requestedCurrency)
?.exchangeBaseUrl
}
- initialAmount={props.exchangeAction?.initialAmount}
+ initialAmount={
+ props.exchangeAction?.initialAmount ??
+ (editDraft &&
+ Amounts.stringifyValue(Amounts.parseOrThrow(editDraft.amount)))
+ }
amountEditable={props.exchangeAction?.initialAmount === undefined}
providerEditable={!directedByExchangeUri}
error={
@@ -3121,7 +3128,9 @@ function WithdrawalRoute(
void prepare(
provider,
amount,
- undefined,
+ editDraft?.provider.exchangeBaseUrl === provider.exchangeBaseUrl
+ ? editDraft.restrictAge
+ : undefined,
provider.ageRestrictionOptions,
)
}
@@ -3543,6 +3552,7 @@ function IntegratedWithdrawalRoute() {
const [prepared, setPrepared] = useState<WithdrawalPreparation | undefined>(
() => loadWithdrawalGateDraft(returnTo),
);
+ const [editDraft, setEditDraft] = useState<WithdrawalPreparation>();
const bankView = useTransactionObservation(connection, transactionId);
const bankSnapshot =
bankView.snapshot?.type === TransactionType.Withdrawal
@@ -3918,6 +3928,7 @@ function IntegratedWithdrawalRoute() {
onConfirm={() => void confirm()}
onBack={() => {
clearWithdrawalGateDraft();
+ setEditDraft(prepared);
setPrepared(undefined);
setError(undefined);
}}
@@ -3940,8 +3951,15 @@ function IntegratedWithdrawalRoute() {
? /* Translators: A cash acceptor is a facility where the user pays physical cash to fund a digital-cash withdrawal into this wallet. */ i18n.str`Prepare the wallet before depositing cash`
: i18n.str`Choose how much digital cash to receive`
}
- initialProviderUrl={setup.initialProviderUrl}
- initialAmount={setup.initialAmount}
+ initialProviderUrl={
+ (info.editableExchange && editDraft?.provider.exchangeBaseUrl) ||
+ setup.initialProviderUrl
+ }
+ initialAmount={
+ info.editableAmount && editDraft
+ ? Amounts.stringifyValue(Amounts.parseOrThrow(editDraft.amount))
+ : setup.initialAmount
+ }
amountEditable={info.editableAmount}
providerEditable={info.editableExchange}
maximumAmount={setup.maximumAmount}
@@ -3959,7 +3977,15 @@ function IntegratedWithdrawalRoute() {
onContinue={(provider, amount, restrictAge) =>
cashAcceptor
? void confirm(provider, restrictAge)
- : void prepare(provider, amount, restrictAge)
+ : void prepare(
+ provider,
+ amount,
+ restrictAge ??
+ (editDraft?.provider.exchangeBaseUrl ===
+ provider.exchangeBaseUrl
+ ? editDraft.restrictAge
+ : undefined),
+ )
}
/>
);
diff --git a/packages/wallet-webui/src/screens/WithdrawalScreen.tsx b/packages/wallet-webui/src/screens/WithdrawalScreen.tsx
@@ -1,3 +1,4 @@
+import { useLanguage } from "../i18n/LanguageProvider.js";
import { useFocusScope } from "@gnu-taler/web-util/browser";
import { useEffect, useMemo, useRef, useState } from "preact/hooks";
import { Button } from "../ui/Button.js";
@@ -8,7 +9,11 @@ import { exchangePickerLabels } from "../ui/exchange-label.js";
import { i18n } from "../i18n/runtime.js";
import { FocusedPage } from "../ui/FocusedPage.js";
import { MoneyAmountInput } from "../ui/MoneyAmountInput.js";
-import { positiveAmountValue } from "../routes/money-flow-model.js";
+import {
+ localizedAmountInput,
+ amountInputHint,
+ positiveAmountValue,
+} from "../routes/money-flow-model.js";
export interface WithdrawalProviderView {
exchangeBaseUrl: string;
@@ -40,10 +45,13 @@ export function WithdrawalScreen(props: {
restrictAge?: number,
) => void;
}) {
+ const { language } = useLanguage();
const [providerUrl, setProviderUrl] = useState(
props.initialProviderUrl ?? "",
);
- const [amount, setAmount] = useState(props.initialAmount ?? "");
+ const [amount, setAmount] = useState(() =>
+ localizedAmountInput(props.initialAmount ?? "", language),
+ );
const [restrictAge, setRestrictAge] = useState<number>();
const amountInput = useRef<HTMLInputElement>(null);
const providers = useMemo(() => props.providers ?? [], [props.providers]);
@@ -58,9 +66,6 @@ export function WithdrawalScreen(props: {
if (!providerUrl && providers[0])
setProviderUrl(providers[0].exchangeBaseUrl);
}, [providerUrl, providers]);
- useEffect(() => {
- if (!amount && props.initialAmount) setAmount(props.initialAmount);
- }, [amount, props.initialAmount]);
// The amount field is only rendered once the exchanges have loaded, which
// is usually after the first render. It sits at the top of the page, so
// focusing it need not scroll; scrolling would also make the story
@@ -70,11 +75,17 @@ export function WithdrawalScreen(props: {
active: amountShown && props.amountEditable !== false,
initialFocus: () => amountInput.current,
});
- const enteredAmount = positiveAmountValue(provider?.currency ?? "", amount);
+ const enteredAmount = positiveAmountValue(
+ provider?.currency ?? "",
+ amount,
+ undefined,
+ language,
+ );
const normalizedAmount = positiveAmountValue(
provider?.currency ?? "",
amount,
props.maximumAmount,
+ language,
);
const validAmount =
props.cashAcceptor === true || normalizedAmount !== undefined;
@@ -160,6 +171,9 @@ export function WithdrawalScreen(props: {
</Card>
) : (
<MoneyAmountInput
+ hint={
+ amount && !enteredAmount ? amountInputHint(language) : undefined
+ }
inputRef={amountInput}
// Translators: %1$s is an ISO-style currency code.
label={i18n.str`Amount to withdraw in ${provider.currency}`}
@@ -181,10 +195,13 @@ export function WithdrawalScreen(props: {
<button
type="button"
key={common}
- onClick={() => setAmount(value)}
+ onClick={() =>
+ setAmount(localizedAmountInput(value, language))
+ }
class="rounded-full border border-outline px-4 py-2 hover:bg-secondaryContainer"
>
- {provider.currency} {value}
+ {provider.currency}{" "}
+ {localizedAmountInput(value, language)}
</button>
);
})}