From a3aa7d95d09c83794067c47df4a455c0e3f21806 Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Fri, 7 Apr 2023 17:30:01 -0300
Subject: anon withdrawal confirmation, and fix error with infinity loop

---
 .../src/pages/WithdrawalConfirmationQuestion.tsx   | 36 +++++++++++++---------
 1 file changed, 22 insertions(+), 14 deletions(-)

(limited to 'packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx')

diff --git a/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx b/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx
index d7ed215be..10a37cd88 100644
--- a/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx
+++ b/packages/demobank-ui/src/pages/WithdrawalConfirmationQuestion.tsx
@@ -14,35 +14,41 @@
  GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 
-import { HttpStatusCode, Logger } from "@gnu-taler/taler-util";
+import {
+  HttpStatusCode,
+  Logger,
+  WithdrawUriResult,
+} from "@gnu-taler/taler-util";
 import {
   RequestError,
   useTranslationContext,
 } from "@gnu-taler/web-util/lib/index.browser";
 import { Fragment, h, VNode } from "preact";
 import { useMemo, useState } from "preact/hooks";
-import { PageStateType, usePageContext } from "../context/pageState.js";
-import { useAccessAPI } from "../hooks/access.js";
+import {
+  ObservedStateType,
+  PageStateType,
+  notifyError,
+} from "../context/pageState.js";
+import { useAccessAnonAPI } from "../hooks/access.js";
 import { buildRequestErrorMessage, undefinedIfEmpty } from "../utils.js";
 import { ShowInputErrorLabel } from "./ShowInputErrorLabel.js";
 
 const logger = new Logger("WithdrawalConfirmationQuestion");
 
 interface Props {
-  withdrawalId: string;
-  onError: (e: PageStateType["error"]) => void;
   onConfirmed: () => void;
   onAborted: () => void;
+  withdrawUri: WithdrawUriResult;
 }
 /**
  * Additional authentication required to complete the operation.
  * Not providing a back button, only abort.
  */
 export function WithdrawalConfirmationQuestion({
-  onError,
   onConfirmed,
   onAborted,
-  withdrawalId,
+  withdrawUri,
 }: Props): VNode {
   const { i18n } = useTranslationContext();
 
@@ -53,7 +59,7 @@ export function WithdrawalConfirmationQuestion({
     };
   }, []);
 
-  const { confirmWithdrawal, abortWithdrawal } = useAccessAPI();
+  const { confirmWithdrawal, abortWithdrawal } = useAccessAnonAPI();
   const [captchaAnswer, setCaptchaAnswer] = useState<string | undefined>();
   const answer = parseInt(captchaAnswer ?? "", 10);
   const errors = undefinedIfEmpty({
@@ -114,11 +120,13 @@ export function WithdrawalConfirmationQuestion({
                   onClick={async (e) => {
                     e.preventDefault();
                     try {
-                      await confirmWithdrawal(withdrawalId);
+                      await confirmWithdrawal(
+                        withdrawUri.withdrawalOperationId,
+                      );
                       onConfirmed();
                     } catch (error) {
                       if (error instanceof RequestError) {
-                        onError(
+                        notifyError(
                           buildRequestErrorMessage(i18n, error.cause, {
                             onClientError: (status) =>
                               status === HttpStatusCode.Conflict
@@ -129,7 +137,7 @@ export function WithdrawalConfirmationQuestion({
                           }),
                         );
                       } else {
-                        onError({
+                        notifyError({
                           title: i18n.str`Operation failed, please report`,
                           description:
                             error instanceof Error
@@ -148,11 +156,11 @@ export function WithdrawalConfirmationQuestion({
                   onClick={async (e) => {
                     e.preventDefault();
                     try {
-                      await abortWithdrawal(withdrawalId);
+                      await abortWithdrawal(withdrawUri.withdrawalOperationId);
                       onAborted();
                     } catch (error) {
                       if (error instanceof RequestError) {
-                        onError(
+                        notifyError(
                           buildRequestErrorMessage(i18n, error.cause, {
                             onClientError: (status) =>
                               status === HttpStatusCode.Conflict
@@ -161,7 +169,7 @@ export function WithdrawalConfirmationQuestion({
                           }),
                         );
                       } else {
-                        onError({
+                        notifyError({
                           title: i18n.str`Operation failed, please report`,
                           description:
                             error instanceof Error
-- 
cgit v1.2.3

