From c67d94c56e154be4b2cf91572cdc2d8d2da7f8e4 Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Sat, 11 Mar 2023 18:19:38 -0300
Subject: fix: #7753

---
 .../demobank-ui/src/pages/WalletWithdrawForm.tsx   | 25 +++++++++++++---------
 1 file changed, 15 insertions(+), 10 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 c1ad2f0cf..8bbfe0713 100644
--- a/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx
+++ b/packages/demobank-ui/src/pages/WalletWithdrawForm.tsx
@@ -14,7 +14,12 @@
  GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 
-import { Amounts, HttpStatusCode, Logger } from "@gnu-taler/taler-util";
+import {
+  AmountJson,
+  Amounts,
+  HttpStatusCode,
+  Logger,
+} from "@gnu-taler/taler-util";
 import {
   RequestError,
   useTranslationContext,
@@ -30,11 +35,11 @@ const logger = new Logger("WalletWithdrawForm");
 
 export function WalletWithdrawForm({
   focus,
-  currency,
+  limit,
   onError,
   onSuccess,
 }: {
-  currency: string;
+  limit: AmountJson;
   focus?: boolean;
   onError: (e: PageStateType["error"]) => void;
   onSuccess: (
@@ -52,20 +57,20 @@ export function WalletWithdrawForm({
     if (focus) ref.current?.focus();
   }, [focus]);
 
-  // Beware: We never ever want to treat the amount as a float!
-
   const trimmedAmountStr = amountStr?.trim();
 
   const parsedAmount = trimmedAmountStr
-    ? Amounts.parse(`${currency}:${trimmedAmountStr}`)
+    ? Amounts.parse(`${limit.currency}:${trimmedAmountStr}`)
     : undefined;
 
   const errors = undefinedIfEmpty({
     amount:
       trimmedAmountStr == null
         ? i18n.str`required`
-        : parsedAmount == null
+        : !parsedAmount
         ? i18n.str`invalid`
+        : Amounts.cmp(limit, parsedAmount) === -1
+        ? i18n.str`balance is not enough`
         : undefined,
   });
   return (
@@ -87,10 +92,10 @@ export function WalletWithdrawForm({
             type="text"
             readonly
             class="currency-indicator"
-            size={currency.length}
-            maxLength={currency.length}
+            size={limit.currency.length}
+            maxLength={limit.currency.length}
             tabIndex={-1}
-            value={currency}
+            value={limit.currency}
           />
           &nbsp;
           <input
-- 
cgit v1.2.3

