From a3aa7d95d09c83794067c47df4a455c0e3f21806 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 7 Apr 2023 17:30:01 -0300 Subject: anon withdrawal confirmation, and fix error with infinity loop --- .../demobank-ui/src/pages/WithdrawalQRCode.tsx | 75 +++++++++++++--------- 1 file changed, 44 insertions(+), 31 deletions(-) (limited to 'packages/demobank-ui/src/pages/WithdrawalQRCode.tsx') diff --git a/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx b/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx index 1a4157d06..9c5f83eca 100644 --- a/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx +++ b/packages/demobank-ui/src/pages/WithdrawalQRCode.tsx @@ -14,30 +14,35 @@ GNU Taler; see the file COPYING. If not, see */ -import { Logger, parseWithdrawUri } from "@gnu-taler/taler-util"; import { + HttpStatusCode, + Logger, + WithdrawUriResult, +} from "@gnu-taler/taler-util"; +import { + ErrorType, HttpResponsePaginated, useTranslationContext, } from "@gnu-taler/web-util/lib/index.browser"; import { Fragment, h, VNode } from "preact"; import { Loading } from "../components/Loading.js"; -import { PageStateType } from "../context/pageState.js"; +import { + ObservedStateType, + notifyError, + notifyInfo, +} from "../context/pageState.js"; import { useWithdrawalDetails } from "../hooks/access.js"; import { QrCodeSection } from "./QrCodeSection.js"; import { WithdrawalConfirmationQuestion } from "./WithdrawalConfirmationQuestion.js"; +import { handleNotOkResult } from "./HomePage.js"; const logger = new Logger("WithdrawalQRCode"); interface Props { - account: string; - withdrawalId: string; - talerWithdrawUri: string; - onError: (e: PageStateType["error"]) => void; + withdrawUri: WithdrawUriResult; onAborted: () => void; onConfirmed: () => void; - onLoadNotOk: ( - error: HttpResponsePaginated, - ) => VNode; + onLoadNotOk: () => void; } /** * Offer the QR code (and a clickable taler://-link) to @@ -45,43 +50,46 @@ interface Props { * the bank. Poll the backend until such operation is done. */ export function WithdrawalQRCode({ - account, - withdrawalId, - talerWithdrawUri, + withdrawUri, onConfirmed, onAborted, - onError, onLoadNotOk, }: Props): VNode { const { i18n } = useTranslationContext(); - - const result = useWithdrawalDetails(account, withdrawalId); + const result = useWithdrawalDetails(withdrawUri.withdrawalOperationId); if (!result.ok) { - return onLoadNotOk(result); + if (result.loading) { + return ; + } + if ( + result.type === ErrorType.CLIENT && + result.status === HttpStatusCode.NotFound + ) { + return
operation not found
; + } + console.log("result", result); + onLoadNotOk(); + return handleNotOkResult(i18n)(result); } const { data } = result; logger.trace("withdrawal status", data); - if (data.aborted) { + if (data.aborted || data.confirmation_done) { // signal that this withdrawal is aborted // will redirect to account info + notifyInfo(i18n.str`Operation was completed from other session`); onAborted(); return ; } - const parsedUri = parseWithdrawUri(talerWithdrawUri); - if (!parsedUri) { - onError({ - title: i18n.str`The Withdrawal URI is not valid: "${talerWithdrawUri}"`, - }); - return ; - } - if (!data.selection_done) { return ( { + notifyInfo(i18n.str`Operation canceled`); + onAborted(); + }} /> ); } @@ -90,10 +98,15 @@ export function WithdrawalQRCode({ // user to authorize the operation (here CAPTCHA). return ( { + notifyInfo(i18n.str`Operation confirmed`); + onConfirmed(); + }} + onAborted={() => { + notifyInfo(i18n.str`Operation canceled`); + onAborted(); + }} /> ); } -- cgit v1.2.3