import React, { useContext, useState } from 'react'; import { I18nContext } from '../../../contexts/i18n'; import { FlexDirection, Display, JustifyContent, AlignItems, } from '../../../helpers/constants/design-system'; import { Modal, ModalContent, ModalHeader, ModalOverlay, Box, ButtonPrimary, } from '../../../components/component-library'; import { SLIPPAGE_HIGH_ERROR, SLIPPAGE_LOW_ERROR, } from '../../../../shared/constants/swaps'; import SwapsBannerAlert from '../swaps-banner-alert/swaps-banner-alert'; interface Props { isOpen: boolean; slippageErrorKey: string; setSlippageNotificationModalOpened: (isOpen: boolean) => void; onSwapSubmit: (opts: { acknowledgedSlippage: boolean }) => void; currentSlippage: number; } export default function SlippageNotificationModal({ isOpen, slippageErrorKey, setSlippageNotificationModalOpened, onSwapSubmit, currentSlippage, }: Props) { const t = useContext(I18nContext); const [submitting, setSubmitting] = useState(false); const getSlippageModalTitle = () => { if (slippageErrorKey === SLIPPAGE_HIGH_ERROR) { return t('swapHighSlippage'); } else if (slippageErrorKey === SLIPPAGE_LOW_ERROR) { return t('swapLowSlippage'); } return ''; }; const primaryButtonText = submitting ? t('preparingSwap') : t('swapAnyway'); return ( setSlippageNotificationModalOpened(false)} isOpen={isOpen} isClosedOnOutsideClick isClosedOnEscapeKey className="mm-modal__custom-scrollbar" > setSlippageNotificationModalOpened(false)}> {getSlippageModalTitle()} { setSubmitting(true); onSwapSubmit({ acknowledgedSlippage: true }); }} block data-testid="high-slippage-continue-anyway" disabled={submitting} > {primaryButtonText} ); }