Skip to content

Commit

Permalink
Do not trim extra decimal zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrila committed Apr 1, 2024
1 parent 63b71c3 commit 95e8924
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
34 changes: 4 additions & 30 deletions src/components/ui/forms/BigNumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,9 @@ export function BigNumberInput({
...rest
}: BigNumberInputProps) {
const { t } = useTranslation('common');
const removeTrailingZeros = (input: string) => {
if (input.includes('.')) {
const [leftDigits, rightDigits] = input.split('.');
if (Number(rightDigits) === 0) {
return input.slice(0, leftDigits.length);
}
}
return input;
};

const [inputValue, setInputValue] = useState<string>('');

useEffect(() => {
if (!value) return;
setInputValue(
value
? !value.isZero()
? removeTrailingZeros(utils.formatUnits(value, decimalPlaces))
: '0'
: '',
);
}, [value, decimalPlaces]);
const [inputValue, setInputValue] = useState<string>(
value && !value.isZero() ? utils.formatUnits(value, decimalPlaces) : '',
);

// this will insure the caret in the input component does not shift to the end of the input when the value is changed
const resetCaretPositionForInput = (event: React.ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -140,13 +121,6 @@ export function BigNumberInput({
[decimalPlaces, max, onChange, truncateDecimalPlaces],
);

const onChangeInput = useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
processValue(event);
},
[processValue],
);

//set value to min if less than min, when focus is lost
const onBlur = useCallback(
(event: React.FocusEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -182,7 +156,7 @@ export function BigNumberInput({
<InputGroup>
<Input
value={inputValue}
onChange={onChangeInput}
onChange={processValue}
onBlur={onBlur}
type="number"
{...rest}
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/modals/ProposalTemplateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ export default function ProposalTemplateModal({
),
)}
{(showAll ||
!transaction.ethValue.bigNumberValue ||
BigNumber.from(transaction.ethValue.bigNumberValue).eq(0)) && (
!transactions[transactionIndex].ethValue.bigNumberValue ||
BigNumber.from(transactions[transactionIndex].ethValue.bigNumberValue).eq(0)) && (
<Flex
width="100%"
flexWrap="wrap"
Expand Down

0 comments on commit 95e8924

Please sign in to comment.