commit b629c49ae46a5d6dd94b235dd29bda048fcd60ab
parent aa4145c75d51a40f8da078cd51e5b5ad01e49371
Author: Florian Dold <dold@taler.net>
Date: Wed, 25 Nov 2026 18:50:24 +0100
wallet web UI: edit saved bank accounts in the guided form
Use the raw payto editor when the guided fields would lose transfer
details. Keep the optional wallet nickname separate from the display
name so accounts learned from withdrawals can stay unnamed.
Issue: https://bugs.taler.net/n/12087
Issue: https://bugs.taler.net/n/12110
Diffstat:
7 files changed, 370 insertions(+), 112 deletions(-)
diff --git a/packages/taler-wallet-core/src/requests.ts b/packages/taler-wallet-core/src/requests.ts
@@ -1320,7 +1320,7 @@ async function handleAddBankAccount(
await tx.upsertBankAccount({
bankAccountId: myId,
paytoUri: req.paytoUri,
- label: req.label,
+ label: req.label || undefined,
currencies,
kycCompleted: false,
});
diff --git a/packages/wallet-webui/src/routes/ManagementRoutes.tsx b/packages/wallet-webui/src/routes/ManagementRoutes.tsx
@@ -32,6 +32,7 @@ import {
exchangeUpdateInProgress,
exchangeUrlFromRoute,
prioritizeExchangeTermsLanguages,
+ sameBankAccountPayto,
} from "./management-model.js";
import { useServices } from "./context.js";
import { i18n } from "../i18n/runtime.js";
@@ -579,7 +580,7 @@ export function BankAccountsRoute() {
const [error, setError] = useState<ErrorPresentation>();
const accounts = query.data?.accounts.map((account) => ({
id: account.bankAccountId,
- label: account.label ?? account.paytoUri,
+ label: account.label,
paytoUri: account.paytoUri,
currencies: account.currencies ?? [],
destination: depositDestinationView(account.paytoUri, account.label),
@@ -595,13 +596,18 @@ export function BankAccountsRoute() {
const preferredEntryType = wireTypes.data?.wireTypeDetails.find(
(entry) => entry.paymentTargetType === "iban",
)?.preferredEntryType;
- if (preferredEntryType === "bban" && !currencies?.[0])
+ if (!editing && preferredEntryType === "bban" && !currencies?.[0])
throw Error(
i18n.str`Enter the account currency so the bank account number can be converted to an IBAN.`,
);
const converted = await connection.client.callForResult(
WalletApiOperation.ConvertIbanAccountFieldToPayto,
- { value: values.accountField, currency: currencies?.[0] ?? "" },
+ // Saved accounts display their IBAN, even for exchanges that
+ // prefer entering new accounts as domestic bank numbers.
+ {
+ value: values.accountField,
+ currency: editing ? "" : (currencies?.[0] ?? ""),
+ },
);
if (Result.isError(converted) || !converted.value.ok)
throw Error(i18n.str`Enter a valid IBAN or bank account number.`);
@@ -620,13 +626,15 @@ export function BankAccountsRoute() {
if (Result.isError(validation) || !validation.value.valid)
throw Error(i18n.str`Enter a valid IBAN or bank account number.`);
paytoUri = bankAccountPayto(values, converted.value.paytoUri);
- } else if (values.method === "x-taler-bank") {
- paytoUri = bankAccountPayto(values);
- } else if (values.method === "bitcoin") {
- paytoUri = bankAccountPayto(values);
} else {
paytoUri = bankAccountPayto(values);
}
+ if (
+ editing &&
+ values.method !== "advanced" &&
+ sameBankAccountPayto(paytoUri, editing.paytoUri)
+ )
+ paytoUri = editing.paytoUri;
paytoUri = validatedPaytoUri(paytoUri);
const result = await callMutation(
WalletApiOperation.AddBankAccount,
diff --git a/packages/wallet-webui/src/routes/management-model.ts b/packages/wallet-webui/src/routes/management-model.ts
@@ -3,10 +3,12 @@ import {
ExchangeUpdateStatus,
Paytos,
PaytoType,
+ Result,
addPaytoQueryParams,
formatAcceptHeader,
type DeleteExchangeRequest,
type ExchangeListItem,
+ type WireTypeDetails,
} from "@gnu-taler/taler-util";
import type { ExchangeView } from "../screens/ExchangesScreen.js";
import { AUTOMATIC_LANGUAGE, i18n } from "../i18n/runtime.js";
@@ -95,10 +97,7 @@ export function prioritizeExchangeTermsLanguages(
return languages.map(({ language }) => language);
}
-export type BankAccountSaveValues = {
- label: string;
- currencies: string;
-} & (
+type BankAccountFields =
| {
method: "iban";
accountField: string;
@@ -113,8 +112,74 @@ export type BankAccountSaveValues = {
receiverName: string;
}
| { method: "bitcoin"; address: string }
- | { method: "advanced"; paytoUri: string }
-);
+ | { method: "advanced"; paytoUri: string };
+
+export type BankAccountSaveValues = BankAccountFields & {
+ label: string;
+ currencies: string;
+};
+
+export function editableBankAccountFields(
+ paytoUri: string,
+ wireTypes: readonly WireTypeDetails[],
+): BankAccountFields {
+ const raw = { method: "advanced", paytoUri } as const;
+ const payto = Result.orUndefined(Paytos.fromString(paytoUri));
+ const wire = wireTypes.find((w) => w.paymentTargetType === payto?.targetType);
+ if (!payto || !wire) return raw;
+ const receiverName = Paytos.getAccountHolder(payto)?.trim();
+ let fields: BankAccountFields;
+ let ibanPayto: string | undefined;
+ switch (payto.targetType) {
+ case PaytoType.IBAN:
+ if (!receiverName) return raw;
+ fields = {
+ method: "iban",
+ accountField: payto.iban,
+ receiverName,
+ receiverTown: Paytos.getReceiverTown(payto)?.trim() ?? "",
+ receiverPostalCode: Paytos.getReceiverPostalCode(payto)?.trim() ?? "",
+ };
+ ibanPayto = `payto://iban/${payto.iban}`;
+ break;
+ case PaytoType.TalerBank:
+ if (
+ !receiverName ||
+ (wire.talerBankHostnames?.length &&
+ !wire.talerBankHostnames.includes(payto.host))
+ )
+ return raw;
+ fields = {
+ method: "x-taler-bank",
+ host: payto.host,
+ account: payto.account,
+ receiverName,
+ };
+ break;
+ case PaytoType.Bitcoin:
+ fields = { method: "bitcoin", address: payto.address };
+ break;
+ default:
+ return raw;
+ }
+ // A saved URI can carry details the form does not expose, such as a BIC,
+ // a Bitcoin reserve key, or additional transfer parameters.
+ return sameBankAccountPayto(paytoUri, bankAccountPayto(fields, ibanPayto))
+ ? fields
+ : raw;
+}
+
+/** Compare the complete paths and all query values, including duplicate keys. */
+export function sameBankAccountPayto(left: string, right: string): boolean {
+ function comparable(uri: string): string {
+ const start = uri.indexOf("?");
+ if (start === -1) return uri;
+ const params = new URLSearchParams(uri.slice(start + 1));
+ params.sort();
+ return `${uri.slice(0, start)}?${params}`;
+ }
+ return comparable(left) === comparable(right);
+}
export function exchangeEntryStatusLabel(status: string): string {
switch (status) {
@@ -209,7 +274,7 @@ export function currenciesFromInput(value: string): string[] | undefined {
}
export function bankAccountPayto(
- values: BankAccountSaveValues,
+ values: BankAccountFields,
convertedIbanPayto?: string,
): string {
switch (values.method) {
diff --git a/packages/wallet-webui/src/screens/BankAccountsScreen.tsx b/packages/wallet-webui/src/screens/BankAccountsScreen.tsx
@@ -1,5 +1,6 @@
+import type { WireTypeDetails } from "@gnu-taler/taler-util";
import { useFocusScope } from "@gnu-taler/web-util/browser";
-import { useEffect, useMemo, useRef, useState } from "preact/hooks";
+import { useLayoutEffect, useMemo, useRef, useState } from "preact/hooks";
import { Button } from "../ui/Button.js";
import { Card } from "../ui/Card.js";
import { ErrorCard } from "../ui/ErrorCard.js";
@@ -7,23 +8,20 @@ import type { ErrorPresentation } from "../ui/error.js";
import { ConfirmationDialog } from "../ui/ConfirmationDialog.js";
import { OverflowMenu } from "../ui/OverflowMenu.js";
import { i18n } from "../i18n/runtime.js";
-import type { BankAccountSaveValues } from "../routes/management-model.js";
+import {
+ editableBankAccountFields,
+ type BankAccountSaveValues,
+} from "../routes/management-model.js";
import type { DepositDestinationView } from "./DepositScreen.js";
export interface BankAccountView {
id: string;
- label: string;
+ label?: string;
paytoUri: string;
currencies: string[];
destination: DepositDestinationView;
}
-export interface BankAccountWireTypeView {
- paymentTargetType: string;
- preferredEntryType?: "iban" | "bban";
- talerBankHostnames?: string[];
-}
-
type GuidedMethod = BankAccountSaveValues["method"];
function methodLabel(method: GuidedMethod): string {
@@ -50,7 +48,7 @@ function supportedMethod(
export function BankAccountsScreen(props: {
accounts?: BankAccountView[];
- wireTypes?: BankAccountWireTypeView[];
+ wireTypes?: WireTypeDetails[];
loading: boolean;
working: boolean;
error?: ErrorPresentation;
@@ -73,56 +71,64 @@ export function BankAccountsScreen(props: {
),
[props.wireTypes],
);
- const [method, setMethod] = useState<GuidedMethod>(
- props.editing ? "advanced" : (guidedMethods[0] ?? "advanced"),
- );
- const [label, setLabel] = useState(props.editing?.label ?? "");
- const [currencies, setCurrencies] = useState(
- props.editing?.currencies.join(", ") ?? "",
- );
- const [paytoUri, setPaytoUri] = useState(props.editing?.paytoUri ?? "");
- const [receiverName, setReceiverName] = useState("");
- const [receiverTown, setReceiverTown] = useState("");
- const [receiverPostalCode, setReceiverPostalCode] = useState("");
- const [accountField, setAccountField] = useState("");
- const [bankHost, setBankHost] = useState("");
- const [bankAccount, setBankAccount] = useState("");
- const [bitcoinAddress, setBitcoinAddress] = useState("");
+ const initial = useMemo(() => {
+ const account = props.editing;
+ const fields =
+ account &&
+ editableBankAccountFields(account.paytoUri, props.wireTypes ?? []);
+ const iban = fields?.method === "iban" ? fields : undefined;
+ const bank = fields?.method === "x-taler-bank" ? fields : undefined;
+ return {
+ method: fields?.method ?? guidedMethods[0] ?? "advanced",
+ label: account?.label ?? "",
+ currencies: account?.currencies.join(", ") ?? "",
+ paytoUri: account?.paytoUri ?? "",
+ receiverName: iban?.receiverName ?? bank?.receiverName ?? "",
+ receiverTown: iban?.receiverTown ?? "",
+ receiverPostalCode: iban?.receiverPostalCode ?? "",
+ accountField: iban?.accountField ?? "",
+ bankHost:
+ bank?.host ??
+ props.wireTypes?.find(
+ (entry) => entry.paymentTargetType === "x-taler-bank",
+ )?.talerBankHostnames?.[0] ??
+ "",
+ bankAccount: bank?.account ?? "",
+ bitcoinAddress: fields?.method === "bitcoin" ? fields.address : "",
+ };
+ }, [props.editing, props.wireTypes, guidedMethods]);
+ const [draft, setDraft] = useState<Partial<typeof initial>>();
+ function update(changes: Partial<typeof initial>) {
+ setDraft((previous) => ({ ...previous, ...changes }));
+ }
+ const {
+ method,
+ label,
+ currencies,
+ paytoUri,
+ receiverName,
+ receiverTown,
+ receiverPostalCode,
+ accountField,
+ bankHost,
+ bankAccount,
+ bitcoinAddress,
+ } = { ...initial, ...draft };
const [formOpen, setFormOpen] = useState(Boolean(props.editing));
const [forgetAccount, setForgetAccount] = useState<BankAccountView>();
const [copiedAccount, setCopiedAccount] = useState<{
id: string;
paytoUri: string;
}>();
- const mounted = useRef(false);
- const selectedInitialMethod = useRef(Boolean(props.editing));
- useEffect(() => {
- if (!props.editing && !selectedInitialMethod.current && guidedMethods[0]) {
- selectedInitialMethod.current = true;
- setMethod(guidedMethods[0]);
- }
- }, [guidedMethods, props.editing]);
- useEffect(() => {
- if (props.editing) setFormOpen(true);
- }, [props.editing]);
- useEffect(() => {
- if (!mounted.current) {
- mounted.current = true;
- return;
- }
- setLabel(props.editing?.label ?? "");
- setCurrencies(props.editing?.currencies.join(", ") ?? "");
- setPaytoUri(props.editing?.paytoUri ?? "");
- setMethod(props.editing ? "advanced" : (guidedMethods[0] ?? "advanced"));
- }, [guidedMethods, props.editing]);
- // Opening the form or starting an edit moves focus to its first text field,
- // which also brings the form into view below the account list. An edit
- // shows the payto URI field only once the reset above has switched to it.
+ const editingId = props.editing?.id;
+ useLayoutEffect(() => {
+ setDraft(undefined);
+ if (editingId) setFormOpen(true);
+ }, [editingId]);
const form = useRef<HTMLFormElement>(null);
useFocusScope({
- active: formOpen,
+ active: formOpen || Boolean(props.editing),
activationKey: props.editing?.id,
- ready: !props.editing || method === "advanced",
root: () => form.current,
initialFocus: () => form.current?.querySelector<HTMLInputElement>("input"),
scroll: true,
@@ -130,20 +136,15 @@ export function BankAccountsScreen(props: {
const wireType = props.wireTypes?.find(
(entry) => entry.paymentTargetType === method,
);
- const hosts = useMemo(() => wireType?.talerBankHostnames ?? [], [wireType]);
- useEffect(() => {
- if (method === "x-taler-bank" && hosts[0])
- setBankHost((current) => current || hosts[0]);
- }, [hosts, method]);
+ const hosts = wireType?.talerBankHostnames ?? [];
const canSave =
- Boolean(label.trim()) &&
- ((method === "iban" && receiverName.trim() && accountField.trim()) ||
- (method === "x-taler-bank" &&
- receiverName.trim() &&
- bankHost.trim() &&
- bankAccount.trim()) ||
- (method === "bitcoin" && bitcoinAddress.trim()) ||
- (method === "advanced" && paytoUri.trim()));
+ (method === "iban" && receiverName.trim() && accountField.trim()) ||
+ (method === "x-taler-bank" &&
+ receiverName.trim() &&
+ bankHost.trim() &&
+ bankAccount.trim()) ||
+ (method === "bitcoin" && bitcoinAddress.trim()) ||
+ (method === "advanced" && paytoUri.trim());
const submit = () => {
const common = { label: label.trim(), currencies };
if (method === "iban")
@@ -207,7 +208,7 @@ export function BankAccountsScreen(props: {
<p class="text-xs font-semibold uppercase tracking-wide text-secondary">
{account.destination.method}
</p>
- <h2 class="font-semibold">{account.label}</h2>
+ <h2 class="font-semibold">{account.destination.title}</h2>
{account.destination.fields.length > 0 ? (
<dl class="mt-3 grid grid-cols-[auto_1fr] gap-x-4 gap-y-2 text-sm">
{account.destination.fields.map((field) => (
@@ -253,8 +254,8 @@ export function BankAccountsScreen(props: {
}</Button>
<OverflowMenu
label={
- // Translators: Accessible menu label; the placeholder is the user-defined account label.
- i18n.str`More actions for ${account.label}`
+ // Translators: Accessible menu label; the placeholder is the display name of the saved account.
+ i18n.str`More actions for ${account.destination.title}`
}
items={[
{
@@ -330,7 +331,9 @@ export function BankAccountsScreen(props: {
<select
value={method}
onChange={(event) =>
- setMethod(event.currentTarget.value as GuidedMethod)
+ update({
+ method: event.currentTarget.value as GuidedMethod,
+ })
}
class="w-full rounded-xl border border-outline bg-surface px-3 py-3"
>
@@ -356,7 +359,7 @@ export function BankAccountsScreen(props: {
required
value={receiverName}
onInput={(event) =>
- setReceiverName(event.currentTarget.value)
+ update({ receiverName: event.currentTarget.value })
}
autoComplete="name"
class="w-full rounded-xl border border-outline bg-surface px-3 py-3"
@@ -364,7 +367,7 @@ export function BankAccountsScreen(props: {
</label>
<label>
<span class="mb-1 block text-sm text-secondary">
- {wireType?.preferredEntryType === "bban"
+ {!props.editing && wireType?.preferredEntryType === "bban"
? // Translators: Domestic Basic Bank Account Number, as opposed to IBAN.
i18n.str`Bank account number (BBAN)`
: i18n.str`IBAN`}
@@ -373,7 +376,9 @@ export function BankAccountsScreen(props: {
required
value={accountField}
onInput={(event) =>
- setAccountField(event.currentTarget.value.toUpperCase())
+ update({
+ accountField: event.currentTarget.value.toUpperCase(),
+ })
}
autoComplete="off"
class="w-full rounded-xl border border-outline bg-surface px-3 py-3 uppercase"
@@ -385,7 +390,9 @@ export function BankAccountsScreen(props: {
<input
value={receiverPostalCode}
onInput={(event) =>
- setReceiverPostalCode(event.currentTarget.value)
+ update({
+ receiverPostalCode: event.currentTarget.value,
+ })
}
autoComplete="postal-code"
class="w-full rounded-xl border border-outline bg-surface px-3 py-3"
@@ -396,7 +403,7 @@ export function BankAccountsScreen(props: {
<input
value={receiverTown}
onInput={(event) =>
- setReceiverTown(event.currentTarget.value)
+ update({ receiverTown: event.currentTarget.value })
}
autoComplete="address-level2"
class="w-full rounded-xl border border-outline bg-surface px-3 py-3"
@@ -418,7 +425,7 @@ export function BankAccountsScreen(props: {
required
value={receiverName}
onInput={(event) =>
- setReceiverName(event.currentTarget.value)
+ update({ receiverName: event.currentTarget.value })
}
autoComplete="name"
class="w-full rounded-xl border border-outline bg-surface px-3 py-3"
@@ -435,7 +442,7 @@ export function BankAccountsScreen(props: {
<select
value={bankHost}
onChange={(event) =>
- setBankHost(event.currentTarget.value)
+ update({ bankHost: event.currentTarget.value })
}
class="w-full rounded-xl border border-outline bg-surface px-3 py-3"
>
@@ -450,7 +457,7 @@ export function BankAccountsScreen(props: {
required
value={bankHost}
onInput={(event) =>
- setBankHost(event.currentTarget.value)
+ update({ bankHost: event.currentTarget.value })
}
placeholder="bank.example"
class="w-full rounded-xl border border-outline bg-surface px-3 py-3"
@@ -468,7 +475,7 @@ export function BankAccountsScreen(props: {
required
value={bankAccount}
onInput={(event) =>
- setBankAccount(event.currentTarget.value)
+ update({ bankAccount: event.currentTarget.value })
}
autoComplete="off"
class="w-full rounded-xl border border-outline bg-surface px-3 py-3"
@@ -483,7 +490,7 @@ export function BankAccountsScreen(props: {
required
value={bitcoinAddress}
onInput={(event) =>
- setBitcoinAddress(event.currentTarget.value)
+ update({ bitcoinAddress: event.currentTarget.value })
}
autoComplete="off"
class="w-full rounded-xl border border-outline bg-surface px-3 py-3 font-mono"
@@ -496,7 +503,9 @@ export function BankAccountsScreen(props: {
<input
required
value={paytoUri}
- onInput={(event) => setPaytoUri(event.currentTarget.value)}
+ onInput={(event) =>
+ update({ paytoUri: event.currentTarget.value })
+ }
placeholder={
// Translators: Example URI syntax; keep the payto scheme literal.
i18n.str`payto://iban/…`
@@ -506,20 +515,32 @@ export function BankAccountsScreen(props: {
/>
</label>
)}
- <label>
- <span class="mb-1 block text-sm text-secondary">
+ <div>
+ <label
+ for="bank-account-nickname"
+ class="mb-1 block text-sm text-secondary"
+ >
{
// Translators: User-defined local name for this saved destination.
- i18n.str`Label`
+ i18n.str`Nickname in this wallet (optional)`
}
- </span>
+ </label>
<input
- required
+ id="bank-account-nickname"
+ aria-describedby="bank-account-nickname-hint"
value={label}
- onInput={(event) => setLabel(event.currentTarget.value)}
+ onInput={(event) =>
+ update({ label: event.currentTarget.value })
+ }
class="w-full rounded-xl border border-outline bg-surface px-3 py-3"
/>
- </label>
+ <p
+ id="bank-account-nickname-hint"
+ class="mt-1 text-sm text-secondary"
+ >
+ {i18n.str`Choose a name for your account list, like “Holiday savings”. If you leave it blank, the wallet shows the holder’s name or account number.`}
+ </p>
+ </div>
<label>
<span class="mb-1 block text-sm text-secondary">
{
@@ -529,7 +550,9 @@ export function BankAccountsScreen(props: {
</span>
<input
value={currencies}
- onInput={(event) => setCurrencies(event.currentTarget.value)}
+ onInput={(event) =>
+ update({ currencies: event.currentTarget.value })
+ }
placeholder={
// Translators: Example currency codes; keep the codes unchanged.
i18n.str`CHF, EUR`
@@ -565,7 +588,7 @@ export function BankAccountsScreen(props: {
description={
<>
<span class="block font-medium text-onSurface">
- {forgetAccount.label}
+ {forgetAccount.destination.title}
</span>
<span class="mt-2 block">{
/* Translators: A deposit sends digital cash from this wallet to an external account, usually a bank account; it does not add funds to the wallet. */ i18n.str`The account will be removed from your saved deposit destinations. Existing transaction records are not deleted.`
diff --git a/packages/wallet-webui/src/testing/demo-wallet.ts b/packages/wallet-webui/src/testing/demo-wallet.ts
@@ -873,7 +873,7 @@ export class DemoWalletConnection implements WalletConnection {
paytoUri: String(request.paytoUri),
kycCompleted: false,
currencies: request.currencies as string[] | undefined,
- label: String(request.label),
+ label: String(request.label) || undefined,
};
const index = this.state.accounts.findIndex(
(account) => account.bankAccountId === id,
diff --git a/packages/wallet-webui/test/management-model.test.ts b/packages/wallet-webui/test/management-model.test.ts
@@ -7,6 +7,7 @@ import {
import {
bankAccountPayto,
currenciesFromInput,
+ editableBankAccountFields,
exchangeDeleteRequest,
exchangeListView,
exchangeRouteId,
@@ -98,8 +99,6 @@ test("bank account payto construction uses taler-util for every guided method",
receiverName: "Alice Example",
receiverTown: "Biel",
receiverPostalCode: "2502",
- label: "Primary",
- currencies: "CHF",
},
"payto://iban/CH9300762011623852957?bic=POFICHBEXXX",
),
@@ -111,8 +110,6 @@ test("bank account payto construction uses taler-util for every guided method",
host: "bank.example",
account: "alice/savings",
receiverName: "Alice Example",
- label: "Taler bank",
- currencies: "TESTKUDOS",
}),
"payto://x-taler-bank/bank.example/alice/savings?receiver-name=Alice%20Example",
);
@@ -120,13 +117,60 @@ test("bank account payto construction uses taler-util for every guided method",
bankAccountPayto({
method: "bitcoin",
address: "bc1example",
- label: "Bitcoin",
- currencies: "BTC",
}),
"payto://bitcoin/bc1example",
);
});
+test("saved bank accounts use guided fields only when the URI can round-trip", () => {
+ const wireTypes = [
+ { paymentTargetType: "iban" },
+ { paymentTargetType: "x-taler-bank", talerBankHostnames: ["bank.example"] },
+ { paymentTargetType: "bitcoin" },
+ ];
+ const iban = "payto://iban/CH9300762011623852957";
+ const bank = "payto://x-taler-bank/bank.example/alice";
+ const bitcoinAddress =
+ "bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0";
+ const bitcoin = `payto://bitcoin/${bitcoinAddress}`;
+ assert.deepEqual(
+ editableBankAccountFields(
+ `${iban}?receiver-town=Biel&receiver-name=Alice+Example&receiver-postal-code=2502`,
+ wireTypes,
+ ),
+ {
+ method: "iban",
+ accountField: "CH9300762011623852957",
+ receiverName: "Alice Example",
+ receiverTown: "Biel",
+ receiverPostalCode: "2502",
+ },
+ );
+ assert.deepEqual(editableBankAccountFields(bitcoin, wireTypes), {
+ method: "bitcoin",
+ address: bitcoinAddress,
+ });
+ for (const paytoUri of [
+ bank,
+ `${bank}?receiver-name=Alice&message=invoice`,
+ `${bank}?receiver-name=A&receiver-name=B`,
+ "payto://x-taler-bank/other.example/alice?receiver-name=Alice",
+ "payto://iban/POFICHBEXXX/CH9300762011623852957?receiver-name=Alice",
+ `${bitcoin}/${"0".repeat(52)}`,
+ "payto://void/account",
+ "bad URI",
+ ]) {
+ assert.deepEqual(editableBankAccountFields(paytoUri, wireTypes), {
+ method: "advanced",
+ paytoUri,
+ });
+ }
+ assert.deepEqual(editableBankAccountFields(bitcoin, []), {
+ method: "advanced",
+ paytoUri: bitcoin,
+ });
+});
+
test("exchange management route identifiers round-trip URLs", () => {
const url = "https://exchange.example/path/";
assert.equal(exchangeUrlFromRoute(exchangeRouteId(url)), url);
diff --git a/packages/wallet-webui/test/screens.test.tsx b/packages/wallet-webui/test/screens.test.tsx
@@ -3059,6 +3059,109 @@ test("bank account management exposes explicit edit and forget actions", async (
await window.happyDOM.abort();
});
+test("an unlabeled bank account keeps its display name separate from its edit fields", async () => {
+ const window = installDom();
+ const { render, cleanup } = await import("@testing-library/preact");
+ const user = (await import("@testing-library/user-event")).userEvent.setup({
+ document: window.document as unknown as Document,
+ });
+ const paytoUri =
+ "payto://x-taler-bank/bank.example/alice?receiver-name=Alice%20Example";
+ const account = {
+ id: "learned",
+ paytoUri,
+ currencies: ["CHF"],
+ destination: depositDestinationView(paytoUri),
+ };
+ let saved: unknown;
+ const props = {
+ loading: false,
+ working: false,
+ accounts: [account],
+ wireTypes: [
+ {
+ paymentTargetType: "x-taler-bank",
+ talerBankHostnames: ["other.example", "bank.example"],
+ },
+ ],
+ onSave: (value: unknown) => {
+ saved = value;
+ },
+ onEdit: () => {},
+ onCopy: () => {},
+ onForget: () => {},
+ onCancelEdit: () => {},
+ onBack: () => {},
+ };
+ const view = render(<BankAccountsScreen {...props} />);
+ try {
+ assert(view.getByRole("heading", { name: "Alice Example" }));
+ assert(
+ view.getByRole("button", { name: "More actions for Alice Example" }),
+ );
+ await user.click(view.getByRole("button", { name: "Forget" }));
+ assert.match(view.getByRole("dialog").textContent, /Alice Example/);
+ await user.click(view.getByRole("button", { name: "Keep account" }));
+ await user.click(view.getByRole("button", { name: "Edit" }));
+ view.rerender(<BankAccountsScreen {...props} editing={account} />);
+ const holder = view.getByLabelText<HTMLInputElement>("Account holder name");
+ await Promise.resolve();
+ assert.equal(window.document.activeElement, holder);
+ assert.equal(holder.value, "Alice Example");
+ assert.equal(
+ view.getByLabelText<HTMLSelectElement>("Bank").value,
+ "bank.example",
+ );
+ assert.equal(
+ view.getByLabelText<HTMLInputElement>("Account name").value,
+ "alice",
+ );
+ assert.equal(
+ view.getByLabelText<HTMLInputElement>(
+ "Nickname in this wallet (optional)",
+ ).value,
+ "",
+ );
+ await user.clear(holder);
+ await user.type(holder, "Alice Smith");
+ view.rerender(<BankAccountsScreen {...props} editing={{ ...account }} />);
+ await user.click(view.getByRole("button", { name: "Save changes" }));
+ assert.deepEqual(saved, {
+ method: "x-taler-bank",
+ host: "bank.example",
+ account: "alice",
+ receiverName: "Alice Smith",
+ label: "",
+ currencies: "CHF",
+ });
+ const rawUri = paytoUri + "&message=invoice";
+ view.rerender(
+ <BankAccountsScreen
+ {...props}
+ editing={{
+ ...account,
+ id: "other",
+ paytoUri: rawUri,
+ label: "Invoices",
+ }}
+ />,
+ );
+ assert.equal(
+ view.getByLabelText<HTMLInputElement>("Payto URI").value,
+ rawUri,
+ );
+ assert.equal(
+ view.getByLabelText<HTMLInputElement>(
+ "Nickname in this wallet (optional)",
+ ).value,
+ "Invoices",
+ );
+ } finally {
+ cleanup();
+ await window.happyDOM.abort();
+ }
+});
+
test("bank account management guides supported wire types and retains advanced entry", async () => {
const window = installDom();
const { render, cleanup } = await import("@testing-library/preact");
@@ -3113,9 +3216,24 @@ test("bank account management guides supported wire types and retains advanced e
assert(view.getByRole("option", { name: "Advanced payto URI" }));
await user.type(view.getByLabelText("Account holder name"), "Alice");
await user.type(view.getByLabelText("IBAN"), "DE75512108001245126199");
- await user.type(view.getByLabelText("Label"), "Salary account");
+ const nickname = view.getByRole("textbox", {
+ name: "Nickname in this wallet (optional)",
+ description: /the wallet shows the holder’s name or account number/,
+ });
+ const addAccount = view.getByRole("button", { name: "Add account" });
+ await user.click(addAccount);
+ assert.deepEqual(saved, {
+ method: "iban",
+ accountField: "DE75512108001245126199",
+ receiverName: "Alice",
+ receiverTown: "",
+ receiverPostalCode: "",
+ label: "",
+ currencies: "",
+ });
+ await user.type(nickname, "Salary account");
await user.type(view.getByLabelText("Currencies (optional)"), "EUR");
- await user.click(view.getByRole("button", { name: "Add account" }));
+ await user.click(addAccount);
assert.deepEqual(saved, {
method: "iban",
accountField: "DE75512108001245126199",