From c9f61158053b83b879738a82db9d05a3ee436306 Mon Sep 17 00:00:00 2001 From: M-RB3 Date: Mon, 20 May 2024 06:10:14 +0400 Subject: [PATCH] fix donation if balance is not fetched --- src/modals/ModalDonation/AmountInput/AmountInput.tsx | 7 ++++++- src/modals/ModalDonation/FormPot/FormPot.tsx | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/modals/ModalDonation/AmountInput/AmountInput.tsx b/src/modals/ModalDonation/AmountInput/AmountInput.tsx index 8b1eba77..a93f69ba 100644 --- a/src/modals/ModalDonation/AmountInput/AmountInput.tsx +++ b/src/modals/ModalDonation/AmountInput/AmountInput.tsx @@ -17,10 +17,15 @@ const AmountInput = (props: any) => { }, onChange: ({ value }: any) => { const tokenBalance = parseFloat(getTokenBalance(value)); + updateState({ selectedDenomination: denominationOptions.find((option: any) => option.value === value), amountError: - tokenBalance > parseFloat(amount) ? "" : "You don’t have enough balance to complete this transaction.", + tokenBalance !== null + ? tokenBalance > parseFloat(amount) + ? "" + : "You don’t have enough balance to complete this transaction." + : "", }); }, containerStyles: { diff --git a/src/modals/ModalDonation/FormPot/FormPot.tsx b/src/modals/ModalDonation/FormPot/FormPot.tsx index 87be68de..8efeafdd 100644 --- a/src/modals/ModalDonation/FormPot/FormPot.tsx +++ b/src/modals/ModalDonation/FormPot/FormPot.tsx @@ -53,7 +53,7 @@ const FormPot = ({ if (amount === ".") amount = "0."; updateState({ amount, amountError: "" }); // error if amount is greater than balance - if (amount > ftBalance) { + if (amount > ftBalance && ftBalance) { updateState({ amountError: "You don’t have enough balance to complete this transaction." }); } else if (parseFloat(amount) < 0.1) { updateState({ amountError: "Minimum donation is 0.1 NEAR" }); @@ -87,6 +87,8 @@ const FormPot = ({ let totalAmount = 0; Object.values(updatedProjects).forEach((amount: any) => (totalAmount += parseFloat(amount))); + console.log("ftBalance", ftBalance); + if (totalAmount > ftBalance && ftBalance !== null) { updateState({ amountError: "You don’t have enough balance to complete this transaction." }); } else if (parseFloat(amount) < 0.1 && parseFloat(amount) !== 0) {