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';
|
|
|
|
|
2021-11-24 18:02:53 +01:00
|
|
|
import { PRIORITY_LEVELS } from '../../../../shared/constants/gas';
|
2021-11-23 19:18:44 +01:00
|
|
|
import { INSUFFICIENT_FUNDS_ERROR_KEY } from '../../../helpers/constants/error-keys';
|
|
|
|
import { submittedPendingTransactionsSelector } from '../../../selectors/transactions';
|
|
|
|
import { useGasFeeContext } from '../../../contexts/gasFee';
|
2021-11-24 18:02:53 +01:00
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2021-11-23 19:18:44 +01:00
|
|
|
import ActionableMessage from '../../../components/ui/actionable-message/actionable-message';
|
|
|
|
import ErrorMessage from '../../../components/ui/error-message';
|
|
|
|
import I18nValue from '../../../components/ui/i18n-value';
|
2021-11-24 18:02:53 +01:00
|
|
|
import Typography from '../../../components/ui/typography';
|
2021-11-23 19:18:44 +01:00
|
|
|
|
2021-11-24 18:02:53 +01:00
|
|
|
const TransactionAlerts = ({
|
|
|
|
userAcknowledgedGasMissing,
|
|
|
|
setUserAcknowledgedGasMissing,
|
|
|
|
}) => {
|
2021-11-29 17:08:24 +01:00
|
|
|
const {
|
|
|
|
balanceError,
|
|
|
|
estimateUsed,
|
|
|
|
hasSimulationError,
|
|
|
|
supportsEIP1559V2,
|
|
|
|
} = 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
|
|
|
|
2021-11-29 17:08:24 +01:00
|
|
|
if (!supportsEIP1559V2) return null;
|
|
|
|
|
2021-11-23 19:18:44 +01:00
|
|
|
return (
|
|
|
|
<div className="transaction-alerts">
|
2021-11-24 18:02:53 +01:00
|
|
|
{hasSimulationError && (
|
|
|
|
<ActionableMessage
|
|
|
|
message={<I18nValue messageKey="simulationErrorMessageV2" />}
|
|
|
|
useIcon
|
|
|
|
iconFillColor="#d73a49"
|
|
|
|
type="danger"
|
|
|
|
primaryActionV2={
|
|
|
|
userAcknowledgedGasMissing === true
|
|
|
|
? undefined
|
|
|
|
: {
|
|
|
|
label: t('proceedWithTransaction'),
|
|
|
|
onClick: setUserAcknowledgedGasMissing,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)}
|
2021-11-23 19:18:44 +01:00
|
|
|
{pendingTransactions?.length > 0 && (
|
|
|
|
<ActionableMessage
|
|
|
|
message={
|
2021-11-24 18:02:53 +01:00
|
|
|
<Typography
|
|
|
|
className="transaction-alerts__pending-transactions"
|
|
|
|
align="left"
|
|
|
|
fontSize="12px"
|
|
|
|
margin={[0, 0]}
|
|
|
|
>
|
2021-11-23 19:18:44 +01:00
|
|
|
<strong>
|
|
|
|
<I18nValue
|
2021-11-24 18:02:53 +01:00
|
|
|
messageKey={
|
|
|
|
pendingTransactions?.length === 1
|
|
|
|
? 'pendingTransactionSingle'
|
|
|
|
: 'pendingTransactionMultiple'
|
|
|
|
}
|
2021-11-23 19:18:44 +01:00
|
|
|
options={[pendingTransactions?.length]}
|
|
|
|
/>
|
|
|
|
</strong>{' '}
|
|
|
|
<I18nValue messageKey="pendingTransactionInfo" />{' '}
|
|
|
|
<I18nValue
|
|
|
|
messageKey="learnCancelSpeeedup"
|
|
|
|
options={[
|
|
|
|
<a
|
|
|
|
key="cancelSpeedUpInfo"
|
|
|
|
href="https://metamask.zendesk.com/hc/en-us/articles/360015489251-How-to-speed-up-or-cancel-a-pending-transaction"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
<I18nValue messageKey="cancelSpeedUp" />
|
|
|
|
</a>,
|
|
|
|
]}
|
|
|
|
/>
|
2021-11-24 18:02:53 +01:00
|
|
|
</Typography>
|
2021-11-23 19:18:44 +01:00
|
|
|
}
|
|
|
|
useIcon
|
|
|
|
iconFillColor="#f8c000"
|
|
|
|
type="warning"
|
|
|
|
/>
|
|
|
|
)}
|
2021-11-24 18:02:53 +01:00
|
|
|
{balanceError && <ErrorMessage errorKey={INSUFFICIENT_FUNDS_ERROR_KEY} />}
|
|
|
|
{estimateUsed === PRIORITY_LEVELS.LOW && (
|
|
|
|
<ActionableMessage
|
|
|
|
message={
|
|
|
|
<Typography align="left" fontSize="12px" margin={[0, 0]}>
|
|
|
|
<I18nValue messageKey="lowPriorityMessage" />
|
|
|
|
</Typography>
|
|
|
|
}
|
|
|
|
useIcon
|
|
|
|
iconFillColor="#f8c000"
|
|
|
|
type="warning"
|
|
|
|
/>
|
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;
|