commit a3f8929ffccbcb7903403b553ff5b48f3e6fc349
parent 417336551683101fe06225223dec104d17df0958
Author: Florian Dold <dold@taler.net>
Date: Wed, 25 Nov 2026 16:55:16 +0100
wallet web UI: explain unsupported QR codes while scanning
For EPC payment codes and Swiss QR bills, suggest scanning the code
with a banking app. Keep the camera running for the next code.
Diffstat:
4 files changed, 89 insertions(+), 14 deletions(-)
diff --git a/packages/wallet-webui/src/routes/App.tsx b/packages/wallet-webui/src/routes/App.tsx
@@ -199,6 +199,7 @@ import {
cancelTransactionBeforeCompleting,
restoreActionGateReason,
runGuardedValueOperation,
+ unsupportedQrCodeHint,
withdrawalTransferResultHint,
} from "./action-model.js";
import type {
@@ -3078,11 +3079,30 @@ function QrScanRoute() {
const [, navigate] = useLocation();
const videoRef = useRef<HTMLVideoElement>(null);
const [error, setError] = useState<string>();
+ const [scanHint, setScanHint] = useState<string>();
useEffect(() => {
let stream: MediaStream | undefined;
let frame = 0;
let finished = false;
+ let lastPayload: string | undefined;
const canvas = document.createElement("canvas");
+ const handleCode = async (payload: string) => {
+ const hint = unsupportedQrCodeHint(payload);
+ if (hint) {
+ setScanHint(hint);
+ return;
+ }
+ try {
+ const entry = await platform.actionInbox.put(payload, "qr");
+ if (finished) return;
+ finished = true;
+ for (const track of stream?.getTracks() ?? []) track.stop();
+ navigate(`/action/${entry.id}`, { replace: true });
+ } catch {
+ if (!finished)
+ setScanHint(i18n.str`The wallet link could not be opened.`);
+ }
+ };
const scan = async () => {
const video = videoRef.current;
if (!video || finished) return;
@@ -3094,19 +3114,10 @@ function QrScanRoute() {
const image = context?.getImageData(0, 0, canvas.width, canvas.height);
const code: jsQrTypes.QRCode | null | undefined =
image && decodeQr(image.data, image.width, image.height);
- if (code) {
- try {
- const entry = await platform.actionInbox.put(code.data, "qr");
- finished = true;
- for (const track of stream?.getTracks() ?? []) track.stop();
- navigate(`/action/${entry.id}`, { replace: true });
- return;
- } catch {
- // Ignore non-Taler QR payloads and keep scanning.
- }
- }
+ if (code && code.data !== lastPayload) await handleCode(code.data);
+ lastPayload = code?.data;
}
- frame = requestAnimationFrame(() => void scan());
+ if (!finished) frame = requestAnimationFrame(() => void scan());
};
void navigator.mediaDevices
.getUserMedia({
@@ -3146,6 +3157,7 @@ function QrScanRoute() {
<QrScannerScreen
videoRef={videoRef}
error={error}
+ scanHint={scanHint}
onEnterLink={() => navigate("/enter")}
onCancel={() => navigate("/")}
/>
diff --git a/packages/wallet-webui/src/routes/action-model.ts b/packages/wallet-webui/src/routes/action-model.ts
@@ -1,5 +1,22 @@
import { Result, type Result as ResultType } from "@gnu-taler/taler-util";
import { i18n } from "../i18n/runtime.js";
+import { validateActionUri } from "../platform/action-inbox.js";
+
+export function unsupportedQrCodeHint(payload: string): string | undefined {
+ try {
+ validateActionUri(payload);
+ return undefined;
+ } catch {
+ // Recognize the record headers without interpreting the payment details.
+ if (/^BCD\r?\n\d{3}\r?\n[1-8]\r?\nSCT\r?\n/.test(payload)) {
+ return i18n.str`This wallet cannot open EPC payment QR codes. Try scanning this code with your banking app.`;
+ }
+ if (/^SPC\r?\n\d{4}\r?\n1\r?\n/.test(payload)) {
+ return i18n.str`This wallet cannot open Swiss QR bills. Try scanning this code with your banking app.`;
+ }
+ return i18n.str`This wallet does not support this QR code.`;
+ }
+}
export type TransactionCancellationOutcome =
| { cancelled: true }
diff --git a/packages/wallet-webui/src/screens/QrScannerScreen.tsx b/packages/wallet-webui/src/screens/QrScannerScreen.tsx
@@ -6,6 +6,7 @@ import { i18n } from "../i18n/runtime.js";
export function QrScannerScreen(props: {
videoRef: Ref<HTMLVideoElement>;
error?: string;
+ scanHint?: string;
onEnterLink: () => void;
onCancel: () => void;
}) {
@@ -13,7 +14,12 @@ export function QrScannerScreen(props: {
<div class="mx-auto w-full max-w-2xl space-y-4">
<div>
<h1 class="text-2xl font-bold">{i18n.str`Scan a GNU Taler QR code`}</h1>
- <p class="text-muted">{i18n.str`Keep the code inside the camera frame.`}</p>
+ <p
+ role="status"
+ class={props.scanHint ? "font-medium text-onSurface" : "text-muted"}
+ >
+ {props.scanHint ?? i18n.str`Keep the code inside the camera frame.`}
+ </p>
</div>
<Card>
{props.error ? (
diff --git a/packages/wallet-webui/test/action-model.test.ts b/packages/wallet-webui/test/action-model.test.ts
@@ -1,13 +1,53 @@
import assert from "node:assert/strict";
import test from "node:test";
-import { Result } from "@gnu-taler/taler-util";
+import { getQrCodesForPayto, Result } from "@gnu-taler/taler-util";
import {
cancelTransactionBeforeCompleting,
restoreActionGateReason,
runGuardedValueOperation,
+ unsupportedQrCodeHint,
withdrawalTransferResultHint,
} from "../src/routes/action-model.js";
+test("bank payment QR codes direct the user to their banking app", () => {
+ const examples = [
+ { iban: "DE75512108001245126199", amount: "EUR:10", format: "EPC" },
+ { iban: "CH9300762011623852957", amount: "CHF:10", format: "Swiss" },
+ ];
+ for (const { iban, amount, format } of examples) {
+ const uri = `payto://iban/${iban}?receiver-name=Alice&amount=${amount}`;
+ const [code] = getQrCodesForPayto(uri);
+ for (const payload of [
+ code.qrContent,
+ code.qrContent.replaceAll("\n", "\r\n"),
+ ]) {
+ const hint = unsupportedQrCodeHint(payload);
+ assert.ok(hint);
+ assert.ok(hint.includes(format));
+ assert.match(hint, /banking app/);
+ }
+ assert.equal(unsupportedQrCodeHint(uri), undefined);
+ }
+});
+
+test("unrelated QR payloads get a generic message and Taler links can proceed", () => {
+ for (const payload of [
+ "https://example.com/",
+ "SPC\nshopping list",
+ "BCD123",
+ "payto://iban/invalid",
+ ]) {
+ assert.equal(
+ unsupportedQrCodeHint(payload),
+ "This wallet does not support this QR code.",
+ );
+ }
+ assert.equal(
+ unsupportedQrCodeHint("taler://pay/example.com/order/session"),
+ undefined,
+ );
+});
+
test("withdrawal callback status is presented only as a bank hint", () => {
assert.match(
withdrawalTransferResultHint("success"),