import React, { useContext } from 'react'; import PropTypes from 'prop-types'; import { useSelector } from 'react-redux'; import { isEIP1559Network } from '../../../ducks/metamask/metamask'; import { I18nContext } from '../../../contexts/i18n'; import Typography from '../../ui/typography/typography'; import { FONT_WEIGHT, TYPOGRAPHY, COLORS, } from '../../../helpers/constants/design-system'; import FormField from '../../ui/form-field'; import { GAS_ESTIMATE_TYPES, GAS_RECOMMENDATIONS, } from '../../../../shared/constants/gas'; import { getGasFormErrorText } from '../../../helpers/constants/gas'; export default function AdvancedGasControls({ estimateToUse, gasFeeEstimates, gasEstimateType, maxPriorityFee, maxFee, setMaxPriorityFee, setMaxFee, onManualChange, gasLimit, setGasLimit, gasPrice, setGasPrice, maxPriorityFeeFiat, maxFeeFiat, gasErrors, networkSupportsEIP1559, minimumGasLimit, }) { const t = useContext(I18nContext); const networkSupports1559 = useSelector(isEIP1559Network); const suggestedValues = {}; if (networkSupportsEIP1559) { suggestedValues.maxFeePerGas = gasFeeEstimates?.[estimateToUse]?.suggestedMaxFeePerGas || gasFeeEstimates?.gasPrice; suggestedValues.maxPriorityFeePerGas = gasFeeEstimates?.[estimateToUse]?.suggestedMaxPriorityFeePerGas || suggestedValues.maxFeePerGas; } else { switch (gasEstimateType) { case GAS_ESTIMATE_TYPES.LEGACY: suggestedValues.gasPrice = gasFeeEstimates?.[estimateToUse]; break; case GAS_ESTIMATE_TYPES.ETH_GASPRICE: suggestedValues.gasPrice = gasFeeEstimates?.gasPrice; break; default: break; } } const showFeeMarketFields = networkSupports1559 && (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET || gasEstimateType === GAS_ESTIMATE_TYPES.ETH_GASPRICE); return (