2021-12-06 17:39:35 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
2023-01-27 19:28:03 +01:00
|
|
|
import { EditGasModes, PriorityLevels } from '../../../../shared/constants/gas';
|
2023-02-02 21:15:26 +01:00
|
|
|
import {
|
2023-02-16 14:26:14 +01:00
|
|
|
Color,
|
2023-02-02 21:15:26 +01:00
|
|
|
TextColor,
|
|
|
|
TypographyVariant,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
2021-12-06 17:39:35 +01:00
|
|
|
import { PRIORITY_LEVEL_ICON_MAP } from '../../../helpers/constants/gas';
|
|
|
|
import { useGasFeeContext } from '../../../contexts/gasFee';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2022-02-01 18:53:03 +01:00
|
|
|
import { useTransactionEventFragment } from '../../../hooks/useTransactionEventFragment';
|
2021-12-06 17:39:35 +01:00
|
|
|
import { useTransactionModalContext } from '../../../contexts/transaction-modal';
|
|
|
|
import InfoTooltip from '../../ui/info-tooltip/info-tooltip';
|
|
|
|
import Typography from '../../ui/typography/typography';
|
2023-02-16 14:26:14 +01:00
|
|
|
import { Icon, ICON_NAMES, ICON_SIZES } from '../../component-library';
|
2021-12-06 17:39:35 +01:00
|
|
|
|
|
|
|
export default function EditGasFeeButton({ userAcknowledgedGasMissing }) {
|
|
|
|
const t = useI18nContext();
|
|
|
|
const {
|
2021-12-12 00:26:28 +01:00
|
|
|
editGasMode,
|
2021-12-06 17:39:35 +01:00
|
|
|
gasLimit,
|
|
|
|
hasSimulationError,
|
|
|
|
estimateUsed,
|
|
|
|
maxFeePerGas,
|
|
|
|
maxPriorityFeePerGas,
|
2022-12-08 19:37:06 +01:00
|
|
|
supportsEIP1559,
|
2021-12-06 17:39:35 +01:00
|
|
|
transaction,
|
|
|
|
} = useGasFeeContext();
|
2022-02-01 18:53:03 +01:00
|
|
|
const { updateTransactionEventFragment } = useTransactionEventFragment();
|
2021-12-06 17:39:35 +01:00
|
|
|
const { openModal } = useTransactionModalContext();
|
|
|
|
const editEnabled =
|
|
|
|
!hasSimulationError || userAcknowledgedGasMissing === true;
|
|
|
|
|
2022-12-08 19:37:06 +01:00
|
|
|
if (!supportsEIP1559 || !estimateUsed || !editEnabled) {
|
2021-12-06 17:39:35 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-12-12 00:26:28 +01:00
|
|
|
let icon = estimateUsed;
|
|
|
|
let title = estimateUsed;
|
|
|
|
if (
|
2023-01-27 19:28:03 +01:00
|
|
|
estimateUsed === PriorityLevels.high &&
|
|
|
|
editGasMode === EditGasModes.swaps
|
2021-12-12 00:26:28 +01:00
|
|
|
) {
|
|
|
|
icon = 'swapSuggested';
|
|
|
|
title = 'swapSuggested';
|
2023-01-27 19:28:03 +01:00
|
|
|
} else if (estimateUsed === PriorityLevels.tenPercentIncreased) {
|
2022-01-06 03:47:26 +01:00
|
|
|
icon = undefined;
|
2022-01-06 23:40:31 +01:00
|
|
|
title = 'tenPercentIncreased';
|
2021-12-12 00:26:28 +01:00
|
|
|
}
|
|
|
|
|
2022-02-01 18:53:03 +01:00
|
|
|
const openEditGasFeeModal = () => {
|
|
|
|
updateTransactionEventFragment({
|
|
|
|
gas_edit_attempted: 'basic',
|
|
|
|
});
|
|
|
|
openModal('editGasFee');
|
|
|
|
};
|
|
|
|
|
|
|
|
const openAdvancedGasFeeModal = () => {
|
|
|
|
updateTransactionEventFragment({
|
|
|
|
gas_edit_attempted: 'advanced',
|
|
|
|
});
|
|
|
|
openModal('advancedGasFee');
|
|
|
|
};
|
|
|
|
|
2021-12-06 17:39:35 +01:00
|
|
|
return (
|
|
|
|
<div className="edit-gas-fee-button">
|
2022-02-01 18:53:03 +01:00
|
|
|
<button onClick={openEditGasFeeModal} data-testid="edit-gas-fee-button">
|
2022-01-06 03:47:26 +01:00
|
|
|
{icon && (
|
|
|
|
<span className="edit-gas-fee-button__icon">
|
2022-01-31 06:51:43 +01:00
|
|
|
{PRIORITY_LEVEL_ICON_MAP[icon]}
|
2022-01-06 03:47:26 +01:00
|
|
|
</span>
|
|
|
|
)}
|
2021-12-12 00:26:28 +01:00
|
|
|
<span className="edit-gas-fee-button__label">{t(title)}</span>
|
2023-02-16 14:26:14 +01:00
|
|
|
<Icon
|
|
|
|
name={ICON_NAMES.ARROW_RIGHT}
|
|
|
|
color={Color.primaryDefault}
|
|
|
|
size={ICON_SIZES.XS}
|
|
|
|
/>
|
2021-12-06 17:39:35 +01:00
|
|
|
</button>
|
|
|
|
{estimateUsed === 'custom' && (
|
2022-02-01 18:53:03 +01:00
|
|
|
<button onClick={openAdvancedGasFeeModal}>{t('edit')}</button>
|
2021-12-06 17:39:35 +01:00
|
|
|
)}
|
|
|
|
{estimateUsed === 'dappSuggested' && (
|
|
|
|
<InfoTooltip
|
|
|
|
contentText={
|
|
|
|
<div className="edit-gas-fee-button__tooltip">
|
2022-05-23 22:04:54 +02:00
|
|
|
{transaction?.origin && (
|
|
|
|
<Typography
|
2023-02-02 21:15:26 +01:00
|
|
|
variant={TypographyVariant.H7}
|
|
|
|
color={TextColor.textAlternative}
|
2022-05-23 22:04:54 +02:00
|
|
|
>
|
|
|
|
{t('dappSuggestedTooltip', [transaction.origin])}
|
|
|
|
</Typography>
|
|
|
|
)}
|
2023-02-02 21:15:26 +01:00
|
|
|
<Typography variant={TypographyVariant.H7}>
|
2022-05-23 22:04:54 +02:00
|
|
|
<b>{t('maxBaseFee')}</b> {maxFeePerGas}
|
2021-12-06 17:39:35 +01:00
|
|
|
</Typography>
|
2023-02-02 21:15:26 +01:00
|
|
|
<Typography variant={TypographyVariant.H7}>
|
2022-05-23 22:04:54 +02:00
|
|
|
<b>{t('maxPriorityFee')}</b> {maxPriorityFeePerGas}
|
2021-12-06 17:39:35 +01:00
|
|
|
</Typography>
|
2023-02-02 21:15:26 +01:00
|
|
|
<Typography variant={TypographyVariant.H7}>
|
2022-05-23 22:04:54 +02:00
|
|
|
<b>{t('gasLimit')}</b> {gasLimit}
|
2021-12-06 17:39:35 +01:00
|
|
|
</Typography>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
position="top"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
EditGasFeeButton.propTypes = {
|
|
|
|
userAcknowledgedGasMissing: PropTypes.bool,
|
|
|
|
};
|