1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 04:46:10 +01:00
metamask-extension/ui/pages/confirm-transaction-base/transaction-alerts/transaction-alerts.js

181 lines
5.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 { 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';
2021-11-23 19:18:44 +01:00
import ActionableMessage from '../../../components/ui/actionable-message/actionable-message';
import I18nValue from '../../../components/ui/i18n-value';
import Button from '../../../components/ui/button';
import Typography from '../../../components/ui/typography';
import { TYPOGRAPHY } from '../../../helpers/constants/design-system';
import { TRANSACTION_TYPES } from '../../../../shared/constants/transaction';
2021-11-23 19:18:44 +01:00
const TransactionAlerts = ({
userAcknowledgedGasMissing,
setUserAcknowledgedGasMissing,
isBuyableChain,
nativeCurrency,
networkName,
showBuyModal,
type,
}) => {
const {
balanceError,
estimateUsed,
hasSimulationError,
supportsEIP1559V2,
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
if (!supportsEIP1559V2) {
return null;
}
2021-11-23 19:18:44 +01:00
return (
<div className="transaction-alerts">
{hasSimulationError && (
<ActionableMessage
message={<I18nValue messageKey="simulationErrorMessageV2" />}
useIcon
iconFillColor="var(--color-error-default)"
type="danger"
primaryActionV2={
userAcknowledgedGasMissing === true
? undefined
: {
label: t('proceedWithTransaction'),
onClick: setUserAcknowledgedGasMissing,
}
}
/>
)}
2021-11-23 19:18:44 +01:00
{pendingTransactions?.length > 0 && (
<ActionableMessage
message={
<Typography
align="left"
className="transaction-alerts__pending-transactions"
margin={[0, 0]}
tag={TYPOGRAPHY.Paragraph}
variant={TYPOGRAPHY.H7}
>
2021-11-23 19:18:44 +01:00
<strong>
<I18nValue
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>,
]}
/>
</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"
/>
)}
{balanceError && type === TRANSACTION_TYPES.DEPLOY_CONTRACT ? (
<ActionableMessage
className="actionable-message--warning"
message={
isBuyableChain ? (
<Typography variant={TYPOGRAPHY.H7} align="left">
{t('insufficientCurrencyBuyOrDeposit', [
nativeCurrency,
networkName,
<Button
type="inline"
className="confirm-page-container-content__link"
onClick={showBuyModal}
key={`${nativeCurrency}-buy-button`}
>
{t('buyAsset', [nativeCurrency])}
</Button>,
])}
</Typography>
) : (
<Typography variant={TYPOGRAPHY.H7} align="left">
{t('insufficientCurrencyDeposit', [
nativeCurrency,
networkName,
])}
</Typography>
)
}
useIcon
iconFillColor="var(--color-error-default)"
type="danger"
/>
) : null}
{estimateUsed === PRIORITY_LEVELS.LOW && (
<ActionableMessage
dataTestId="low-gas-fee-alert"
message={
<Typography
align="left"
margin={[0, 0]}
tag={TYPOGRAPHY.Paragraph}
variant={TYPOGRAPHY.H7}
>
<I18nValue messageKey="lowPriorityMessage" />
</Typography>
}
useIcon
iconFillColor="var(--color-warning-default)"
type="warning"
/>
2021-11-23 19:18:44 +01:00
)}
{isNetworkBusy ? (
<ActionableMessage
message={
<Typography
align="left"
margin={[0, 0]}
tag={TYPOGRAPHY.Paragraph}
variant={TYPOGRAPHY.H7}
>
<I18nValue messageKey="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,
nativeCurrency: PropTypes.string,
networkName: PropTypes.string,
showBuyModal: PropTypes.func,
type: PropTypes.string,
isBuyableChain: PropTypes.bool,
};
2021-11-23 19:18:44 +01:00
export default TransactionAlerts;