import React, { useContext, useRef } from 'react'; import PropTypes from 'prop-types'; import BigNumber from 'bignumber.js'; import { EditGasModes } from '../../../../shared/constants/gas'; import Button from '../../ui/button'; import { TEXT_ALIGN, FONT_WEIGHT, TextColor, TextVariant, } from '../../../helpers/constants/design-system'; import { Text } from '../../component-library'; import { areDappSuggestedAndTxParamGasFeesTheSame } from '../../../helpers/utils/confirm-tx.util'; import InfoTooltip from '../../ui/info-tooltip'; import ErrorMessage from '../../ui/error-message'; 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 = EditGasModes.modifyInPlace, estimatedMinimumNative, transaction, gasPrice, setGasPrice, gasLimit, setGasLimit, properGasLimit, dappSuggestedGasFeeAcknowledged, setDappSuggestedGasFeeAcknowledged, onManualChange, minimumGasLimit, balanceError, gasErrors, txParamsHaveBeenCustomized, }) { const t = useContext(I18nContext); const scrollRef = useRef(null); const dappSuggestedAndTxParamGasFeesAreTheSame = areDappSuggestedAndTxParamGasFeesTheSame(transaction); const requireDappAcknowledgement = Boolean( transaction?.dappSuggestedGasFees && !dappSuggestedGasFeeAcknowledged && dappSuggestedAndTxParamGasFeesAreTheSame, ); let warningMessage; if ( gasLimit !== undefined && properGasLimit !== undefined && new BigNumber(gasLimit).lessThan(new BigNumber(properGasLimit)) ) { warningMessage = t('gasLimitRecommended', [properGasLimit]); } const showTopError = balanceError && txParamsHaveBeenCustomized; let errorKey; if (balanceError) { errorKey = 'insufficientFunds'; } return (
{showTopError && (
)} {warningMessage && (
)} {requireDappAcknowledgement && (
)} {mode === EditGasModes.speedUp && (
{t('speedUpTooltipText')}{' '}
)} {estimatedMinimumNative} {requireDappAcknowledgement && ( )} {!requireDappAcknowledgement && ( )}
); } EditGasDisplay.propTypes = { mode: PropTypes.oneOf(Object.values(EditGasModes)), estimatedMinimumNative: PropTypes.string, gasPrice: PropTypes.string, setGasPrice: PropTypes.func, gasLimit: PropTypes.number, setGasLimit: PropTypes.func, properGasLimit: PropTypes.number, dappSuggestedGasFeeAcknowledged: PropTypes.bool, setDappSuggestedGasFeeAcknowledged: PropTypes.func, transaction: PropTypes.object, onManualChange: PropTypes.func, minimumGasLimit: PropTypes.string, balanceError: PropTypes.bool, gasErrors: PropTypes.object, txParamsHaveBeenCustomized: PropTypes.bool, };