From f8ac04bd80a3cac41de606387f90e24ea8e49df8 Mon Sep 17 00:00:00 2001 From: Alduin Date: Mon, 30 Sep 2024 10:09:06 -0300 Subject: [PATCH] Fix precision of shares field --- .../components/MarketBetting/SharesAmountField/index.tsx | 8 +++++--- frontend/src/utils/coins.ts | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/src/features/MarketDetail/components/MarketBetting/SharesAmountField/index.tsx b/frontend/src/features/MarketDetail/components/MarketBetting/SharesAmountField/index.tsx index 26b17b4..640b046 100644 --- a/frontend/src/features/MarketDetail/components/MarketBetting/SharesAmountField/index.tsx +++ b/frontend/src/features/MarketDetail/components/MarketBetting/SharesAmountField/index.tsx @@ -86,10 +86,12 @@ const SharesAmountField = (props: SharesAmountFieldProps) => { */ const onChange = useCallback( (newAmount: string) => { - const regex = VALID_DECIMAL_REGEX(3) + if (balance) { + const regex = VALID_DECIMAL_REGEX(balance?.maxDecimalPlaces) - if (balance && matchesRegex(newAmount, regex)) { - setFormValue(newAmount === "." ? "0." : newAmount) + if (matchesRegex(newAmount, regex)) { + setFormValue(newAmount === "." ? "0." : newAmount) + } } }, [balance, setFormValue], diff --git a/frontend/src/utils/coins.ts b/frontend/src/utils/coins.ts index 4c3b5b1..acae0de 100644 --- a/frontend/src/utils/coins.ts +++ b/frontend/src/utils/coins.ts @@ -210,7 +210,7 @@ abstract class Asset { } toFullPrecision(withSuffix: boolean): string { - return `${this.getValue().toFormat(this.exponent)}${withSuffix ? ` ${this.symbol}` : ""}` + return `${this.getValue().toFormat(this.maxDecimalPlaces)}${withSuffix ? ` ${this.symbol}` : ""}` } getValue(): BigNumber {