diff --git a/src/components/SettingsDialog/SlippageSetting.tsx b/src/components/SettingsDialog/SlippageSetting.tsx index 65a3a48f..eec25168 100644 --- a/src/components/SettingsDialog/SlippageSetting.tsx +++ b/src/components/SettingsDialog/SlippageSetting.tsx @@ -1,43 +1,88 @@ import * as ToggleGroup from "@radix-ui/react-toggle-group"; import { clsx } from "clsx"; -import { ComponentProps } from "react"; +import { ComponentProps, useEffect, useRef, useState } from "react"; -import { useSettingsStore } from "@/context/settings"; +import { defaultValues, useSettingsStore } from "@/context/settings"; -const OPTION_VALUES = ["1", "2.5", "3", "5"]; +const OPTION_VALUES = ["1", "3", "5"]; export const SlippageSetting = ({ className, ...props }: ComponentProps<"div">) => { const currentValue = useSettingsStore((state) => state.slippage); + + const [custom, setCustom] = useState(() => false); + + const toggleCustom = () => + setCustom((prev) => { + const latest = !prev; + if (!latest) { + useSettingsStore.setState({ slippage: defaultValues.slippage }); + } + return latest; + }); + + const ref = useRef(null); + useEffect(() => { + if (custom) ref.current?.focus(); + }, [custom]); + return ( -
+

Slippage

- { + useSettingsStore.setState({ slippage: event.target.value }); + }} + ref={ref} + /> + ) : ( + + {OPTION_VALUES.map((value, i) => ( + useSettingsStore.setState({ slippage: value })} + > + {value}% + + ))} + + )} +
); };