Skip to content

Commit

Permalink
refactor: improve redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
ogous committed Aug 15, 2024
1 parent edc2537 commit 7a58c81
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions web/src/components/ConfirmSwap.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7a58c81

Please sign in to comment.