1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 10:30:04 +01:00
metamask-extension/ui/components/app/transaction-alerts/transaction-alerts.js

78 lines
2.6 KiB
JavaScript
Raw Normal View History

2021-11-23 19:18:44 +01:00
import React from 'react';
import PropTypes from 'prop-types';
2021-11-23 19:18:44 +01:00
import { useSelector } from 'react-redux';
import { PriorityLevels } from '../../../../shared/constants/gas';
import { submittedPendingTransactionsSelector } from '../../../selectors';
2021-11-23 19:18:44 +01:00
import { useGasFeeContext } from '../../../contexts/gasFee';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { BannerAlert, ButtonLink, Text } from '../../component-library';
import SimulationErrorMessage from '../../ui/simulation-error-message';
import { SEVERITIES } from '../../../helpers/constants/design-system';
import ZENDESK_URLS from '../../../helpers/constants/zendesk-url';
2021-11-23 19:18:44 +01:00
const TransactionAlerts = ({
userAcknowledgedGasMissing,
setUserAcknowledgedGasMissing,
}) => {
const { estimateUsed, hasSimulationError, supportsEIP1559, isNetworkBusy } =
useGasFeeContext();
2021-11-23 19:18:44 +01:00
const pendingTransactions = useSelector(submittedPendingTransactionsSelector);
const t = useI18nContext();
2021-11-23 19:18:44 +01:00
return (
<div className="transaction-alerts">
{supportsEIP1559 && hasSimulationError && (
<SimulationErrorMessage
userAcknowledgedGasMissing={userAcknowledgedGasMissing}
setUserAcknowledgedGasMissing={setUserAcknowledgedGasMissing}
/>
)}
{supportsEIP1559 && pendingTransactions?.length > 0 && (
<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
)}
{estimateUsed === PriorityLevels.low && (
<BannerAlert
data-testid="low-gas-fee-alert"
severity={SEVERITIES.WARNING}
>
{t('lowPriorityMessage')}
</BannerAlert>
2021-11-23 19:18:44 +01:00
)}
{supportsEIP1559 && isNetworkBusy ? (
<BannerAlert severity={SEVERITIES.WARNING}>
{t('networkIsBusy')}
</BannerAlert>
) : null}
2021-11-23 19:18:44 +01:00
</div>
);
};
TransactionAlerts.propTypes = {
userAcknowledgedGasMissing: PropTypes.bool,
setUserAcknowledgedGasMissing: PropTypes.func,
};
2021-11-23 19:18:44 +01:00
export default TransactionAlerts;