import React from 'react'; import PropTypes from 'prop-types'; import { EditGasModes, PriorityLevels } from '../../../../shared/constants/gas'; import { Color, TextColor, TextVariant, } from '../../../helpers/constants/design-system'; import { PRIORITY_LEVEL_ICON_MAP } from '../../../helpers/constants/gas'; import { useGasFeeContext } from '../../../contexts/gasFee'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { useTransactionEventFragment } from '../../../hooks/useTransactionEventFragment'; import { useTransactionModalContext } from '../../../contexts/transaction-modal'; import InfoTooltip from '../../ui/info-tooltip/info-tooltip'; import { Icon, IconName, IconSize, Text } from '../../component-library'; export default function EditGasFeeButton({ userAcknowledgedGasMissing }) { const t = useI18nContext(); const { editGasMode, gasLimit, hasSimulationError, estimateUsed, maxFeePerGas, maxPriorityFeePerGas, supportsEIP1559, transaction, } = useGasFeeContext(); const { updateTransactionEventFragment } = useTransactionEventFragment(); const { openModal } = useTransactionModalContext(); const editEnabled = !hasSimulationError || userAcknowledgedGasMissing === true; if (!supportsEIP1559 || !estimateUsed || !editEnabled) { return null; } let icon = estimateUsed; let title = estimateUsed; if ( estimateUsed === PriorityLevels.high && editGasMode === EditGasModes.swaps ) { icon = 'swapSuggested'; title = 'swapSuggested'; } else if (estimateUsed === PriorityLevels.tenPercentIncreased) { icon = undefined; title = 'tenPercentIncreased'; } const openEditGasFeeModal = () => { updateTransactionEventFragment({ gas_edit_attempted: 'basic', }); openModal('editGasFee'); }; const openAdvancedGasFeeModal = () => { updateTransactionEventFragment({ gas_edit_attempted: 'advanced', }); openModal('advancedGasFee'); }; return (
{estimateUsed === 'custom' && ( )} {estimateUsed === 'dappSuggested' && ( {transaction?.origin && ( {t('dappSuggestedTooltip', [transaction.origin])} )} {t('maxBaseFee')} {maxFeePerGas} {t('maxPriorityFee')} {maxPriorityFeePerGas} {t('gasLimit')} {gasLimit}
} position="top" /> )} ); } EditGasFeeButton.propTypes = { userAcknowledgedGasMissing: PropTypes.bool, };