import React, { useContext } from 'react'; import PropTypes from 'prop-types'; import { GAS_RECOMMENDATIONS, EDIT_GAS_MODES, } from '../../../../shared/constants/gas'; import Button from '../../ui/button'; import Typography from '../../ui/typography/typography'; import { COLORS, TYPOGRAPHY, FONT_WEIGHT, TEXT_ALIGN, } from '../../../helpers/constants/design-system'; import InfoTooltip from '../../ui/info-tooltip'; 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'; export default function EditGasDisplay({ mode = EDIT_GAS_MODES.MODIFY_IN_PLACE, alwaysShowForm = false, showEducationButton = false, onEducationClick, transaction, defaultEstimateToUse, maxPriorityFeePerGas, setMaxPriorityFeePerGas, maxPriorityFeePerGasFiat, maxFeePerGas, setMaxFeePerGas, maxFeePerGasFiat, estimatedMaximumNative, isGasEstimatesLoading, gasFeeEstimates, gasEstimateType, gasPrice, setGasPrice, gasLimit, setGasLimit, estimateToUse, setEstimateToUse, estimatedMinimumFiat, estimatedMaximumFiat, isMaxFeeError, isMaxPriorityFeeError, isGasTooLow, dappSuggestedGasFeeAcknowledged, setDappSuggestedGasFeeAcknowledged, showAdvancedForm, setShowAdvancedForm, warning, }) { const t = useContext(I18nContext); const requireDappAcknowledgement = Boolean( transaction?.dappSuggestedGasFees && !dappSuggestedGasFeeAcknowledged, ); return (
{warning && (
)} {requireDappAcknowledgement && (
)} {mode === EDIT_GAS_MODES.SPEED_UP && (
{t('speedUpTooltipText')}{' '}
)} {estimatedMaximumFiat} , {estimatedMaximumNative} , ]) } timing="" /> {requireDappAcknowledgement && ( )} {isGasTooLow && (
{t('editGasTooLow')}
)} {!requireDappAcknowledgement && ![EDIT_GAS_MODES.SPEED_UP, EDIT_GAS_MODES.CANCEL].includes(mode) && ( )} {!alwaysShowForm && !requireDappAcknowledgement && ( )} {!requireDappAcknowledgement && (alwaysShowForm || showAdvancedForm) && ( )}
{!requireDappAcknowledgement && showEducationButton && (
)}
); } EditGasDisplay.propTypes = { alwaysShowForm: PropTypes.bool, mode: PropTypes.oneOf(Object.values(EDIT_GAS_MODES)), showEducationButton: PropTypes.bool, onEducationClick: PropTypes.func, defaultEstimateToUse: PropTypes.oneOf(Object.values(GAS_RECOMMENDATIONS)), maxPriorityFeePerGas: PropTypes.string, setMaxPriorityFeePerGas: PropTypes.func, maxPriorityFeePerGasFiat: PropTypes.string, maxFeePerGas: PropTypes.string, setMaxFeePerGas: PropTypes.func, maxFeePerGasFiat: PropTypes.string, estimatedMaximumNative: PropTypes.string, isGasEstimatesLoading: PropTypes.boolean, gasFeeEstimates: PropTypes.object, gasEstimateType: PropTypes.string, gasPrice: PropTypes.string, setGasPrice: PropTypes.func, gasLimit: PropTypes.number, setGasLimit: PropTypes.func, estimateToUse: PropTypes.string, setEstimateToUse: PropTypes.func, estimatedMinimumFiat: PropTypes.string, estimatedMaximumFiat: PropTypes.string, isMaxFeeError: PropTypes.boolean, isMaxPriorityFeeError: PropTypes.boolean, isGasTooLow: PropTypes.boolean, dappSuggestedGasFeeAcknowledged: PropTypes.boolean, setDappSuggestedGasFeeAcknowledged: PropTypes.func, showAdvancedForm: PropTypes.bool, setShowAdvancedForm: PropTypes.func, warning: PropTypes.string, transaction: PropTypes.object, };