From bfa66d58564e88c385b19a6fd99a1cf54c2ddee6 Mon Sep 17 00:00:00 2001 From: David Westgate Date: Sun, 9 Mar 2025 14:59:08 -0700 Subject: [PATCH] limit ranges for buy in selector --- components/BuyInSelector.tsx | 13 +++++++++++-- components/ChipDistributionSummary.tsx | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/components/BuyInSelector.tsx b/components/BuyInSelector.tsx index e6fe07b..a280820 100644 --- a/components/BuyInSelector.tsx +++ b/components/BuyInSelector.tsx @@ -10,6 +10,14 @@ interface BuyInSelectorProps { } const defaultBuyInOptions = [10, 25, 50]; +const MIN = 1; +const MAX = 200; + +const parseRoundClamp = (num: string): number => { + const parsed = parseFloat(num); + const rounded = Math.round(parsed); + return Math.min(Math.max(rounded, MIN), MAX); +}; const BuyInSelector: React.FC = ({ setBuyInAmount, @@ -19,9 +27,9 @@ const BuyInSelector: React.FC = ({ const [buyInAmount, setBuyInAmountState] = useState(null); const handleCustomAmountChange = (value: string) => { - const numericValue = parseFloat(value); + const numericValue = parseRoundClamp(value); if (!isNaN(numericValue) && numericValue >= 0) { - setCustomAmount(value); + setCustomAmount(numericValue.toString()); setBuyInAmountState(numericValue); setBuyInAmount(numericValue); } else { @@ -55,6 +63,7 @@ const BuyInSelector: React.FC = ({ - {i18n.t("total_value")}: {selectedCurrency} {totalValue} + {i18n.t("total_value")}: {selectedCurrency} {totalValue.toFixed(2)} {selectedCurrency} {potValue} {i18n.t("pot")}