import React from 'react';
import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import { PRIORITY_LEVELS } from '../../../../shared/constants/gas';
import { submittedPendingTransactionsSelector } from '../../../selectors/transactions';
import { useGasFeeContext } from '../../../contexts/gasFee';
import { useI18nContext } from '../../../hooks/useI18nContext';
import ActionableMessage from '../../../components/ui/actionable-message/actionable-message';
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';
const TransactionAlerts = ({
userAcknowledgedGasMissing,
setUserAcknowledgedGasMissing,
isBuyableChain,
nativeCurrency,
networkName,
showBuyModal,
type,
}) => {
const {
balanceError,
estimateUsed,
hasSimulationError,
supportsEIP1559V2,
isNetworkBusy,
} = useGasFeeContext();
const pendingTransactions = useSelector(submittedPendingTransactionsSelector);
const t = useI18nContext();
if (!supportsEIP1559V2) {
return null;
}
return (
{hasSimulationError && (
)}
{pendingTransactions?.length > 0 && (
{pendingTransactions?.length === 1
? t('pendingTransactionSingle', [pendingTransactions?.length])
: t('pendingTransactionMultiple', [
pendingTransactions?.length,
])}
{' '}
{t('pendingTransactionInfo')}
{t('learnCancelSpeeedup', [
{t('cancelSpeedUp')}
,
])}
}
useIcon
iconFillColor="var(--color-warning-default)"
type="warning"
/>
)}
{balanceError && type === TRANSACTION_TYPES.DEPLOY_CONTRACT ? (
{t('insufficientCurrencyBuyOrDeposit', [
nativeCurrency,
networkName,
,
])}
) : (
{t('insufficientCurrencyDeposit', [
nativeCurrency,
networkName,
])}
)
}
useIcon
iconFillColor="var(--color-error-default)"
type="danger"
/>
) : null}
{estimateUsed === PRIORITY_LEVELS.LOW && (
{t('lowPriorityMessage')}
}
useIcon
iconFillColor="var(--color-warning-default)"
type="warning"
/>
)}
{isNetworkBusy ? (
{t('networkIsBusy')}
}
iconFillColor="var(--color-warning-default)"
type="warning"
useIcon
/>
) : null}
);
};
TransactionAlerts.propTypes = {
userAcknowledgedGasMissing: PropTypes.bool,
setUserAcknowledgedGasMissing: PropTypes.func,
nativeCurrency: PropTypes.string,
networkName: PropTypes.string,
showBuyModal: PropTypes.func,
type: PropTypes.string,
isBuyableChain: PropTypes.bool,
};
export default TransactionAlerts;