taler-typescript-core

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

commit 70c5a639cad5f2ed86c8b557e1cd02eb99410f29
parent 7050b9f18e1d3569f5e8f8b39b09ada9b1296907
Author: Florian Dold <dold@taler.net>
Date:   Thu, 26 Nov 2026 16:59:39 +0100

wallet-webui: confirm peer transfers and invoices from history

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

Diffstat:
Mpackages/wallet-webui/src/routes/App.tsx | 202+++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
Mpackages/wallet-webui/src/screens/PeerReceiveScreen.tsx | 134+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Mpackages/wallet-webui/src/screens/TransactionDetailScreen.tsx | 27++++++++++++++++++++++++++-
Mpackages/wallet-webui/test/peer-credit-observation.test.tsx | 223++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 469 insertions(+), 117 deletions(-)

diff --git a/packages/wallet-webui/src/routes/App.tsx b/packages/wallet-webui/src/routes/App.tsx @@ -34,8 +34,14 @@ import type { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import type { ComponentChildren } from "preact"; -import { useCallback, useEffect, useMemo, useState } from "preact/hooks"; -import { useRef } from "preact/hooks"; +import { + useCallback, + useEffect, + useLayoutEffect, + useMemo, + useRef, + useState, +} from "preact/hooks"; import jsQR, * as jsQrTypes from "jsqr"; import { Redirect, @@ -91,7 +97,10 @@ import type { PeerExpirationChoice, PeerExpirationPreviewRequest, } from "../screens/PeerCreateScreen.js"; -import { PeerReceiveScreen } from "../screens/PeerReceiveScreen.js"; +import { + PeerReceiveScreen, + type PeerConfirmationControlsProps, +} from "../screens/PeerReceiveScreen.js"; import { PeerShareScreen } from "../screens/PeerShareScreen.js"; import { PaymentTemplateScreen, @@ -2782,30 +2791,81 @@ interface PeerReviewActions { } function usePeerPaymentConfirmation( - actionId: string, - request: () => Promise<Result<{ transactionId: TransactionIdStr }, unknown>>, + view: TransactionObservationView, + transactionId: TransactionIdStr, + kind: "receive" | "pay", + actionId?: string, + cancelling = false, ) { - const { platform } = useServices(); + const { connection, platform } = useServices(); const [, navigate] = useLocation(); const durability = useDurability(); + const { controller: progressRequest } = useWalletProgress(connection); + const callMutation = useWalletMutation(connection); const [working, setWorking] = useState(false); const [error, setError] = useState<ErrorPresentation>(); + const expectedType = + kind === "receive" + ? TransactionType.PeerPushCredit + : TransactionType.PeerPullDebit; + const snapshot = + view.snapshot?.type === expectedType ? view.snapshot : undefined; + const eligibility = peerCreditConfirmationView( + view.state, + actionId ? `/peer-receive/${actionId}` : `/transaction/${transactionId}`, + error, + ); + const proposed = + snapshot?.transaction.txState.major === TransactionMajorState.Dialog && + snapshot.transaction.txState.minor === TransactionMinorState.Proposed; + const canConfirm = + proposed && + eligibility.enabled && + !cancelling && + snapshot.transaction.transactionId === transactionId; + const eligible = useRef(false); + const busy = useRef(false); + useLayoutEffect(() => { + eligible.current = canConfirm; + return () => { + eligible.current = false; + }; + }, [canConfirm]); const confirm = async () => { - if (working || !(await durability.guardValueOperation())) return; + if (busy.current || !eligible.current) return; + busy.current = true; setWorking(true); setError(undefined); + let accepted = false; try { - const result = await request(); - if (Result.isError(result)) + if (!(await durability.guardValueOperation()) || !eligible.current) + return; + const result = + kind === "receive" + ? await progressRequest.callAndInvalidate( + WalletApiOperation.ConfirmPeerPushCredit, + { transactionId }, + ["balances", "transactions"], + ) + : await callMutation( + WalletApiOperation.ConfirmPeerPullDebit, + { transactionId }, + ["balances", "transactions"], + ); + if (Result.isError(result)) { setError( walletErrorHint( result.detail, /* Translators: Peer payments transfer digital cash between people using links. A shared link can offer money to receive or request money to be paid. */ i18n.str`The wallet could not confirm this peer payment.`, ), ); - else { - navigate(`/transaction/${result.value.transactionId}`); - void completeActionBestEffort(platform.actionInbox, actionId); + } else { + // Acknowledgement may arrive before the snapshot removes the proposal. + accepted = true; + if (actionId) { + navigate(`/transaction/${result.value.transactionId}`); + void completeActionBestEffort(platform.actionInbox, actionId); + } } } catch (cause) { if (!isProgressRequestCancelled(cause)) @@ -2813,10 +2873,24 @@ function usePeerPaymentConfirmation( errorFromException(cause, i18n.str`Peer payment confirmation failed`), ); } finally { - setWorking(false); + if (!accepted) { + busy.current = false; + setWorking(false); + } } }; - return { working, error, confirm }; + const recovery = eligibility.enabled ? undefined : eligibility.recovery; + const controls: PeerConfirmationControlsProps = { + kind, + working, + confirmDisabled: !canConfirm, + blockedReason: + eligibility.enabled || view.loading ? undefined : eligibility.reason, + blockedActionLabel: recovery?.label, + onResolveBlock: recovery ? () => navigate(recovery.href) : undefined, + onConfirm: confirm, + }; + return { controls, error, snapshot, proposed }; } function peerExpirationLabel( @@ -2835,44 +2909,20 @@ function PeerPaymentReview(props: PeerReviewActions & PreparedPeerPayment) { const { connection } = useServices(); const { language } = useLanguage(); const [, navigate] = useLocation(); - const { controller: progressRequest } = useWalletProgress(connection); - const callMutation = useWalletMutation(connection); const view = useTransactionObservation(connection, props.transactionId); - const expectedType = - props.kind === "receive" - ? TransactionType.PeerPushCredit - : TransactionType.PeerPullDebit; - const snapshot = - view.snapshot?.type === expectedType ? view.snapshot : undefined; - const unexpectedType = view.snapshot && !snapshot; - const { working, error, confirm } = usePeerPaymentConfirmation( + const { controls, error, snapshot } = usePeerPaymentConfirmation( + view, + props.transactionId, + props.kind, props.actionId, - () => - props.kind === "receive" - ? progressRequest.callAndInvalidate( - WalletApiOperation.ConfirmPeerPushCredit, - { transactionId: props.transactionId }, - ["balances", "transactions"], - ) - : callMutation( - WalletApiOperation.ConfirmPeerPullDebit, - { transactionId: props.transactionId }, - ["balances", "transactions"], - ), - ); - const confirmation = peerCreditConfirmationView( - view.state, - `/peer-receive/${props.actionId}`, - error, + props.cancelling, ); - const canConfirm = !!snapshot && confirmation.enabled; + const unexpectedType = view.snapshot && !snapshot; return ( <PeerReceiveScreen - kind={props.kind} + {...controls} loading={view.loading} - working={working} cancelling={props.cancelling} - confirmDisabled={!canConfirm} error={ props.cancellationError ?? error ?? @@ -2886,19 +2936,6 @@ function PeerPaymentReview(props: PeerReviewActions & PreparedPeerPayment) { : undefined) } onRetryObservation={view.canRetry ? view.retry : undefined} - blockedReason={ - confirmation.enabled || view.loading ? undefined : confirmation.reason - } - blockedActionLabel={ - confirmation.enabled ? undefined : confirmation.recovery?.label - } - onResolveBlock={ - !confirmation.enabled && confirmation.recovery - ? () => { - window.location.hash = confirmation.recovery!.href; - } - : undefined - } amountRaw={snapshot?.transaction.amountRaw} amountEffective={snapshot?.transaction.amountEffective} summary={snapshot?.transaction.info.summary} @@ -2907,9 +2944,6 @@ function PeerPaymentReview(props: PeerReviewActions & PreparedPeerPayment) { snapshot?.transaction.info.expiration, language, )} - onConfirm={() => { - if (canConfirm && !props.cancelling) void confirm(); - }} onCancel={props.onCancel} onWithdraw={() => navigate("/withdraw")} /> @@ -5272,6 +5306,22 @@ function ObservedTransactionDetailRoute({ }) { const { connection } = useServices(); const view = useTransactionObservation(connection, transactionId); + if ( + view.snapshot?.type === TransactionType.PeerPushCredit || + view.snapshot?.type === TransactionType.PeerPullDebit + ) { + return ( + <PeerTransactionDetail + transactionId={transactionId} + view={view} + kind={ + view.snapshot.type === TransactionType.PeerPushCredit + ? "receive" + : "pay" + } + /> + ); + } return ( <TransactionDetailView transactionId={transactionId} @@ -5281,14 +5331,42 @@ function ObservedTransactionDetailRoute({ ); } +function PeerTransactionDetail({ + view, + transactionId, + kind, +}: { + view: TransactionObservationView; + transactionId: TransactionIdStr; + kind: "receive" | "pay"; +}) { + const { controls, error, proposed } = usePeerPaymentConfirmation( + view, + transactionId, + kind, + ); + return ( + <TransactionDetailView + view={view} + transactionId={transactionId} + peerConfirmation={proposed ? controls : undefined} + peerError={proposed ? error : undefined} + /> + ); +} + function TransactionDetailView({ transactionId, view, showTransferInstructions = false, + peerConfirmation, + peerError, }: { transactionId: TransactionIdStr; view: TransactionObservationView; showTransferInstructions?: boolean; + peerConfirmation?: PeerConfirmationControlsProps; + peerError?: ErrorPresentation; }) { const { connection, platform } = useServices(); const { language } = useLanguage(); @@ -5384,6 +5462,7 @@ function TransactionDetailView({ <TransactionDetailScreen transaction={transaction} loading={view.loading} + peerConfirmation={peerConfirmation} contractLoading={contract.loading} contractError={ contract.error @@ -5399,6 +5478,7 @@ function TransactionDetailView({ onRetryObservation={view.canRetry ? view.retry : undefined} error={ error ?? + peerError ?? (view.state.status === "deleted" ? localError(i18n.str`This transaction no longer exists.`) : view.error diff --git a/packages/wallet-webui/src/screens/PeerReceiveScreen.tsx b/packages/wallet-webui/src/screens/PeerReceiveScreen.tsx @@ -5,27 +5,85 @@ import { ErrorCard } from "../ui/ErrorCard.js"; import type { ErrorPresentation } from "../ui/error.js"; import { i18n } from "../i18n/runtime.js"; -export function PeerReceiveScreen(props: { +export interface PeerConfirmationControlsProps { kind: "receive" | "pay"; - loading: boolean; working: boolean; - cancelling?: boolean; - amountRaw?: string; - amountEffective?: string; - summary?: string; - expiration?: string; - exchange?: string; - error?: ErrorPresentation; - onRetryObservation?: () => void; - onRetryPreparation?: () => void; confirmDisabled?: boolean; blockedReason?: string; blockedActionLabel?: string; onConfirm: () => void; onResolveBlock?: () => void; - onCancel: () => void; - onWithdraw: () => void; -}) { +} + +export function PeerConfirmationControls( + props: PeerConfirmationControlsProps & { + showButtons: boolean; + cancelling?: boolean; + onCancel?: () => void; + }, +) { + return ( + <> + {props.blockedReason && ( + <Card class="border-warning bg-warningContainer"> + <p role="alert" class="text-onWarningContainer"> + {props.blockedReason} + </p> + {props.onResolveBlock && ( + <div class="mt-4"> + <Button tone="secondary" onClick={props.onResolveBlock}> + {props.blockedActionLabel ?? + i18n.str`Resolve exchange requirement`} + </Button> + </div> + )} + </Card> + )} + {props.showButtons && ( + <div class="flex justify-end gap-3"> + {props.onCancel && ( + <Button + tone="secondary" + onClick={props.onCancel} + disabled={props.cancelling || props.working} + > + {props.cancelling ? i18n.str`Cancelling…` : i18n.str`Cancel`} + </Button> + )} + <Button + onClick={props.onConfirm} + disabled={ + props.working || props.cancelling || props.confirmDisabled + } + > + {props.working + ? i18n.str`Confirming…` + : props.kind === "receive" + ? i18n.str`Receive money` + : i18n.str`Pay`} + </Button> + </div> + )} + </> + ); +} + +export function PeerReceiveScreen( + props: PeerConfirmationControlsProps & { + loading: boolean; + cancelling?: boolean; + amountRaw?: string; + amountEffective?: string; + summary?: string; + expiration?: string; + exchange?: string; + error?: ErrorPresentation; + onRetryObservation?: () => void; + onRetryPreparation?: () => void; + onCancel: () => void; + onWithdraw: () => void; + }, +) { const receive = props.kind === "receive"; const insufficientFunds = props.error?.detail?.code === @@ -36,7 +94,7 @@ export function PeerReceiveScreen(props: { <button type="button" onClick={props.onCancel} - disabled={props.cancelling} + disabled={props.cancelling || props.working} aria-label={ /* Translators: Cancel accepting a peer transfer or paying a peer request in this wallet. */ i18n.str`Cancel peer payment` } @@ -84,21 +142,6 @@ export function PeerReceiveScreen(props: { )} </ErrorCard> )} - {props.blockedReason && ( - <Card class="border-warning bg-warningContainer"> - <p role="alert" class="text-onWarningContainer"> - {props.blockedReason} - </p> - {props.onResolveBlock && ( - <div class="mt-4"> - <Button tone="secondary" onClick={props.onResolveBlock}> - {props.blockedActionLabel ?? - i18n.str`Resolve exchange requirement`} - </Button> - </div> - )} - </Card> - )} {!props.loading && props.amountEffective && ( <> <Card class="text-center"> @@ -133,32 +176,15 @@ export function PeerReceiveScreen(props: { )} </dl> </Card> - <div class="flex justify-end gap-3"> - <Button - tone="secondary" - onClick={props.onCancel} - disabled={props.cancelling} - > - {props.cancelling ? i18n.str`Cancelling…` : i18n.str`Cancel`} - </Button> - <Button - onClick={props.onConfirm} - disabled={ - props.working || - props.cancelling || - (props.confirmDisabled ?? - (Boolean(props.error) || Boolean(props.blockedReason))) - } - > - {props.working - ? i18n.str`Confirming…` - : receive - ? i18n.str`Receive money` - : i18n.str`Pay`} - </Button> - </div> </> )} + <PeerConfirmationControls + {...props} + showButtons={!props.loading && !!props.amountEffective} + confirmDisabled={ + props.confirmDisabled ?? (!!props.error || !!props.blockedReason) + } + /> </div> ); } diff --git a/packages/wallet-webui/src/screens/TransactionDetailScreen.tsx b/packages/wallet-webui/src/screens/TransactionDetailScreen.tsx @@ -1,3 +1,8 @@ +import { TalerErrorCode } from "@gnu-taler/taler-util"; +import { + PeerConfirmationControls, + type PeerConfirmationControlsProps, +} from "./PeerReceiveScreen.js"; import { useEffect, useState } from "preact/hooks"; import type { TransactionActionView, @@ -60,6 +65,7 @@ export function TransactionDetailScreen(props: { onAction: (action: TransactionUiAction) => void; onOpenExternal: (url: string) => void; onContinue?: () => void; + peerConfirmation?: PeerConfirmationControlsProps; paymentReview?: TransactionPaymentReview; onSelectPaymentChoice?: (index: number) => void; onConfirmPayment?: (useDonau?: boolean) => void; @@ -200,6 +206,15 @@ export function TransactionDetailScreen(props: { </div> </div> </Card> + {props.peerConfirmation && ( + <PeerConfirmationControls + {...props.peerConfirmation} + showButtons + confirmDisabled={ + props.peerConfirmation.confirmDisabled || !!props.workingAction + } + /> + )} {transaction.error && ( <ErrorCard title={i18n.str`Wallet reported a problem`} @@ -216,6 +231,14 @@ export function TransactionDetailScreen(props: { )} {props.error && ( <ErrorCard error={props.error}> + {props.peerConfirmation?.kind === "pay" && + props.error.detail?.code === + TalerErrorCode.WALLET_PEER_PULL_PAYMENT_INSUFFICIENT_BALANCE && ( + <Button + tone="secondary" + onClick={props.onWithdraw} + >{i18n.str`Withdraw funds`}</Button> + )} {props.onRetryObservation && ( <Button onClick={props.onRetryObservation} @@ -412,7 +435,9 @@ export function TransactionDetailScreen(props: { ? "primary" : "secondary" } - disabled={Boolean(props.workingAction)} + disabled={ + Boolean(props.workingAction) || props.peerConfirmation?.working + } onClick={() => perform(action)} > {props.workingAction === action.id diff --git a/packages/wallet-webui/test/peer-credit-observation.test.tsx b/packages/wallet-webui/test/peer-credit-observation.test.tsx @@ -61,6 +61,7 @@ async function harness( | "pull" | "bank" = "normal", pullBlocker?: TransactionConfirmationUnavailableReason, + withStoragePrompt = false, ) { const dom = new Window({ url: "https://wallet.example/" }); for (const key of [ @@ -194,6 +195,22 @@ async function harness( services.connection.client.call = async (operation, request) => { calls.push(operation); if ( + operation === WalletApiOperation.GetExchangeTos && + pullBlocker === "exchange-tos-not-accepted" + ) { + const terms = await originalCall( + WalletApiOperation.GetExchangeTos, + request as { exchangeBaseUrl: string }, + ); + return { ...terms, tosStatus: ExchangeTosStatus.Proposed } as never; + } + if ( + operation === WalletApiOperation.GetTransactionsV2 && + latest?.snapshot?.type === TransactionType.PeerPullDebit + ) { + return { transactions: [latest.snapshot.transaction] } as never; + } + if ( mode === "pull" && operation === WalletApiOperation.ObserveTransaction ) { @@ -249,6 +266,8 @@ async function harness( const original = services.connection.client.callForResult; services.connection.client.callForResult = async (operation, request) => { mutations.push(operation); + if (operation === WalletApiOperation.SetExchangeTosAccepted) + pullBlocker = undefined; if ( mode === "pull" && operation === WalletApiOperation.PreparePeerPullDebit @@ -283,7 +302,7 @@ async function harness( }; const view = render( <SWRConfig value={{ provider: () => new Map(), shouldRetryOnError: false }}> - <App {...services} /> + <App {...services} demo={withStoragePrompt ? undefined : services.demo} /> </SWRConfig>, ); const waitFor = async (check: () => void) => { @@ -312,6 +331,32 @@ async function harness( holdSnapshots = false; for (const send of pendingSnapshots.splice(0)) send(); }, + updatePeerState: ( + major: TransactionMajorState, + reasons: TransactionConfirmationUnavailableReason[], + ) => { + const snapshot = latest?.snapshot; + assert.ok(latest && snapshot?.type === TransactionType.PeerPullDebit); + latest = { + ...latest, + revision: latest.revision + 1, + snapshot: { + ...snapshot, + transaction: { + ...snapshot.transaction, + txState: { + major, + minor: + major === TransactionMajorState.Dialog + ? TransactionMinorState.Proposed + : undefined, + }, + }, + confirmation: { unavailableReasons: reasons }, + }, + }; + for (const listener of listeners) listener(latest); + }, failObserved: () => { assert.ok(latest); for (const listener of listeners) @@ -819,3 +864,179 @@ for (const mode of ["normal", "pull"] as const) { } }); } + +async function reopenPeerFromHistory( + h: Awaited<ReturnType<typeof harness>>, + summary: string, +) { + await h.waitFor(() => assert(h.view.getByText(summary))); + await h.services.platform.actionInbox.complete(h.entry.id); + await h.act(() => { + h.dom.location.hash = "#/transactions"; + }); + const row = () => h.view.getByRole("button", { name: new RegExp(summary) }); + await h.waitFor(() => assert.ok(row())); + const id = row().id.slice("history-".length); + await h.act(() => row().click()); + await h.waitFor(() => + assert.ok(h.view.getByRole("heading", { name: "Transaction details" })), + ); + assert.equal(h.dom.location.hash, "#/transaction/" + id); + return id; +} + +for (const mode of ["normal", "pull"] as const) { + test(`History can confirm a saved ${mode === "pull" ? "invoice" : "incoming transfer"} after its link is gone`, async () => { + const h = await harness("paste", mode); + try { + const pull = mode === "pull"; + const summary = pull ? "Observed invoice" : "Shared lunch"; + const button = () => + h.view.getByRole("button", { + name: pull ? "Pay" : "Receive money", + exact: true, + }); + const id = await reopenPeerFromHistory(h, summary); + assert.equal( + await h.services.platform.actionInbox.get(h.entry.id), + undefined, + ); + assert.ok(h.view.getByText(pull ? "CHF:3.1" : "+CHF:7.00")); + await h.act(() => + h.view.getByRole("button", { name: "Back to history" }).click(), + ); + await h.waitFor(() => + assert.ok(h.view.getByRole("button", { name: new RegExp(summary) })), + ); + assert.equal(h.counts().confirms, 0); + await h.act(() => + h.view.getByRole("button", { name: new RegExp(summary) }).click(), + ); + await h.waitFor(() => assert.ok(button())); + const original = h.services.connection.client.callForResult; + const confirmOp = pull + ? WalletApiOperation.ConfirmPeerPullDebit + : WalletApiOperation.ConfirmPeerPushCredit; + let attempts = 0; + h.services.connection.client.callForResult = async (operation, args) => { + if (operation === confirmOp) { + assert.equal((args as { transactionId: string }).transactionId, id); + if (++attempts === 1) throw Error("temporarily unavailable"); + } + return original(operation, args); + }; + await h.act(() => button().click()); + await h.waitFor(() => + assert.ok(h.view.getByText("Peer payment confirmation failed")), + ); + await h.act(() => { + const confirm = button(); + confirm.click(); + confirm.click(); + }); + await h.waitFor(() => assert.equal(h.counts().confirms, 1)); + if (pull) { + await h.waitFor(() => + assert.equal( + ( + h.view.getByRole("button", { + name: "Confirming…", + }) as HTMLButtonElement + ).disabled, + true, + ), + ); + await h.act(() => + h.updatePeerState(TransactionMajorState.Done, ["not-proposed"]), + ); + } + await h.waitFor(() => assert.ok(h.view.getAllByText("Completed").length)); + assert.equal( + h.view.queryByRole("button", { + name: pull ? "Pay" : "Receive money", + exact: true, + }), + null, + ); + assert.equal(attempts, 2); + assert.equal(h.counts().prepares, 1); + assert.equal(h.dom.location.hash, "#/transaction/" + id); + } finally { + await h.close(); + } + }); +} + +test("History rechecks peer eligibility when the storage prompt closes", async () => { + const h = await harness("paste", "pull", undefined, true); + try { + await reopenPeerFromHistory(h, "Observed invoice"); + await h.act(() => + h.view.getByRole("button", { name: "Pay", exact: true }).click(), + ); + const approve = () => + h.view.getByRole("button", { name: "Continue without protection" }); + await h.waitFor(() => assert.ok(approve())); + await h.act(() => + h.updatePeerState(TransactionMajorState.Dialog, ["expired"]), + ); + await h.act(() => approve().click()); + await h.waitFor(() => + assert.equal( + ( + h.view.getByRole("button", { + name: "Pay", + exact: true, + }) as HTMLButtonElement + ).disabled, + true, + ), + ); + assert.ok(h.view.getByText("This peer payment has expired.")); + assert.equal(h.counts().confirms, 0); + } finally { + await h.close(); + } +}); + +test("History returns to the saved invoice after exchange recovery", async () => { + const h = await harness("paste", "pull", "exchange-tos-not-accepted"); + try { + const id = await reopenPeerFromHistory(h, "Observed invoice"); + assert.equal( + ( + h.view.getByRole("button", { + name: "Pay", + exact: true, + }) as HTMLButtonElement + ).disabled, + true, + ); + await h.act(() => + h.view.getByRole("button", { name: "Review terms" }).click(), + ); + await h.waitFor(() => assert.match(h.dom.location.hash, /#\/exchange\//)); + const returnTo = new URLSearchParams(h.dom.location.hash.split("?")[1]).get( + "returnTo", + ); + assert.equal(returnTo, "/transaction/" + id); + const accept = () => h.view.getByRole("button", { name: "Accept terms" }); + await h.waitFor(() => assert.ok(accept())); + await h.act(() => accept().click()); + await h.waitFor(() => assert.equal(h.dom.location.hash, "#" + returnTo)); + await h.waitFor(() => + assert.equal( + ( + h.view.getByRole("button", { + name: "Pay", + exact: true, + }) as HTMLButtonElement + ).disabled, + false, + ), + ); + assert.equal(h.counts().prepares, 1); + } finally { + await h.close(); + } +});