import React, { useContext } from 'react'; import { useDispatch } from 'react-redux'; import PropTypes from 'prop-types'; import { I18nContext } from '../../../contexts/i18n'; import { BannerAlert } from '../../../components/component-library/banner-alert'; import Box from '../../../components/ui/box'; import { AlignItems, SEVERITIES, Size, TextVariant, } from '../../../helpers/constants/design-system'; import { ButtonLink, Text } from '../../../components/component-library'; import { QUOTES_EXPIRED_ERROR, SWAP_FAILED_ERROR, ERROR_FETCHING_QUOTES, QUOTES_NOT_AVAILABLE_ERROR, CONTRACT_DATA_DISABLED_ERROR, OFFLINE_FOR_MAINTENANCE, SLIPPAGE_OVER_LIMIT_ERROR, SLIPPAGE_VERY_HIGH_ERROR, SLIPPAGE_TOO_LOW_ERROR, SLIPPAGE_NEGATIVE_ERROR, } from '../../../../shared/constants/swaps'; import { setTransactionSettingsOpened } from '../../../ducks/swaps/swaps'; export default function SwapsBannerAlert({ swapsErrorKey }) { const t = useContext(I18nContext); const dispatch = useDispatch(); let severity = SEVERITIES.DANGER; let title; let description; switch (swapsErrorKey) { case SLIPPAGE_OVER_LIMIT_ERROR: title = t('swapSlippageOverLimitTitle'); description = ( {t('swapSlippageOverLimitDescription')} { e.preventDefault(); dispatch(setTransactionSettingsOpened(true)); }} > {t('swapEditTransactionSettings')} ); break; case SLIPPAGE_VERY_HIGH_ERROR: severity = SEVERITIES.WARNING; title = t('swapSlippageVeryHighTitle'); description = ( {t('swapSlippageVeryHighDescription')} ); break; case SLIPPAGE_TOO_LOW_ERROR: severity = SEVERITIES.WARNING; title = t('swapSlippageTooLowTitle'); description = ( {t('swapSlippageTooLowDescription')} ); break; case SLIPPAGE_NEGATIVE_ERROR: title = t('swapSlippageNegativeTitle'); description = ( {t('swapSlippageNegativeDescription')} { e.preventDefault(); dispatch(setTransactionSettingsOpened(true)); }} > {t('swapEditTransactionSettings')} ); break; case QUOTES_NOT_AVAILABLE_ERROR: title = t('swapQuotesNotAvailableErrorTitle'); description = ( {t('swapQuotesNotAvailableDescription')} {t('swapLearnMore')} ); break; case ERROR_FETCHING_QUOTES: title = t('swapFetchingQuotesErrorTitle'); description = ( {t('swapFetchingQuotesErrorDescription')} ); break; case CONTRACT_DATA_DISABLED_ERROR: title = t('swapContractDataDisabledErrorTitle'); description = ( {t('swapContractDataDisabledErrorDescription')} ); break; case QUOTES_EXPIRED_ERROR: title = t('swapQuotesExpiredErrorTitle'); description = ( {t('swapQuotesExpiredErrorDescription')} ); break; case OFFLINE_FOR_MAINTENANCE: title = t('offlineForMaintenance'); description = ( {t('metamaskSwapsOfflineDescription')} ); break; case SWAP_FAILED_ERROR: title = t('swapFailedErrorTitle'); break; default: } return ( {description} ); } SwapsBannerAlert.propTypes = { swapsErrorKey: PropTypes.string, };