From 4cf142d52a7f86a24aa9c5e594327915c0bc2794 Mon Sep 17 00:00:00 2001
From: garageinc <9-b-rinat@rambler.ru>
Date: Thu, 7 Nov 2024 17:23:08 +0300
Subject: [PATCH] fix: force rounding input numbers
---
libs/ui-kit/src/lib/modal-input.tsx | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/libs/ui-kit/src/lib/modal-input.tsx b/libs/ui-kit/src/lib/modal-input.tsx
index e6ce545b1..671200014 100644
--- a/libs/ui-kit/src/lib/modal-input.tsx
+++ b/libs/ui-kit/src/lib/modal-input.tsx
@@ -3,6 +3,7 @@ import {
InputHTMLAttributes,
ReactNode,
useCallback,
+ useMemo,
} from 'react';
import clsx from 'clsx';
import MaskedInput from 'react-text-mask';
@@ -29,7 +30,13 @@ const CurrencyInput = ({
...maskOptions,
});
- return ;
+ const inputValue = useMemo(() => {
+ // Hack, because react-text-mask doesn't work with correct with decimals
+ // ex: it converts 0.0709 to 0.070 (not 0.071!)
+ return inputProps.value ? Number(inputProps.value).toFixed(3) : undefined;
+ }, [inputProps.value]);
+
+ return ;
};
export function StringInput({