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

121 lines
3.8 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 { PRIORITY_LEVELS } from '../../../../shared/constants/gas';
2021-11-23 19:18:44 +01:00
import { submittedPendingTransactionsSelector } from '../../../selectors/transactions';
import { useGasFeeContext } from '../../../contexts/gasFee';
import { useI18nContext } from '../../../hooks/useI18nContext';
import ActionableMessage from '../../ui/actionable-message/actionable-message';
import Typography from '../../ui/typography';
import { TYPOGRAPHY } 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 && (
<ActionableMessage
message={t('simulationErrorMessageV2')}
useIcon
iconFillColor="var(--color-error-default)"
type="danger"
primaryActionV2={
userAcknowledgedGasMissing === true
? undefined
: {
label: t('proceedWithTransaction'),
onClick: setUserAcknowledgedGasMissing,
}
}
/>
)}
{supportsEIP1559 && pendingTransactions?.length > 0 && (
2021-11-23 19:18:44 +01:00
<ActionableMessage
message={
<Typography
align="left"
className="transaction-alerts__pending-transactions"
margin={0}
tag={TYPOGRAPHY.Paragraph}
variant={TYPOGRAPHY.H7}
>
2021-11-23 19:18:44 +01:00
<strong>
{pendingTransactions?.length === 1
? t('pendingTransactionSingle', [pendingTransactions?.length])
: t('pendingTransactionMultiple', [
pendingTransactions?.length,
])}
2021-11-23 19:18:44 +01:00
</strong>{' '}
{t('pendingTransactionInfo')}
{t('learnCancelSpeeedup', [
<a
key="cancelSpeedUpInfo"
href={ZENDESK_URLS.SPEEDUP_CANCEL}
rel="noopener noreferrer"
target="_blank"
>
{t('cancelSpeedUp')}
</a>,
])}
</Typography>
2021-11-23 19:18:44 +01:00
}
useIcon
iconFillColor="var(--color-warning-default)"
2021-11-23 19:18:44 +01:00
type="warning"
/>
)}
{estimateUsed === PRIORITY_LEVELS.LOW && (
<ActionableMessage
dataTestId="low-gas-fee-alert"
message={
<Typography
align="left"
margin={0}
tag={TYPOGRAPHY.Paragraph}
variant={TYPOGRAPHY.H7}
>
{t('lowPriorityMessage')}
</Typography>
}
useIcon
iconFillColor="var(--color-warning-default)"
type="warning"
/>
2021-11-23 19:18:44 +01:00
)}
{supportsEIP1559 && isNetworkBusy ? (
<ActionableMessage
message={
<Typography
align="left"
margin={0}
tag={TYPOGRAPHY.Paragraph}
variant={TYPOGRAPHY.H7}
>
{t('networkIsBusy')}
</Typography>
}
iconFillColor="var(--color-warning-default)"
type="warning"
useIcon
/>
) : 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;