From 7a58c810792a515cd6a7e2625771cb99360cf322 Mon Sep 17 00:00:00 2001 From: ogous Date: Fri, 16 Aug 2024 00:12:09 +0300 Subject: [PATCH] refactor: improve redirect --- web/src/components/ConfirmSwap.tsx | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/web/src/components/ConfirmSwap.tsx b/web/src/components/ConfirmSwap.tsx index e37427ac..96e19f50 100644 --- a/web/src/components/ConfirmSwap.tsx +++ b/web/src/components/ConfirmSwap.tsx @@ -1,7 +1,7 @@ "use client"; import { Button } from "@/components/ui/button"; -import { useRouter } from "next/navigation"; +import { redirect, useRouter } from "next/navigation"; import { cn } from "@/lib/utils"; import { useSwapStore } from "@/stores/useSwapStore"; import { motion } from "framer-motion"; @@ -39,10 +39,6 @@ export const ConfirmSwap = () => { const { address, chainId } = useAccount(); const expectedChainId = useChainId(); - useEffect(() => { - if (!address || chainId !== expectedChainId) router.back(); - }, [address, expectedChainId, chainId]); - const { token0, token1, @@ -54,6 +50,9 @@ export const ConfirmSwap = () => { gas, } = useSwapStore(); + if (!address || chainId !== expectedChainId || !(token0 && token0Amount)) + redirect("/"); + // price of the current pool const { data: token0SqrtPriceX96 } = useSimulateContract({ address: ammAddress, @@ -155,13 +154,6 @@ export const ConfirmSwap = () => { return snapAmountToDecimals(Number(token1Price) / Number(token0Price)); }, [isSwappingBaseAsset, isSwap1, token0Price, token1Price, token1]); - // if no token or no token amount redirect to the swap form - useEffect(() => { - if (token0 && token0Amount) return; - - router.push("/"); - }, [router, token0, token0Amount]); - // read the allowance of the token const { data: allowanceData } = useSimulateContract({ address: token0.address,