1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

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
This commit is contained in:
Jyoti Puri 2021-09-23 00:39:45 +05:30 committed by GitHub
parent 02a4da9ad2
commit adb56d8d16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -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);

View File

@ -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}