import React, { useContext } from 'react'; import PropTypes from 'prop-types'; import { useSelector } from 'react-redux'; import { I18nContext } from '../../../contexts/i18n'; import FormField from '../../ui/form-field'; import { GAS_ESTIMATE_TYPES } from '../../../../shared/constants/gas'; import { getGasFormErrorText } from '../../../helpers/constants/gas'; import { getIsGasEstimatesLoading } from '../../../ducks/metamask/metamask'; import { getNetworkSupportsSettingGasFees } from '../../../selectors'; export default function AdvancedGasControls({ gasEstimateType, maxPriorityFee, maxFee, setMaxPriorityFee, setMaxFee, onManualChange, gasLimit, setGasLimit, gasPrice, setGasPrice, maxPriorityFeeFiat, maxFeeFiat, gasErrors, minimumGasLimit, supportsEIP1559, }) { const t = useContext(I18nContext); const isGasEstimatesLoading = useSelector(getIsGasEstimatesLoading); const showFeeMarketFields = supportsEIP1559 && (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET || gasEstimateType === GAS_ESTIMATE_TYPES.ETH_GASPRICE || isGasEstimatesLoading); const networkSupportsSettingGasFees = useSelector( getNetworkSupportsSettingGasFees, ); return (
{ onManualChange?.(); setGasLimit(value); }} tooltipText={t('editGasLimitTooltip')} value={gasLimit} allowDecimals={false} disabled={!networkSupportsSettingGasFees} numeric /> {showFeeMarketFields ? ( <> { onManualChange?.(); setMaxPriorityFee(value); }} value={maxPriorityFee} detailText={maxPriorityFeeFiat} numeric allowDecimals error={ gasErrors?.maxPriorityFee ? getGasFormErrorText(gasErrors.maxPriorityFee, t) : null } /> { onManualChange?.(); setMaxFee(value); }} value={maxFee} numeric allowDecimals detailText={maxFeeFiat} error={ gasErrors?.maxFee ? getGasFormErrorText(gasErrors.maxFee, t) : null } /> ) : ( <> { onManualChange?.(); setGasPrice(value); }} tooltipText={t('editGasPriceTooltip')} value={gasPrice} numeric allowDecimals error={ gasErrors?.gasPrice ? getGasFormErrorText(gasErrors.gasPrice, t) : null } disabled={!networkSupportsSettingGasFees} /> )}
); } AdvancedGasControls.propTypes = { gasEstimateType: PropTypes.oneOf(Object.values(GAS_ESTIMATE_TYPES)), setMaxPriorityFee: PropTypes.func, setMaxFee: PropTypes.func, maxPriorityFee: PropTypes.string, maxFee: PropTypes.string, onManualChange: PropTypes.func, gasLimit: PropTypes.number, setGasLimit: PropTypes.func, gasPrice: PropTypes.string, setGasPrice: PropTypes.func, maxPriorityFeeFiat: PropTypes.string, maxFeeFiat: PropTypes.string, gasErrors: PropTypes.object, minimumGasLimit: PropTypes.string, supportsEIP1559: PropTypes.bool, };