import { XMarkIcon } from '@heroicons/react/20/solid' import { useTranslation } from 'next-i18next' import { useEffect, useRef, useState } from 'react' import mangoStore from '@store/mangoStore' import ButtonGroup from '../forms/ButtonGroup' import Input from '../forms/Input' import Button, { IconButton, LinkButton } from '../shared/Button' const slippagePresets = ['0.1', '0.5', '1', '2'] const SwapSettings = ({ onClose }: { onClose: () => void }) => { const { t } = useTranslation(['common', 'settings', 'swap']) const slippage = mangoStore((s) => s.swap.slippage) const set = mangoStore((s) => s.set) const focusRef = useRef(null) const [showCustomSlippageForm, setShowCustomSlippageForm] = useState(false) const [inputValue, setInputValue] = useState(slippage.toString()) useEffect(() => { if (!slippagePresets.includes(slippage.toString())) { setShowCustomSlippageForm(true) } }, []) const handleSetSlippage = (slippage: string, close?: boolean) => { set((s) => { s.swap.slippage = parseFloat(slippage) }) if (close) { onClose() } } useEffect(() => { if (focusRef?.current) { focusRef.current.focus() } }, [focusRef]) return ( <>

{t('settings')}

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

setShowCustomSlippageForm(!showCustomSlippageForm)} > {showCustomSlippageForm ? t('swap:preset') : t('settings:custom')}
{showCustomSlippageForm ? ( <> setInputValue(e.target.value)} suffix="%" /> ) : ( <> handleSetSlippage(v)} unit="%" values={slippagePresets} /> )}
) } export default SwapSettings