import classNames from 'classnames'; import PropTypes from 'prop-types'; import React from 'react'; import { EditGasModes, PriorityLevels, } from '../../../../../shared/constants/gas'; import { PRIORITY_LEVEL_ICON_MAP } from '../../../../helpers/constants/gas'; import { PRIMARY } from '../../../../helpers/constants/common'; import { toHumanReadableTime } from '../../../../helpers/utils/util'; 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'; import LoadingHeartBeat from '../../../ui/loading-heartbeat'; import UserPreferencedCurrencyDisplay from '../../user-preferenced-currency-display'; import EditGasToolTip from '../edit-gas-tooltip/edit-gas-tooltip'; import { useGasItemFeeDetails } from './useGasItemFeeDetails'; const getTitleAndIcon = (priorityLevel, editGasMode) => { let icon = priorityLevel; let title = priorityLevel; if (priorityLevel === PriorityLevels.dAppSuggested) { title = 'dappSuggestedShortLabel'; } else if (priorityLevel === PriorityLevels.dappSuggestedHigh) { title = 'dappSuggestedHighShortLabel'; } else if (priorityLevel === PriorityLevels.tenPercentIncreased) { icon = null; title = 'tenPercentIncreased'; } else if ( priorityLevel === PriorityLevels.high && editGasMode === EditGasModes.swaps ) { icon = 'swapSuggested'; title = 'swapSuggested'; } return { title, icon }; }; const EditGasItem = ({ priorityLevel }) => { const { editGasMode, estimateUsed, gasLimit, updateTransactionToTenPercentIncreasedGasFee, updateTransactionUsingDAPPSuggestedValues, updateTransactionUsingEstimate, transaction, } = useGasFeeContext(); const { updateTransactionEventFragment } = useTransactionEventFragment(); const t = useI18nContext(); const { closeModal, openModal } = useTransactionModalContext(); const { dappSuggestedGasFees } = transaction; const { // for cancel or speedup estimateGreaterThaGasUse is true if previous gas used // was more than estimate for the priorityLevel estimateGreaterThanGasUse, hexMaximumTransactionFee, maxFeePerGas, maxPriorityFeePerGas, minWaitTime, } = useGasItemFeeDetails(priorityLevel); if ( priorityLevel === PriorityLevels.dAppSuggested && !dappSuggestedGasFees?.maxFeePerGas && !dappSuggestedGasFees?.gasPrice ) { return null; } const onOptionSelect = () => { if (priorityLevel === PriorityLevels.custom) { updateTransactionEventFragment({ properties: { gas_edit_attempted: 'advanced', }, }); openModal('advancedGasFee'); } else { updateTransactionEventFragment({ properties: { gas_edit_type: 'basic', }, }); closeModal(['editGasFee']); if (priorityLevel === PriorityLevels.tenPercentIncreased) { updateTransactionToTenPercentIncreasedGasFee(); } else if (priorityLevel === PriorityLevels.dAppSuggested) { updateTransactionUsingDAPPSuggestedValues(); } else { updateTransactionUsingEstimate(priorityLevel); } } }; const { title, icon } = getTitleAndIcon(priorityLevel, editGasMode); return ( ); }; EditGasItem.propTypes = { priorityLevel: PropTypes.string, }; export default EditGasItem;