import React, { useContext } from 'react'; import { useSelector } from 'react-redux'; import PropTypes from 'prop-types'; import { GAS_RECOMMENDATIONS, EDIT_GAS_MODES, } from '../../../../shared/constants/gas'; import { isEIP1559Network } from '../../../ducks/metamask/metamask'; import Button from '../../ui/button'; import Typography from '../../ui/typography/typography'; import { COLORS, TYPOGRAPHY, FONT_WEIGHT, } from '../../../helpers/constants/design-system'; import { areDappSuggestedAndTxParamGasFeesTheSame } from '../../../helpers/utils/confirm-tx.util'; import InfoTooltip from '../../ui/info-tooltip'; import ErrorMessage from '../../ui/error-message'; import TransactionTotalBanner from '../transaction-total-banner/transaction-total-banner.component'; import RadioGroup from '../../ui/radio-group/radio-group.component'; import AdvancedGasControls from '../advanced-gas-controls/advanced-gas-controls.component'; import ActionableMessage from '../../ui/actionable-message/actionable-message'; import { I18nContext } from '../../../contexts/i18n'; import GasTiming from '../gas-timing'; export default function EditGasDisplay({ mode = EDIT_GAS_MODES.MODIFY_IN_PLACE, showEducationButton = false, onEducationClick, transaction, defaultEstimateToUse, maxPriorityFeePerGas, setMaxPriorityFeePerGas, maxPriorityFeePerGasFiat, maxFeePerGas, setMaxFeePerGas, maxFeePerGasFiat, estimatedMaximumNative, isGasEstimatesLoading, gasFeeEstimates, gasEstimateType, gasPrice, setGasPrice, gasLimit, setGasLimit, estimateToUse, setEstimateToUse, estimatedMinimumFiat, estimatedMaximumFiat, dappSuggestedGasFeeAcknowledged, setDappSuggestedGasFeeAcknowledged, showAdvancedForm, setShowAdvancedForm, warning, gasErrors, onManualChange, minimumGasLimit, balanceError, }) { const t = useContext(I18nContext); const dappSuggestedAndTxParamGasFeesAreTheSame = areDappSuggestedAndTxParamGasFeesTheSame( transaction, ); const requireDappAcknowledgement = Boolean( transaction?.dappSuggestedGasFees && !dappSuggestedGasFeeAcknowledged && dappSuggestedAndTxParamGasFeesAreTheSame, ); const networkSupports1559 = useSelector(isEIP1559Network); const showTopError = balanceError; let errorKey; if (balanceError) { errorKey = 'insufficientFunds'; } return (