// to be used only when the defaults need to be hard reset
import {
	setSlippage,
	toggleDynamicSlippage,
	updateLocalStorage,
} from "@store/settingsSlice";
import { useEffect } from "react";
import { useDispatch } from "react-redux";

const bungeeLocalStore =
	typeof window !== "undefined"
		? JSON.parse(localStorage.getItem("bungee") || "{}")
		: {};

export const resetUserDefaults = () => {
	const dispatch = useDispatch();
	const defaultSlippageReset = bungeeLocalStore?.settings?.slippageReset0801;

	useEffect(() => {
		if (!defaultSlippageReset && dispatch) {
			dispatch(setSlippage("dynamic"));
			dispatch(toggleDynamicSlippage(true));
			updateLocalStorage("settings", "slippageReset0801", true);
		}
	}, [defaultSlippageReset, dispatch]);
};
