2021-11-23 19:18:44 +01:00
|
|
|
import React from 'react';
|
2021-11-24 18:02:53 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2021-11-23 19:18:44 +01:00
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
|
2023-01-27 19:28:03 +01:00
|
|
|
import { PriorityLevels } from '../../../../shared/constants/gas';
|
|
|
|
import { submittedPendingTransactionsSelector } from '../../../selectors';
|
2021-11-23 19:18:44 +01:00
|
|
|
import { useGasFeeContext } from '../../../contexts/gasFee';
|
2021-11-24 18:02:53 +01:00
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2023-07-20 00:32:35 +02:00
|
|
|
import { BannerAlert, ButtonLink, Text } from '../../component-library';
|
2023-02-02 00:14:09 +01:00
|
|
|
import SimulationErrorMessage from '../../ui/simulation-error-message';
|
2023-03-13 20:29:10 +01:00
|
|
|
import { SEVERITIES } from '../../../helpers/constants/design-system';
|
2022-08-23 16:19:31 +02:00
|
|
|
import ZENDESK_URLS from '../../../helpers/constants/zendesk-url';
|
2021-11-23 19:18:44 +01:00
|
|
|
|
2021-11-24 18:02:53 +01:00
|
|
|
const TransactionAlerts = ({
|
|
|
|
userAcknowledgedGasMissing,
|
|
|
|
setUserAcknowledgedGasMissing,
|
|
|
|
}) => {
|
2022-12-08 19:37:06 +01:00
|
|
|
const { estimateUsed, hasSimulationError, supportsEIP1559, isNetworkBusy } =
|
2022-11-09 16:36:21 +01:00
|
|
|
useGasFeeContext();
|
2021-11-23 19:18:44 +01:00
|
|
|
const pendingTransactions = useSelector(submittedPendingTransactionsSelector);
|
2021-11-24 18:02:53 +01:00
|
|
|
const t = useI18nContext();
|
2021-11-23 19:18:44 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="transaction-alerts">
|
2022-12-08 19:37:06 +01:00
|
|
|
{supportsEIP1559 && hasSimulationError && (
|
2023-02-02 00:14:09 +01:00
|
|
|
<SimulationErrorMessage
|
|
|
|
userAcknowledgedGasMissing={userAcknowledgedGasMissing}
|
|
|
|
setUserAcknowledgedGasMissing={setUserAcknowledgedGasMissing}
|
2021-11-24 18:02:53 +01:00
|
|
|
/>
|
|
|
|
)}
|
2022-12-08 19:37:06 +01:00
|
|
|
{supportsEIP1559 && pendingTransactions?.length > 0 && (
|
2023-03-13 20:29:10 +01:00
|
|
|
<BannerAlert severity={SEVERITIES.WARNING}>
|
|
|
|
<Text as="p">
|
|
|
|
<strong>
|
|
|
|
{pendingTransactions?.length === 1
|
|
|
|
? t('pendingTransactionSingle', [pendingTransactions?.length])
|
|
|
|
: t('pendingTransactionMultiple', [
|
|
|
|
pendingTransactions?.length,
|
|
|
|
])}
|
|
|
|
</strong>{' '}
|
|
|
|
{t('pendingTransactionInfo')}
|
|
|
|
{t('learnCancelSpeeedup', [
|
|
|
|
<ButtonLink
|
|
|
|
key="cancelSpeedUpInfo"
|
|
|
|
href={ZENDESK_URLS.SPEEDUP_CANCEL}
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
{t('cancelSpeedUp')}
|
|
|
|
</ButtonLink>,
|
|
|
|
])}
|
|
|
|
</Text>
|
|
|
|
</BannerAlert>
|
2021-11-23 19:18:44 +01:00
|
|
|
)}
|
2023-01-27 19:28:03 +01:00
|
|
|
{estimateUsed === PriorityLevels.low && (
|
2023-03-13 20:29:10 +01:00
|
|
|
<BannerAlert
|
|
|
|
data-testid="low-gas-fee-alert"
|
|
|
|
severity={SEVERITIES.WARNING}
|
|
|
|
>
|
|
|
|
{t('lowPriorityMessage')}
|
|
|
|
</BannerAlert>
|
2021-11-23 19:18:44 +01:00
|
|
|
)}
|
2022-12-08 19:37:06 +01:00
|
|
|
{supportsEIP1559 && isNetworkBusy ? (
|
2023-03-13 20:29:10 +01:00
|
|
|
<BannerAlert severity={SEVERITIES.WARNING}>
|
|
|
|
{t('networkIsBusy')}
|
|
|
|
</BannerAlert>
|
2022-01-07 20:18:02 +01:00
|
|
|
) : null}
|
2021-11-23 19:18:44 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-11-24 18:02:53 +01:00
|
|
|
TransactionAlerts.propTypes = {
|
|
|
|
userAcknowledgedGasMissing: PropTypes.bool,
|
|
|
|
setUserAcknowledgedGasMissing: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
2021-11-23 19:18:44 +01:00
|
|
|
export default TransactionAlerts;
|