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

---
 .../demobank-ui/src/pages/WalletWithdrawForm.tsx   | 29 ++++++++++++++--------
 1 file changed, 18 insertions(+), 11 deletions(-)

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

diff --git a/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx b/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx
index 8bbfe0713..7f3e207ac 100644
--- a/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx
+++ b/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx
@@ -19,6 +19,7 @@ import {
   Amounts,
   HttpStatusCode,
   Logger,
+  parseWithdrawUri,
 } from "@gnu-taler/taler-util";
 import {
   RequestError,
@@ -26,7 +27,11 @@ import {
 } from "@gnu-taler/web-util/lib/index.browser";
 import { h, VNode } from "preact";
 import { useEffect, useRef, useState } from "preact/hooks";
-import { PageStateType } from "../context/pageState.js";
+import {
+  ObservedStateType,
+  PageStateType,
+  notifyError,
+} from "../context/pageState.js";
 import { useAccessAPI } from "../hooks/access.js";
 import { buildRequestErrorMessage, undefinedIfEmpty } from "../utils.js";
 import { ShowInputErrorLabel } from "./ShowInputErrorLabel.js";
@@ -36,18 +41,12 @@ const logger = new Logger("WalletWithdrawForm");
 export function WalletWithdrawForm({
   focus,
   limit,
-  onError,
   onSuccess,
 }: {
   limit: AmountJson;
   focus?: boolean;
-  onError: (e: PageStateType["error"]) => void;
-  onSuccess: (
-    data: SandboxBackend.Access.BankAccountCreateWithdrawalResponse,
-  ) => void;
+  onSuccess: (operationId: string) => void;
 }): VNode {
-  // const backend = useBackendContext();
-  // const { pageState, pageStateSetter } = usePageContext();
   const { i18n } = useTranslationContext();
   const { createWithdrawal } = useAccessAPI();
 
@@ -129,10 +128,18 @@ export function WalletWithdrawForm({
                 const result = await createWithdrawal({
                   amount: Amounts.stringify(parsedAmount),
                 });
-                onSuccess(result.data);
+                const uri = parseWithdrawUri(result.data.taler_withdraw_uri);
+                if (!uri) {
+                  return notifyError({
+                    title: i18n.str`Server responded with an invalid  withdraw URI`,
+                    description: i18n.str`Withdraw URI: ${result.data.taler_withdraw_uri}`,
+                  });
+                } else {
+                  onSuccess(uri.withdrawalOperationId);
+                }
               } catch (error) {
                 if (error instanceof RequestError) {
-                  onError(
+                  notifyError(
                     buildRequestErrorMessage(i18n, error.cause, {
                       onClientError: (status) =>
                         status === HttpStatusCode.Forbidden
@@ -141,7 +148,7 @@ export function WalletWithdrawForm({
                     }),
                   );
                 } else {
-                  onError({
+                  notifyError({
                     title: i18n.str`Operation failed, please report`,
                     description:
                       error instanceof Error
-- 
cgit v1.2.3

