commit 95dc27cfe9fedd1e17f68a49137ca4b83f7f996e
parent 5d5aa758e7a1e9be5d664604a64a8de1c67023a3
Author: Florian Dold <dold@taler.net>
Date: Wed, 25 Nov 2026 20:06:24 +0100
wallet web UI: show each banking QR code for the selected transfer
Use the shared banking QR frame for EPC and Swiss codes. Keep the Swiss
code first when a QR-bill transfer offers more than one format.
Issue: https://bugs.taler.net/n/12108
Diffstat:
10 files changed, 127 insertions(+), 136 deletions(-)
diff --git a/packages/wallet-webui/package.json b/packages/wallet-webui/package.json
@@ -43,7 +43,6 @@
"@sqlite.org/sqlite-wasm": "3.53.0-build1",
"jsqr": "^1.4.0",
"preact": "10.29.8",
- "qrcode-generator": "1.4.4",
"swr": "2.2.2",
"wouter-preact": "^3.7.1"
},
diff --git a/packages/wallet-webui/src/routes/withdrawal-model.ts b/packages/wallet-webui/src/routes/withdrawal-model.ts
@@ -12,6 +12,7 @@ import {
type ExchangeListItem,
type ObservedDepositTransaction,
type ObservedWithdrawalTransaction,
+ type QrCodeSpec,
type WithdrawalExchangeAccountDetails,
} from "@gnu-taler/taler-util";
import type { WithdrawalProviderView } from "../screens/WithdrawalScreen.js";
@@ -28,8 +29,7 @@ export interface WireOptionView {
bankLabel?: string;
fields: WireFieldView[];
paytoUri?: string;
- qrContent?: string;
- qrStyle?: "generic" | "swiss-payment";
+ qrCodes?: QrCodeSpec[];
externalUri?: string;
expiresAt?: number;
restrictionHints?: string[];
@@ -163,7 +163,7 @@ export function wireOptions(
id: `${accountIndex}-${optionIndex}`,
label:
account.bankLabel && account.transferOptions.length > 1
- ? `${account.bankLabel} — banking app`
+ ? /* Translators: %1$s is a bank-provided account label. */ i18n.str`${account.bankLabel} — banking app`
: (account.bankLabel ?? i18n.str`Open banking app`),
...(account.bankLabel ? { bankLabel: account.bankLabel } : {}),
fields: [],
@@ -187,11 +187,12 @@ export function wireOptions(
option.type === "ch-qr-bill"
? option.qrReferenceNumber
: params["message"];
- const qrCode =
- option.type === "ch-qr-bill"
- ? (option.qrCodes.find((candidate) => candidate.type === "spc") ??
- option.qrCodes[0])
- : option.qrCodes[0];
+ const qrCodes = option.qrCodes.filter((qr) => qr.qrContent);
+ if (option.type === "ch-qr-bill") {
+ qrCodes.sort(
+ (a, b) => Number(b.type === "spc") - Number(a.type === "spc"),
+ );
+ }
if (accountNumber)
fields.push({
label: Paytos.getTargetLabel(parsed),
@@ -219,12 +220,7 @@ export function wireOptions(
...(account.bankLabel ? { bankLabel: account.bankLabel } : {}),
fields,
paytoUri: option.paytoUri,
- ...(qrCode?.qrContent
- ? {
- qrContent: qrCode.qrContent,
- qrStyle: qrCode.type === "spc" ? "swiss-payment" : "generic",
- }
- : {}),
+ qrCodes,
...common,
};
});
diff --git a/packages/wallet-webui/src/screens/StorybookScreen.tsx b/packages/wallet-webui/src/screens/StorybookScreen.tsx
@@ -16,6 +16,7 @@ import { TransactionScreen } from "./TransactionScreen.js";
import { WithdrawalScreen } from "./WithdrawalScreen.js";
import { WithdrawalReviewScreen } from "./WithdrawalReviewScreen.js";
import { WireTransferScreen } from "./WireTransferScreen.js";
+import { wireOptions } from "../routes/withdrawal-model.js";
import { TokenListScreen } from "./TokenListScreen.js";
import { DonauSettingsScreen } from "./DonauSettingsScreen.js";
import { DonauStatementsScreen } from "./DonauStatementsScreen.js";
@@ -44,6 +45,7 @@ import {
} from "preact";
import { useState } from "preact/hooks";
import {
+ getQrCodesForPayto,
ScopeType,
TalerErrorCode,
type ScopeInfo,
@@ -60,6 +62,9 @@ const reviewedStoryMap = new Map(
reviewedStories.map((story) => [story.id, story]),
);
+const wireStoryReference = "210000000003139471430009017";
+const wireStoryPayto = `payto://iban/CH4431999123000889012?receiver-name=Taler%20Operations%20AG&receiver-town=Biel&receiver-postal-code=2502&amount=CHF:11.23&ch-qrr=${wireStoryReference}`;
+
function popupBalance(
scopeInfo: ScopeInfo,
availableValue: string,
@@ -1522,36 +1527,22 @@ Example exchange terms.`}
amountRaw={"CHF:11.23"}
amountEffective={"CHF:10"}
exchange={"https://taler-ops.example/"}
- options={[
+ options={wireOptions([
{
- id: "iban",
- // Translators: %1$s is a bank-provided account label; Swiss QR bill is a payment method name.
- label: i18n.str`${"Swiss bank account"} — Swiss QR bill`,
- paytoUri:
- "payto://iban/CH6808573105529100001?amount=CHF%3A11.23&message=RESERVE123",
- qrContent: "SPC\n0200\n1\nCH6808573105529100001",
- qrStyle: "swiss-payment",
- fields: [
- { label: "IBAN", value: "CH68 0857 3105 5291 0000 1" },
- {
- label: i18n.str`Recipient name`,
- value: "Taler Operations AG",
- },
- { label: i18n.str`Amount`, value: "CHF:11.23" },
+ status: "ok",
+ paytoUri: wireStoryPayto,
+ bankLabel: "Swiss bank account",
+ transferOptions: [
{
- label: i18n.str`Payment reference`,
- value: "RESERVE123",
+ type: "ch-qr-bill",
+ paytoUri: wireStoryPayto,
+ qrReferenceNumber: wireStoryReference,
+ qrCodes: getQrCodesForPayto(wireStoryPayto),
},
+ { type: "uri", uri: "https://bank.example/transfer/ABC" },
],
},
- {
- id: "app",
- // Translators: %1$s is a bank-provided account label.
- label: i18n.str`${"Swiss bank account"} — banking app`,
- fields: [],
- externalUri: "https://bank.example/transfer/ABC",
- },
- ]}
+ ])}
onCopy={() => {}}
onOpenExternal={() => {}}
onDone={() => {}}
diff --git a/packages/wallet-webui/src/screens/WireTransferScreen.tsx b/packages/wallet-webui/src/screens/WireTransferScreen.tsx
@@ -178,6 +178,7 @@ export function WireTransferScreen(props: {
[activeOption].map((option) => {
const index = activeOptionIndex;
const qrHeadingId = `bank-qr-heading-${option.id}`;
+ const qrCodes = option.qrCodes ?? [];
const expired =
option.expiresAt !== undefined && option.expiresAt <= now;
const blockedReason = expired
@@ -254,18 +255,36 @@ export function WireTransferScreen(props: {
</div>
</div>
)}
- {!blockedReason && option.qrContent && (
+ {!blockedReason && qrCodes.length > 0 && (
<section aria-labelledby={qrHeadingId}>
<h4
id={qrHeadingId}
class="mb-3 text-center font-semibold"
>{i18n.str`Scan with your banking app`}</h4>
- <QrFrame
- content={option.qrContent}
- // Translators: %1$s is a bank-provided transfer-method label.
- alt={i18n.str`Bank transfer QR code for ${option.label}`}
- style={option.qrStyle}
- />
+ {qrCodes.map((qr) => {
+ const label =
+ qr.type === "spc"
+ ? i18n.str`Swiss QR bill`
+ : i18n.str`EPC payment QR code`;
+ return (
+ <figure key={qr.qrContent} class="mb-4">
+ {qrCodes.length > 1 && (
+ <figcaption class="text-center text-sm">
+ {label}
+ </figcaption>
+ )}
+ <QrFrame
+ content={qr.qrContent}
+ alt={label}
+ style={
+ qr.type === "spc"
+ ? "swiss-payment"
+ : "epc-payment"
+ }
+ />
+ </figure>
+ );
+ })}
</section>
)}
{!blockedReason && option.fields.length > 0 && (
diff --git a/packages/wallet-webui/src/styles/main.css b/packages/wallet-webui/src/styles/main.css
@@ -115,9 +115,6 @@ input {
.qr-frame {
border-radius: 8%;
}
-.qr-frame[data-qr-style="swiss-payment"] {
- border-radius: 0;
-}
.qr-frame::before {
content: "";
position: absolute;
@@ -135,9 +132,6 @@ input {
);
animation: qr-rotate 10s linear infinite;
}
-.qr-frame[data-qr-style="swiss-payment"]::before {
- display: none;
-}
@property --qr-angle {
syntax: "<angle>";
initial-value: 0deg;
diff --git a/packages/wallet-webui/src/testing/demo-wallet.ts b/packages/wallet-webui/src/testing/demo-wallet.ts
@@ -1,5 +1,6 @@
import {
ConfirmPayResultType,
+ getQrCodesForPayto,
observedTransaction,
ExchangeEntryStatus,
ExchangeEntrySource,
@@ -123,7 +124,11 @@ function withdrawalAccount(transferAmount: AmountString = "CHF:10.50") {
bankLabel: "Demo bank account",
transferAmount,
transferOptions: [
- { type: "payto" as const, paytoUri, qrCodes: [] },
+ {
+ type: "payto" as const,
+ paytoUri,
+ qrCodes: getQrCodesForPayto(paytoUri),
+ },
{
type: "uri" as const,
uri: "https://bank.demo.invalid/transfer/manual",
diff --git a/packages/wallet-webui/src/ui/QrFrame.tsx b/packages/wallet-webui/src/ui/QrFrame.tsx
@@ -1,72 +1,55 @@
-import qrcode from "qrcode-generator";
+import { QrCodeFrame, generateQrDataUrl } from "@gnu-taler/web-util/browser";
import { useMemo } from "preact/hooks";
import { i18n } from "../i18n/runtime.js";
-export const MAX_QR_CONTENT_BYTES = 1273;
-
-export function qrDataUrl(content: string): string | undefined {
- if (new TextEncoder().encode(content).byteLength > MAX_QR_CONTENT_BYTES)
- return undefined;
- try {
- const code = qrcode(0, "H");
- code.addData(content, "Byte");
- code.make();
- return `data:image/svg+xml,${encodeURIComponent(code.createSvgTag({ scalable: true, margin: 0 }))}`;
- } catch {
- return undefined;
- }
-}
-
-function SwissCross() {
- return (
- <svg
- aria-hidden="true"
- data-testid="swiss-payment-cross"
- viewBox="0 0 70 70"
- class="absolute left-1/2 top-1/2 z-[2] h-[12.5%] w-[12.5%] -translate-x-1/2 -translate-y-1/2"
- >
- <rect width="70" height="70" fill="#000" />
- <path fill="#fff" d="M29 14h12v15h15v12H41v15H29V41H14V29h15z" />
- </svg>
- );
-}
-
export function QrFrame(props: {
content: string;
alt: string;
- style?: "generic" | "swiss-payment";
+ style?: "generic" | "swiss-payment" | "epc-payment";
}) {
- const dataUrl = useMemo(() => qrDataUrl(props.content), [props.content]);
- const swissPayment =
- props.style === "swiss-payment" || props.content.startsWith("SPC\n");
+ const style =
+ props.style ??
+ (/^SPC\r?\n/.test(props.content) ? "swiss-payment" : "generic");
+ const variant =
+ style === "swiss-payment"
+ ? "swiss"
+ : style === "epc-payment"
+ ? "epc"
+ : "taler";
+ const code = useMemo(
+ () => generateQrDataUrl(props.content, variant),
+ [props.content, variant],
+ );
+ if (code.type === "error") {
+ return (
+ <p role="alert" class="p-6 text-center text-sm text-secondary">
+ {i18n.str`QR code unavailable. Use the text or copy action instead.`}
+ </p>
+ );
+ }
+ if (variant !== "taler") {
+ return (
+ <div data-qr-style={style} class="mx-auto w-full max-w-sm">
+ <QrCodeFrame code={code} size={384} alt={props.alt} />
+ </div>
+ );
+ }
return (
<div
- data-qr-style={swissPayment ? "swiss-payment" : "generic"}
- class={`qr-frame relative mx-auto grid aspect-square w-full max-w-sm place-items-center overflow-hidden ${swissPayment ? "bg-white p-[8.93%]" : "bg-[#F1F1F4] p-[6.25%]"}`}
+ data-qr-style={style}
+ class="qr-frame relative mx-auto grid aspect-square w-full max-w-sm place-items-center overflow-hidden bg-[#F1F1F4] p-[6.25%]"
>
- {dataUrl ? (
- <>
- <img
- src={dataUrl}
- alt={props.alt}
- class="relative z-[1] h-full w-full bg-white"
- />
- {swissPayment ? (
- <SwissCross />
- ) : (
- <img
- src="./qr-logo.svg"
- alt=""
- data-testid="taler-qr-logo"
- class="absolute left-1/2 top-1/2 z-[2] h-[12.5%] w-auto -translate-x-1/2 -translate-y-1/2"
- />
- )}
- </>
- ) : (
- <p role="alert" class="p-6 text-center text-sm text-secondary">
- {i18n.str`QR code unavailable. Use the text or copy action instead.`}
- </p>
- )}
+ <img
+ src={code.url}
+ alt={props.alt}
+ class="relative z-[1] h-full w-full bg-white"
+ />
+ <img
+ src="./qr-logo.svg"
+ alt=""
+ data-testid="taler-qr-logo"
+ class="absolute left-1/2 top-1/2 z-[2] h-[12.5%] w-auto -translate-x-1/2 -translate-y-1/2"
+ />
</div>
);
}
diff --git a/packages/wallet-webui/test/screens.test.tsx b/packages/wallet-webui/test/screens.test.tsx
@@ -34,7 +34,7 @@ import { ShoppingScreen } from "../src/screens/ShoppingScreen.js";
import { Shell } from "../src/ui/Shell.js";
import { ConfirmationDialog } from "../src/ui/ConfirmationDialog.js";
import { RequestProgressPanel } from "../src/ui/RequestProgress.js";
-import { MAX_QR_CONTENT_BYTES, QrFrame } from "../src/ui/QrFrame.js";
+import { QrFrame } from "../src/ui/QrFrame.js";
import { StorybookScreen } from "../src/screens/StorybookScreen.js";
import { SettingsScreen } from "../src/screens/SettingsScreen.js";
import { PopupScreen } from "../src/screens/PopupScreen.js";
@@ -1538,7 +1538,7 @@ test("oversized QR content leaves an accessible manual fallback", async () => {
const { render, cleanup } = await import("@testing-library/preact");
const view = render(
<QrFrame
- content={"x".repeat(MAX_QR_CONTENT_BYTES + 1)}
+ content={"x".repeat(1274)}
alt="Transfer QR code"
/>,
);
@@ -3519,7 +3519,7 @@ test("wire instructions become unavailable when their expiry is reached", async
label: "Bank transfer",
fields: [{ label: "Payment reference", value: "RESERVE123" }],
paytoUri: "payto://iban/CH680857?message=RESERVE123",
- qrContent: "payto://iban/CH680857?message=RESERVE123",
+ qrCodes: [{ type: "spc", qrContent: "SPC\n0200\n1" }],
externalUri: "https://bank.example/transfer/ABC",
expiresAt: Date.now() + 30,
},
@@ -3537,10 +3537,7 @@ test("wire instructions become unavailable when their expiry is reached", async
assert.match(view.getByRole("alert").textContent ?? "", /expired/i);
assert.equal(view.queryByRole("button", { name: "Copy" }), null);
assert.equal(view.queryByRole("button", { name: "Open banking app" }), null);
- assert.equal(
- view.queryByRole("img", { name: /Bank transfer QR code/ }),
- null,
- );
+ assert.equal(view.queryByRole("img", { name: "Swiss QR bill" }), null);
cleanup();
await window.happyDOM.abort();
});
@@ -4220,7 +4217,7 @@ test("developer settings require explicit confirmation before clearing the walle
await window.happyDOM.abort();
});
-test("Swiss payment QR codes use the Swiss cross and omit Taler branding", async () => {
+test("all available bank QR codes are shown with their format and only the Swiss bill has a cross", async () => {
const window = installDom();
const { render, cleanup } = await import("@testing-library/preact");
const view = render(
@@ -4234,8 +4231,10 @@ test("Swiss payment QR codes use the Swiss cross and omit Taler branding", async
id: "swiss",
label: "Swiss QR bill",
fields: [],
- qrContent: "SPC\n0200\n1",
- qrStyle: "swiss-payment",
+ qrCodes: [
+ { type: "spc", qrContent: "SPC\n0200\n1" },
+ { type: "epc-qr", qrContent: "BCD\n002" },
+ ],
},
]}
onCopy={() => {}}
@@ -4248,10 +4247,16 @@ test("Swiss payment QR codes use the Swiss cross and omit Taler branding", async
assert.equal(view.queryByTestId("taler-qr-logo"), null);
assert.equal(
view
- .getByRole("img", { name: "Bank transfer QR code for Swiss QR bill" })
+ .getByRole("img", { name: "Swiss QR bill" })
.parentElement?.getAttribute("data-qr-style"),
"swiss-payment",
);
+ assert.equal(
+ view
+ .getByRole("img", { name: "EPC payment QR code" })
+ .parentElement?.getAttribute("data-qr-style"),
+ "epc-payment",
+ );
cleanup();
await window.happyDOM.abort();
});
@@ -4330,8 +4335,7 @@ test("deposit KYC authentication identifies the source and keeps all transfer op
label: "Swiss QR bill",
fields: [{ label: "Amount", value: "CHF:0.01" }],
paytoUri: "payto://iban/CH4431999123000889012?amount=CHF%3A0.01",
- qrContent: "SPC\n0200\n1",
- qrStyle: "swiss-payment",
+ qrCodes: [{ type: "spc", qrContent: "SPC\n0200\n1" }],
},
{
id: "app",
diff --git a/packages/wallet-webui/test/withdrawal-model.test.ts b/packages/wallet-webui/test/withdrawal-model.test.ts
@@ -42,8 +42,9 @@ test("wire options expose accepted post-reserve transfer details", () => {
const options = wireOptions(accounts);
assert.equal(options.length, 1);
assert.equal(options[0].label, "Swiss bank account");
- assert.equal(options[0].qrContent, "SPC\n0200\n1");
- assert.equal(options[0].qrStyle, "swiss-payment");
+ assert.deepEqual(options[0].qrCodes, [
+ { type: "spc", qrContent: "SPC\n0200\n1" },
+ ]);
assert.match(options[0].paytoUri ?? "", /^payto:\/\/iban\/CH68/);
assert(
options[0].fields.some(
@@ -167,7 +168,7 @@ test("known source accounts fail restrictions closed", () => {
sourcePaytoUri: "payto://iban/CH5210395CX7GTDCRC3C4",
})[0];
assert.match(blocked.unavailableReason ?? "", /does not accept transfers/);
- assert.equal(blocked.qrContent, "BCD\n002");
+ assert.equal(blocked.qrCodes?.[0].qrContent, "BCD\n002");
const allowed = wireOptions([account], {
sourcePaytoUri: "payto://iban/DE75512108001245126199",
@@ -231,7 +232,7 @@ test("transaction withdrawal continuation preserves every stored transfer method
assert.equal(transactionWireOptions(transaction).length, 2);
});
-test("Swiss QR bill options prefer the SPC code and its mandated visual style", () => {
+test("Swiss QR bill options keep every supplied code and put the SPC code first", () => {
const accounts = [
{
paytoUri: "payto://iban/CH4431999123000889012",
@@ -250,8 +251,10 @@ test("Swiss QR bill options prefer the SPC code and its mandated visual style",
},
] as WithdrawalExchangeAccountDetails[];
const option = wireOptions(accounts)[0];
- assert.equal(option.qrContent, "SPC\n0200\n1");
- assert.equal(option.qrStyle, "swiss-payment");
+ assert.deepEqual(option.qrCodes, [
+ { type: "spc", qrContent: "SPC\n0200\n1" },
+ { type: "epc-qr", qrContent: "BCD\n002" },
+ ]);
assert(
option.fields.some(
(field) =>
@@ -290,7 +293,7 @@ test("deposit KYC authentication preserves every account transfer method", () =>
} as unknown as TransactionDeposit;
const options = depositKycAuthWireOptions(transaction);
assert.equal(options.length, 2);
- assert.equal(options[0].qrStyle, "swiss-payment");
+ assert.equal(options[0].qrCodes?.[0].type, "spc");
assert.equal(options[1].externalUri, "https://bank.example/transfer/auth");
});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
@@ -712,9 +712,6 @@ importers:
preact:
specifier: 10.29.8
version: 10.29.8(preact-render-to-string@5.2.6)
- qrcode-generator:
- specifier: 1.4.4
- version: 1.4.4
swr:
specifier: 2.2.2
version: 2.2.2(react@18.3.1)