Skip to content

Commit

Permalink
use numeric for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistevam committed Feb 5, 2024
1 parent 38d63f8 commit 597ee13
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
PriorityLevels,
} from '../../../../../../shared/constants/gas';
import { PRIMARY } from '../../../../../helpers/constants/common';
import { bnGreaterThan, bnLessThan } from '../../../../../helpers/utils/util';
import { getAdvancedGasFeeValues } from '../../../../../selectors';
import { useGasFeeContext } from '../../../../../contexts/gasFee';
import { useI18nContext } from '../../../../../hooks/useI18nContext';
Expand All @@ -22,20 +21,21 @@ import { decGWEIToHexWEI } from '../../../../../../shared/modules/conversion.uti
import { Numeric } from '../../../../../../shared/modules/Numeric';

const validateBaseFee = (value, gasFeeEstimates, maxPriorityFeePerGas) => {
if (bnGreaterThan(maxPriorityFeePerGas, value)) {
const baseFeeValue = new Numeric(value, 10);
if (new Numeric(maxPriorityFeePerGas, 10).greaterThan(baseFeeValue)) {
return 'editGasMaxBaseFeeGWEIImbalance';
}
if (
gasFeeEstimates?.low &&
bnLessThan(value, gasFeeEstimates.low.suggestedMaxFeePerGas)
baseFeeValue.lessThan(gasFeeEstimates.low.suggestedMaxFeePerGas, 10)
) {
return 'editGasMaxBaseFeeLow';
}
if (
gasFeeEstimates?.high &&
bnGreaterThan(
value,
baseFeeValue.greaterThan(
gasFeeEstimates.high.suggestedMaxFeePerGas * HIGH_FEE_WARNING_MULTIPLIER,
10,
)
) {
return 'editGasMaxBaseFeeHigh';
Expand Down Expand Up @@ -83,6 +83,7 @@ const BaseFeeInput = () => {
const updateBaseFee = useCallback(
(value) => {
setBaseFee(new Numeric(value, 10)?.toString());
// setBaseFee(value);
},
[setBaseFee],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,32 @@ import { useI18nContext } from '../../../../../hooks/useI18nContext';
import { useUserPreferencedCurrency } from '../../../../../hooks/useUserPreferencedCurrency';
import FormField from '../../../../ui/form-field';
import Box from '../../../../ui/box';
import { bnGreaterThan, bnLessThan } from '../../../../../helpers/utils/util';

import { useAdvancedGasFeePopoverContext } from '../../context';
import AdvancedGasFeeInputSubtext from '../../advanced-gas-fee-input-subtext';
import { decGWEIToHexWEI } from '../../../../../../shared/modules/conversion.utils';
import { Numeric } from '../../../../../../shared/modules/Numeric';

const validatePriorityFee = (value, gasFeeEstimates) => {
if (value < 0) {
const priorityFeeValue = new Numeric(value, 10);
if (priorityFeeValue.lessThan(0, 10)) {
return 'editGasMaxPriorityFeeBelowMinimumV2';
}
if (
gasFeeEstimates?.low &&
bnLessThan(value, gasFeeEstimates.low.suggestedMaxPriorityFeePerGas)
priorityFeeValue.lessThan(
gasFeeEstimates.low.suggestedMaxPriorityFeePerGas,
10,
)
) {
return 'editGasMaxPriorityFeeLowV2';
}
if (
gasFeeEstimates?.high &&
bnGreaterThan(
value,
priorityFeeValue.greaterThan(
gasFeeEstimates.high.suggestedMaxPriorityFeePerGas *
HIGH_FEE_WARNING_MULTIPLIER,
10,
)
) {
return 'editGasMaxPriorityFeeHighV2';
Expand Down

0 comments on commit 597ee13

Please sign in to comment.