import React, { useMemo } from 'react'; import PropTypes from 'prop-types'; import { EDIT_GAS_MODES, PRIORITY_LEVELS, } from '../../../../../shared/constants/gas'; import { COLORS, FONT_WEIGHT, TYPOGRAPHY, } from '../../../../helpers/constants/design-system'; import { roundToDecimalPlacesRemovingExtraZeroes } from '../../../../helpers/utils/util'; import Typography from '../../../ui/typography'; const EditGasToolTip = ({ editGasMode, estimateGreaterThanGasUse, gasLimit, priorityLevel, // maxFeePerGas & maxPriorityFeePerGas are derived from conditional logic // related to the source of the estimates. We pass these values from the // the parent component (edit-gas-item) rather than recalculate them maxFeePerGas, maxPriorityFeePerGas, transaction, t, }) => { const toolTipMessage = useMemo(() => { switch (priorityLevel) { case PRIORITY_LEVELS.LOW: return t('lowGasSettingToolTipMessage', [ {t('low')} , ]); case PRIORITY_LEVELS.MEDIUM: if (estimateGreaterThanGasUse) { return t('disabledGasOptionToolTipMessage', [ {t(priorityLevel)} , ]); } return t('mediumGasSettingToolTipMessage', [ {t('medium')} , ]); case PRIORITY_LEVELS.HIGH: if (estimateGreaterThanGasUse) { return t('disabledGasOptionToolTipMessage', [ {t(priorityLevel)} , ]); } if (editGasMode === EDIT_GAS_MODES.SWAPS) { return t('swapSuggestedGasSettingToolTipMessage'); } return t('highGasSettingToolTipMessage', [ {t('high')} , ]); case PRIORITY_LEVELS.CUSTOM: return t('customGasSettingToolTipMessage', [ {t('custom')} , ]); case PRIORITY_LEVELS.DAPP_SUGGESTED: return transaction?.origin ? t('dappSuggestedGasSettingToolTipMessage', [ {transaction?.origin}, ]) : null; default: return ''; } }, [editGasMode, estimateGreaterThanGasUse, priorityLevel, transaction, t]); return (
{priorityLevel !== PRIORITY_LEVELS.CUSTOM && priorityLevel !== PRIORITY_LEVELS.DAPP_SUGGESTED && !( priorityLevel === PRIORITY_LEVELS.HIGH && editGasMode === EDIT_GAS_MODES.SWAPS ) && !estimateGreaterThanGasUse ? ( ) : null} {toolTipMessage && (
{toolTipMessage}
)} {priorityLevel === PRIORITY_LEVELS.CUSTOM || estimateGreaterThanGasUse ? null : (
{t('maxBaseFee')} {maxFeePerGas && ( {roundToDecimalPlacesRemovingExtraZeroes(maxFeePerGas, 4)} )}
{t('priorityFeeProperCase')} {maxPriorityFeePerGas && ( {roundToDecimalPlacesRemovingExtraZeroes( maxPriorityFeePerGas, 4, )} )}
{t('gasLimit')} {gasLimit && ( {roundToDecimalPlacesRemovingExtraZeroes(gasLimit, 4)} )}
)}
); }; EditGasToolTip.propTypes = { estimateGreaterThanGasUse: PropTypes.bool, priorityLevel: PropTypes.string, maxFeePerGas: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), maxPriorityFeePerGas: PropTypes.oneOfType([ PropTypes.number, PropTypes.string, ]), t: PropTypes.func, editGasMode: PropTypes.string, gasLimit: PropTypes.number, transaction: PropTypes.object, }; export default EditGasToolTip;