From adb56d8d16a9aa3d91e10d1608552f6a5c04e32a Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Thu, 23 Sep 2021 00:39:45 +0530 Subject: [PATCH] Adding base to BigNumber constructor to round off value (#12140) * Adding base to BigNumber constructor to round off value * Numeric inputs to not allow more than 14 decimal places --- ui/components/app/gas-timing/gas-timing.component.js | 4 ++-- ui/components/ui/numeric-input/numeric-input.component.js | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ui/components/app/gas-timing/gas-timing.component.js b/ui/components/app/gas-timing/gas-timing.component.js index 0f28ea7dc..95e5bc24a 100644 --- a/ui/components/app/gas-timing/gas-timing.component.js +++ b/ui/components/app/gas-timing/gas-timing.component.js @@ -71,8 +71,8 @@ export default function GasTiming({ ) { // getGasFeeTimeEstimate requires parameters in string format getGasFeeTimeEstimate( - new BigNumber(priority).toString(10), - new BigNumber(fee).toString(10), + new BigNumber(priority, 10).toString(10), + new BigNumber(fee, 10).toString(10), ).then((result) => { if (maxFeePerGas === fee && maxPriorityFeePerGas === priority) { setCustomEstimatedTime(result); diff --git a/ui/components/ui/numeric-input/numeric-input.component.js b/ui/components/ui/numeric-input/numeric-input.component.js index 0befdf4f6..948ecec92 100644 --- a/ui/components/ui/numeric-input/numeric-input.component.js +++ b/ui/components/ui/numeric-input/numeric-input.component.js @@ -4,6 +4,8 @@ import PropTypes from 'prop-types'; import Typography from '../typography/typography'; import { COLORS, TYPOGRAPHY } from '../../../helpers/constants/design-system'; +const DECIMAL_REGEX = /\.(\d*)/u; + export default function NumericInput({ detailText = '', value = 0, @@ -26,7 +28,10 @@ export default function NumericInput({ } }} onChange={(e) => { - onChange?.(parseFloat(e.target.value || 0, 10)); + const newValue = e.target.value; + const match = DECIMAL_REGEX.exec(newValue); + if (match?.[1]?.length >= 15) return; + onChange?.(parseFloat(newValue || 0, 10)); }} min="0" autoFocus={autoFocus}