import { useEffect, useState } from 'react' import Modal from './Modal' import { useTranslation } from 'next-i18next' import Button from './Button' import ButtonGroup from './ButtonGroup' import Input, { Label } from './Input' import { LinkButton } from './Button' const slippagePresets = ['0.1', '0.5', '1', '2'] const SwapSettingsModal = ({ isOpen, onClose, slippage, setSlippage, }: { isOpen: boolean onClose?: () => void slippage: number setSlippage: (x) => void }) => { const { t } = useTranslation(['common', 'swap']) const [tempSlippage, setTempSlippage] = useState(slippage) const [inputValue, setInputValue] = useState( tempSlippage ? tempSlippage.toString() : '' ) const [showCustomSlippageForm, setShowCustomSlippageForm] = useState(false) const handleSetTempSlippage = (s) => { setTempSlippage(s) setInputValue('') } const handleSave = () => { setSlippage(inputValue ? parseFloat(inputValue) : tempSlippage) onClose() } useEffect(() => { if (!slippagePresets.includes(tempSlippage.toString())) { setShowCustomSlippageForm(true) } }, []) return (

{t('swap:slippage-settings')}

setShowCustomSlippageForm(!showCustomSlippageForm)} > {showCustomSlippageForm ? t('presets') : t('custom')}
{showCustomSlippageForm ? ( setInputValue(e.target.value)} suffix="%" /> ) : ( handleSetTempSlippage(v)} unit="%" values={slippagePresets} /> )}
) } export default SwapSettingsModal