import React, { useState, useContext } from 'react'; import PropTypes from 'prop-types'; import { GAS_RECOMMENDATIONS } 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'; import { useGasFeeInputs } from '../../../hooks/useGasFeeInputs'; export default function EditGasDisplay({ alwaysShowForm, type, showEducationButton, onEducationClick, dappSuggestedGasFee, dappOrigin, defaultEstimateToUse = 'medium', }) { const t = useContext(I18nContext); const [warning] = useState(null); const [showAdvancedForm, setShowAdvancedForm] = useState(false); const [ dappSuggestedGasFeeAcknowledged, setDappSuggestedGasFeeAcknowledged, ] = useState(false); const requireDappAcknowledgement = Boolean( dappSuggestedGasFee && !dappSuggestedGasFeeAcknowledged, ); const { maxPriorityFeePerGas, setMaxPriorityFeePerGas, maxPriorityFeePerGasFiat, maxFeePerGas, setMaxFeePerGas, maxFeePerGasFiat, estimatedMaximumNative, isGasEstimatesLoading, gasFeeEstimates, gasEstimateType, gasPrice, setGasPrice, gasLimit, setGasLimit, estimateToUse, setEstimateToUse, estimatedMinimumFiat, estimatedMaximumFiat, isMaxFeeError, isMaxPriorityFeeError, isGasTooLow, } = useGasFeeInputs(defaultEstimateToUse); return (
{warning && (
)} {requireDappAcknowledgement && (
)} {type === 'speed-up' && (
{t('speedUpTooltipText')}{' '}
)} {estimatedMaximumFiat} , {estimatedMaximumNative} , ]) } timing="" /> {requireDappAcknowledgement && ( )} {isGasTooLow && (
{t('editGasTooLow')}
)} {!requireDappAcknowledgement && ( )} {!alwaysShowForm && ( )} {!requireDappAcknowledgement && (alwaysShowForm || showAdvancedForm) && ( )}
{!requireDappAcknowledgement && showEducationButton && (
)}
); } EditGasDisplay.propTypes = { alwaysShowForm: PropTypes.bool, type: PropTypes.oneOf(['customize-gas', 'speed-up']), showEducationButton: PropTypes.bool, onEducationClick: PropTypes.func, dappSuggestedGasFee: PropTypes.number, dappOrigin: PropTypes.string, defaultEstimateToUse: PropTypes.oneOf(Object.values(GAS_RECOMMENDATIONS)), }; EditGasDisplay.defaultProps = { alwaysShowForm: false, type: 'customize-gas', showEducationButton: false, onEducationClick: undefined, dappSuggestedGasFee: 0, dappOrigin: '', };