You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
178 lines
5.6 KiB
178 lines
5.6 KiB
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', [
|
|
<span key={priorityLevel}>
|
|
<b>{t('low')}</b>
|
|
</span>,
|
|
]);
|
|
case PRIORITY_LEVELS.MEDIUM:
|
|
if (estimateGreaterThanGasUse) {
|
|
return t('disabledGasOptionToolTipMessage', [
|
|
<span key={`disabled-priority-level-${priorityLevel}`}>
|
|
{t(priorityLevel)}
|
|
</span>,
|
|
]);
|
|
}
|
|
return t('mediumGasSettingToolTipMessage', [
|
|
<span key={priorityLevel}>
|
|
<b>{t('medium')}</b>
|
|
</span>,
|
|
]);
|
|
case PRIORITY_LEVELS.HIGH:
|
|
if (estimateGreaterThanGasUse) {
|
|
return t('disabledGasOptionToolTipMessage', [
|
|
<span key={`disabled-priority-level-${priorityLevel}`}>
|
|
{t(priorityLevel)}
|
|
</span>,
|
|
]);
|
|
}
|
|
if (editGasMode === EDIT_GAS_MODES.SWAPS) {
|
|
return t('swapSuggestedGasSettingToolTipMessage');
|
|
}
|
|
return t('highGasSettingToolTipMessage', [
|
|
<span key={priorityLevel}>
|
|
<b>{t('high')}</b>
|
|
</span>,
|
|
]);
|
|
case PRIORITY_LEVELS.CUSTOM:
|
|
return t('customGasSettingToolTipMessage', [
|
|
<span key={priorityLevel}>
|
|
<b>{t('custom')}</b>
|
|
</span>,
|
|
]);
|
|
case PRIORITY_LEVELS.DAPP_SUGGESTED:
|
|
return transaction?.origin
|
|
? t('dappSuggestedGasSettingToolTipMessage', [
|
|
<span key={transaction?.origin}>{transaction?.origin}</span>,
|
|
])
|
|
: null;
|
|
default:
|
|
return '';
|
|
}
|
|
}, [editGasMode, estimateGreaterThanGasUse, priorityLevel, transaction, t]);
|
|
|
|
return (
|
|
<div className="edit-gas-tooltip__container">
|
|
{priorityLevel !== PRIORITY_LEVELS.CUSTOM &&
|
|
priorityLevel !== PRIORITY_LEVELS.DAPP_SUGGESTED &&
|
|
!(
|
|
priorityLevel === PRIORITY_LEVELS.HIGH &&
|
|
editGasMode === EDIT_GAS_MODES.SWAPS
|
|
) &&
|
|
!estimateGreaterThanGasUse ? (
|
|
<img alt="" src={`./images/curve-${priorityLevel}.svg`} />
|
|
) : null}
|
|
{toolTipMessage && (
|
|
<div className="edit-gas-tooltip__container__message">
|
|
<Typography variant={TYPOGRAPHY.H7}>{toolTipMessage}</Typography>
|
|
</div>
|
|
)}
|
|
{priorityLevel === PRIORITY_LEVELS.CUSTOM ||
|
|
estimateGreaterThanGasUse ? null : (
|
|
<div className="edit-gas-tooltip__container__values">
|
|
<div>
|
|
<Typography
|
|
variant={TYPOGRAPHY.H7}
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
className="edit-gas-tooltip__container__label"
|
|
>
|
|
{t('maxBaseFee')}
|
|
</Typography>
|
|
{maxFeePerGas && (
|
|
<Typography
|
|
variant={TYPOGRAPHY.H7}
|
|
color={COLORS.NEUTRAL_GREY}
|
|
className="edit-gas-tooltip__container__value"
|
|
>
|
|
{roundToDecimalPlacesRemovingExtraZeroes(maxFeePerGas, 4)}
|
|
</Typography>
|
|
)}
|
|
</div>
|
|
<div>
|
|
<Typography
|
|
variant={TYPOGRAPHY.H7}
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
className="edit-gas-tooltip__container__label"
|
|
>
|
|
{t('priorityFeeProperCase')}
|
|
</Typography>
|
|
{maxPriorityFeePerGas && (
|
|
<Typography
|
|
variant={TYPOGRAPHY.H7}
|
|
color={COLORS.NEUTRAL_GREY}
|
|
className="edit-gas-tooltip__container__value"
|
|
>
|
|
{roundToDecimalPlacesRemovingExtraZeroes(
|
|
maxPriorityFeePerGas,
|
|
4,
|
|
)}
|
|
</Typography>
|
|
)}
|
|
</div>
|
|
<div>
|
|
<Typography
|
|
variant={TYPOGRAPHY.H7}
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
className="edit-gas-tooltip__container__label"
|
|
>
|
|
{t('gasLimit')}
|
|
</Typography>
|
|
{gasLimit && (
|
|
<Typography
|
|
variant={TYPOGRAPHY.H7}
|
|
color={COLORS.NEUTRAL_GREY}
|
|
className="edit-gas-tooltip__container__value"
|
|
>
|
|
{roundToDecimalPlacesRemovingExtraZeroes(gasLimit, 4)}
|
|
</Typography>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
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;
|
|
|