taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit aea8f22a11e8f0d244bfb05212fbe922755af8d1
parent 57c566a176eea508fcd4d4a4494256774648327d
Author: Florian Dold <dold@taler.net>
Date:   Wed, 25 Nov 2026 21:19:38 +0100

wallet web UI: offer retry only for valid incoming links

Dismiss invalid links and remove them from the URL so refreshing the
wallet does not show the same error again. Keep valid links available
for another attempt if the wallet cannot store them.

Issue: https://bugs.taler.net/n/12091

Diffstat:
Mpackages/wallet-webui/src/platform/action-inbox.ts | 6+++++-
Mpackages/wallet-webui/src/platform/adapters.ts | 72+++++++++++++++++++++++++++++++++++++-----------------------------------
Mpackages/wallet-webui/src/routes/App.tsx | 35+++++++++++++++++++----------------
Mpackages/wallet-webui/test/payment-entry.test.tsx | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
4 files changed, 127 insertions(+), 64 deletions(-)

diff --git a/packages/wallet-webui/src/platform/action-inbox.ts b/packages/wallet-webui/src/platform/action-inbox.ts @@ -43,12 +43,16 @@ export function randomActionId(): string { return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(""); } +export class InvalidActionUriError extends Error {} + export function validateActionUri(uri: string): void { if ( Result.isError(TalerUris.parse(uri)) && Result.isError(Paytos.fromString(uri)) ) { - throw Error("Invalid or unsupported GNU Taler or payto URI"); + throw new InvalidActionUriError( + "Invalid or unsupported GNU Taler or payto URI", + ); } } diff --git a/packages/wallet-webui/src/platform/adapters.ts b/packages/wallet-webui/src/platform/adapters.ts @@ -1,5 +1,6 @@ import type { ActionEntry, + ActionInbox, BrowserIntegrationSettings, PersistenceCapability, PlatformAdapter, @@ -12,6 +13,7 @@ import { } from "./integration-settings.js"; import { ExtensionSessionActionStore, + InvalidActionUriError, SessionStorageActionStore, StoredActionInbox, } from "./action-inbox.js"; @@ -42,6 +44,39 @@ function browserGuidance(): PersistenceCapability["guidance"] { return "other"; } +async function captureProtocolInput( + inbox: ActionInbox, + target: WalletTarget, +): Promise<ActionEntry | undefined> { + const search = new URLSearchParams(location.search); + const uri = search.get("talerUri"); + if (uri === null) return undefined; + const fromBrowser = + target !== "pwa" && search.get("talerActionSource") === "browser"; + const clearInput = () => { + search.delete("talerUri"); + if (target !== "pwa") search.delete("talerActionSource"); + const query = search.toString(); + history.replaceState( + history.state, + "", + `${location.pathname}${query ? `?${query}` : ""}${location.hash}`, + ); + }; + let entry: ActionEntry; + try { + entry = await inbox.put(uri, "protocol", { + autoOpen: true, + fulfillmentTarget: fromBrowser ? "current-tab" : "new-tab", + }); + } catch (cause) { + if (cause instanceof InvalidActionUriError) clearInput(); + throw cause; + } + clearInput(); + return entry; +} + export function makePwaPlatform(): PlatformAdapter { const actionInbox = new StoredActionInbox(new SessionStorageActionStore()); return { @@ -138,22 +173,7 @@ export function makePwaPlatform(): PlatformAdapter { return false; }, isExtensionOnlyPage: () => false, - async captureProtocolInput(): Promise<ActionEntry | undefined> { - const search = new URLSearchParams(location.search); - const rawUri = search.get("talerUri"); - if (!rawUri) return undefined; - const entry = await actionInbox.put(rawUri, "protocol", { - autoOpen: true, - }); - search.delete("talerUri"); - const cleanSearch = search.toString(); - history.replaceState( - history.state, - "", - `${location.pathname}${cleanSearch ? `?${cleanSearch}` : ""}${location.hash}`, - ); - return entry; - }, + captureProtocolInput: () => captureProtocolInput(actionInbox, "pwa"), async getBrowserIntegrationSettings() { return undefined; }, @@ -228,25 +248,7 @@ export function makeExtensionPlatform( } }, isExtensionOnlyPage: () => location.pathname.endsWith("popup.html"), - async captureProtocolInput(): Promise<ActionEntry | undefined> { - const search = new URLSearchParams(location.search); - const rawUri = search.get("talerUri"); - if (!rawUri) return undefined; - const browserAction = search.get("talerActionSource") === "browser"; - const entry = await actionInbox.put(rawUri, "protocol", { - autoOpen: true, - fulfillmentTarget: browserAction ? "current-tab" : "new-tab", - }); - search.delete("talerUri"); - search.delete("talerActionSource"); - const cleanSearch = search.toString(); - history.replaceState( - history.state, - "", - `${location.pathname}${cleanSearch ? `?${cleanSearch}` : ""}${location.hash}`, - ); - return entry; - }, + captureProtocolInput: () => captureProtocolInput(actionInbox, target), async getBrowserIntegrationSettings() { return readBrowserIntegrationSettings(); }, diff --git a/packages/wallet-webui/src/routes/App.tsx b/packages/wallet-webui/src/routes/App.tsx @@ -105,6 +105,7 @@ import { } from "../platform/storage-manager.js"; import { completeActionBestEffort, + InvalidActionUriError, validateActionUri, } from "../platform/action-inbox.js"; import { Shell } from "../ui/Shell.js"; @@ -380,20 +381,17 @@ function NotificationBridge() { function ProtocolCapture() { const { platform } = useServices(); const [, navigate] = useLocation(); - const [error, setError] = useState<ErrorPresentation>(); + const [error, setError] = useState<"invalid-link" | "save-failed">(); const [working, setWorking] = useState(false); const capture = useCallback(async () => { setWorking(true); - setError(undefined); try { const entry = await platform.captureProtocolInput(); + setError(undefined); if (entry) navigate(`/action/${entry.id}`, { replace: true }); } catch (cause) { setError( - errorFromException( - cause, - i18n.str`The wallet could not save the requested action.`, - ), + cause instanceof InvalidActionUriError ? "invalid-link" : "save-failed", ); } finally { setWorking(false); @@ -406,18 +404,23 @@ function ProtocolCapture() { return ( <div class="fixed inset-x-4 top-4 z-50 mx-auto max-w-2xl"> <ErrorCard - title={ - /* Translators: The wallet could not store an incoming Taler link for later review; no financial operation has been confirmed. */ i18n.str`Action could not be captured` - } - error={error} + error={localError( + error === "invalid-link" + ? i18n.str`This link is invalid or unsupported.` + : i18n.str`The wallet couldn’t open this link.`, + )} > <div class="mt-4 flex flex-wrap gap-3"> - <Button onClick={() => void capture()} disabled={working}> - {working - ? i18n.str`Retrying…` - : /* Translators: Try saving the incoming Taler link to the local action inbox again. */ i18n.str`Retry capture`} - </Button> - <Button tone="secondary" onClick={() => setError(undefined)}> + {error === "save-failed" && ( + <Button onClick={() => void capture()} disabled={working}> + {working ? i18n.str`Retrying…` : i18n.str`Try again`} + </Button> + )} + <Button + tone="secondary" + disabled={working} + onClick={() => setError(undefined)} + > {i18n.str`Dismiss`} </Button> </div> diff --git a/packages/wallet-webui/test/payment-entry.test.tsx b/packages/wallet-webui/test/payment-entry.test.tsx @@ -24,10 +24,8 @@ import { demoActionUris, } from "../src/testing/demo-wallet.js"; import type { ActionEntry } from "../src/api/contracts.js"; -import { - SessionStorageActionStore, - StoredActionInbox, -} from "../src/platform/action-inbox.js"; +import { SessionStorageActionStore } from "../src/platform/action-inbox.js"; +import { makePwaPlatform } from "../src/platform/adapters.js"; // Match the browser bundle's React alias when rendering SWR-backed routes. register( @@ -43,6 +41,7 @@ register( async function harness( source: ActionEntry["source"], mode: "normal" | "failure" | "delayed" = "normal", + uri: string = demoActionUris.payment, ) { const dom = new Window({ url: "https://wallet.example/" }); for (const key of [ @@ -79,17 +78,17 @@ async function harness( const { SWRConfig } = await import("swr"); const { App } = await import("../src/routes/App.js"); const services = createDemoServices(); - const platform = { - ...services.platform, - actionInbox: new StoredActionInbox(new SessionStorageActionStore()), - }; + const platform = makePwaPlatform(); if (source === "paste") { dom.location.hash = "#/enter"; - } else { - const entry = await platform.actionInbox.put( - demoActionUris.payment, - source, + } else if (source === "protocol") { + dom.history.replaceState( + null, + "", + `?talerUri=${encodeURIComponent(uri)}&embed=yes#/enter`, ); + } else { + const entry = await platform.actionInbox.put(uri, source); dom.location.hash = `#/action/${entry.id}`; } let prepares = 0; @@ -169,6 +168,61 @@ for (const source of ["paste", "qr", "protocol"] as const) { }); } +test("an unsupported incoming link offers dismissal and stays dismissed on reload", async () => { + const h = await harness("protocol", "normal", "taler://frobnicate/x"); + try { + await h.waitFor(() => + assert.equal( + h.view.getByRole("alert").textContent, + "This link is invalid or unsupported.", + ), + ); + assert.equal(h.view.queryByRole("button", { name: "Try again" }), null); + await h.act(() => h.view.getByRole("button", { name: "Dismiss" }).click()); + assert.equal(h.view.queryByRole("alert"), null); + assert.equal(h.dom.location.search, "?embed=yes"); + assert.equal(h.dom.location.hash, "#/enter"); + assert.deepEqual(h.counts(), { prepares: 0, confirms: 0 }); + } finally { + await h.close(); + } +}); + +test("a failed save keeps the incoming link available for an explicit retry", async (t) => { + t.mock.method( + SessionStorageActionStore.prototype, + "write", + async () => { + throw Error("storage unavailable"); + }, + { times: 1 }, + ); + const h = await harness("protocol"); + try { + await h.waitFor(() => + assert.equal( + h.view.getByRole("alert").textContent, + "The wallet couldn’t open this link.", + ), + ); + assert.equal( + new URLSearchParams(h.dom.location.search).get("talerUri"), + demoActionUris.payment, + ); + assert.equal(h.counts().prepares, 0); + await h.act(() => + h.view.getByRole("button", { name: "Try again" }).click(), + ); + await h.waitFor(() => + assert(h.view.getByRole("heading", { name: "Review payment" })), + ); + assert.equal(h.dom.location.search, "?embed=yes"); + assert.deepEqual(h.counts(), { prepares: 1, confirms: 0 }); + } finally { + await h.close(); + } +}); + test("entering a payto link opens a deposit to the pasted account", async () => { const h = await harness("paste"); try {