2021-11-18 18:54:58 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
2023-01-27 19:28:03 +01:00
|
|
|
import { EditGasModes, PriorityLevels } from '../../../../shared/constants/gas';
|
2021-11-18 18:54:58 +01:00
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2021-11-23 18:46:33 +01:00
|
|
|
import { useTransactionModalContext } from '../../../contexts/transaction-modal';
|
2022-01-22 01:23:02 +01:00
|
|
|
import Box from '../../ui/box';
|
2021-11-23 19:18:44 +01:00
|
|
|
import ErrorMessage from '../../ui/error-message';
|
2021-11-23 17:52:50 +01:00
|
|
|
import Popover from '../../ui/popover';
|
|
|
|
import Typography from '../../ui/typography/typography';
|
2021-11-18 18:54:58 +01:00
|
|
|
|
2023-02-02 21:15:26 +01:00
|
|
|
import {
|
|
|
|
TextColor,
|
|
|
|
TypographyVariant,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
2021-11-23 19:18:44 +01:00
|
|
|
import { INSUFFICIENT_FUNDS_ERROR_KEY } from '../../../helpers/constants/error-keys';
|
|
|
|
import { useGasFeeContext } from '../../../contexts/gasFee';
|
2022-01-06 03:47:26 +01:00
|
|
|
import AppLoadingSpinner from '../app-loading-spinner';
|
2022-08-23 16:19:31 +02:00
|
|
|
import ZENDESK_URLS from '../../../helpers/constants/zendesk-url';
|
2021-11-18 18:54:58 +01:00
|
|
|
import EditGasItem from './edit-gas-item';
|
2021-12-06 17:02:23 +01:00
|
|
|
import NetworkStatistics from './network-statistics';
|
2021-11-18 18:54:58 +01:00
|
|
|
|
2021-11-23 18:46:33 +01:00
|
|
|
const EditGasFeePopover = () => {
|
2021-12-12 00:26:28 +01:00
|
|
|
const { balanceError, editGasMode } = useGasFeeContext();
|
2021-11-18 18:54:58 +01:00
|
|
|
const t = useI18nContext();
|
2022-07-31 20:26:40 +02:00
|
|
|
const { closeAllModals, closeModal, currentModal, openModalCount } =
|
|
|
|
useTransactionModalContext();
|
2021-11-23 18:46:33 +01:00
|
|
|
|
2022-01-06 23:56:51 +01:00
|
|
|
if (currentModal !== 'editGasFee') {
|
|
|
|
return null;
|
|
|
|
}
|
2021-11-18 18:54:58 +01:00
|
|
|
|
2022-01-06 03:47:26 +01:00
|
|
|
let popupTitle = 'editGasFeeModalTitle';
|
2023-01-27 19:28:03 +01:00
|
|
|
if (editGasMode === EditGasModes.cancel) {
|
2022-01-06 03:47:26 +01:00
|
|
|
popupTitle = 'editCancellationGasFeeModalTitle';
|
2023-01-27 19:28:03 +01:00
|
|
|
} else if (editGasMode === EditGasModes.speedUp) {
|
2022-01-06 03:47:26 +01:00
|
|
|
popupTitle = 'editSpeedUpEditGasFeeModalTitle';
|
|
|
|
}
|
|
|
|
|
2021-11-18 18:54:58 +01:00
|
|
|
return (
|
|
|
|
<Popover
|
2022-01-06 03:47:26 +01:00
|
|
|
title={t(popupTitle)}
|
|
|
|
// below logic ensures that back button is visible only if there are other modals open before this.
|
2022-04-05 15:36:58 +02:00
|
|
|
onBack={
|
|
|
|
openModalCount === 1 ? undefined : () => closeModal(['editGasFee'])
|
|
|
|
}
|
2022-01-06 03:47:26 +01:00
|
|
|
onClose={closeAllModals}
|
2021-11-18 18:54:58 +01:00
|
|
|
className="edit-gas-fee-popover"
|
|
|
|
>
|
|
|
|
<>
|
2022-01-06 03:47:26 +01:00
|
|
|
<AppLoadingSpinner />
|
2021-11-18 18:54:58 +01:00
|
|
|
<div className="edit-gas-fee-popover__wrapper">
|
|
|
|
<div className="edit-gas-fee-popover__content">
|
2022-01-22 01:23:02 +01:00
|
|
|
<Box>
|
|
|
|
{balanceError && (
|
|
|
|
<ErrorMessage errorKey={INSUFFICIENT_FUNDS_ERROR_KEY} />
|
|
|
|
)}
|
|
|
|
<div className="edit-gas-fee-popover__content__header">
|
|
|
|
<span className="edit-gas-fee-popover__content__header-option">
|
2022-07-12 15:59:38 +02:00
|
|
|
{t('gasOption')}
|
2022-01-22 01:23:02 +01:00
|
|
|
</span>
|
|
|
|
<span className="edit-gas-fee-popover__content__header-time">
|
2023-01-27 19:28:03 +01:00
|
|
|
{editGasMode !== EditGasModes.swaps && t('time')}
|
2022-01-22 01:23:02 +01:00
|
|
|
</span>
|
|
|
|
<span className="edit-gas-fee-popover__content__header-max-fee">
|
2022-07-12 15:59:38 +02:00
|
|
|
{t('maxFee')}
|
2022-01-22 01:23:02 +01:00
|
|
|
</span>
|
|
|
|
</div>
|
2023-01-27 19:28:03 +01:00
|
|
|
{(editGasMode === EditGasModes.cancel ||
|
|
|
|
editGasMode === EditGasModes.speedUp) && (
|
2022-01-22 01:23:02 +01:00
|
|
|
<EditGasItem
|
2023-01-27 19:28:03 +01:00
|
|
|
priorityLevel={PriorityLevels.tenPercentIncreased}
|
2022-01-22 01:23:02 +01:00
|
|
|
/>
|
|
|
|
)}
|
2023-01-27 19:28:03 +01:00
|
|
|
{editGasMode === EditGasModes.modifyInPlace && (
|
|
|
|
<EditGasItem priorityLevel={PriorityLevels.low} />
|
2022-01-22 01:23:02 +01:00
|
|
|
)}
|
2023-01-27 19:28:03 +01:00
|
|
|
<EditGasItem priorityLevel={PriorityLevels.medium} />
|
|
|
|
<EditGasItem priorityLevel={PriorityLevels.high} />
|
2022-01-22 01:23:02 +01:00
|
|
|
<div className="edit-gas-fee-popover__content__separator" />
|
2023-01-27 19:28:03 +01:00
|
|
|
{editGasMode === EditGasModes.modifyInPlace && (
|
|
|
|
<EditGasItem priorityLevel={PriorityLevels.dAppSuggested} />
|
2022-01-22 01:23:02 +01:00
|
|
|
)}
|
2023-01-27 19:28:03 +01:00
|
|
|
<EditGasItem priorityLevel={PriorityLevels.custom} />
|
2022-01-22 01:23:02 +01:00
|
|
|
</Box>
|
|
|
|
<Box>
|
|
|
|
<NetworkStatistics />
|
|
|
|
<Typography
|
|
|
|
className="edit-gas-fee-popover__know-more"
|
|
|
|
align="center"
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.textAlternative}
|
|
|
|
tag={TypographyVariant.paragraph}
|
|
|
|
variant={TypographyVariant.H7}
|
2022-01-22 01:23:02 +01:00
|
|
|
>
|
2022-09-22 16:50:05 +02:00
|
|
|
{t('learnMoreAboutGas', [
|
2022-07-12 15:59:38 +02:00
|
|
|
<a
|
|
|
|
key="learnMoreLink"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
2022-08-23 16:19:31 +02:00
|
|
|
href={ZENDESK_URLS.USER_GUIDE_GAS}
|
2022-07-12 15:59:38 +02:00
|
|
|
>
|
|
|
|
{t('learnMore')}
|
|
|
|
</a>,
|
|
|
|
])}
|
2022-01-22 01:23:02 +01:00
|
|
|
</Typography>
|
|
|
|
</Box>
|
2021-11-18 18:54:58 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
</Popover>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default EditGasFeePopover;
|