From f9e7ccce1b4ec9db20ec6a49d34d04648b9ee3d7 Mon Sep 17 00:00:00 2001 From: Alec Ananian <1013230+alecananian@users.noreply.github.com> Date: Fri, 3 Jan 2025 10:13:54 -0800 Subject: [PATCH] reuse withdraw prompt on unstake --- app/components/pools/PoolIncentiveUnstake.tsx | 59 ++----------------- app/routes/pools_.$id.tsx | 6 +- 2 files changed, 11 insertions(+), 54 deletions(-) diff --git a/app/components/pools/PoolIncentiveUnstake.tsx b/app/components/pools/PoolIncentiveUnstake.tsx index 43dc646..614a064 100644 --- a/app/components/pools/PoolIncentiveUnstake.tsx +++ b/app/components/pools/PoolIncentiveUnstake.tsx @@ -1,59 +1,33 @@ import { useCallback, useState } from "react"; -import { type Address, formatEther, parseEther, parseUnits } from "viem"; +import { parseEther } from "viem"; -import type { SerializeFrom } from "@remix-run/node"; -import { useRouteLoaderData } from "@remix-run/react"; import { useAccount } from "~/contexts/account"; -import { useTokenBalance } from "~/hooks/useTokenBalance"; import { useUnstake } from "~/hooks/useUnstake"; -import { useWithdrawBatch } from "~/hooks/useWithdrawBatch"; import type { Pool } from "~/lib/pools.server"; -import type { loader } from "~/routes/pools_.$id"; import type { NumberString } from "~/types"; -import { SelectionPopup } from "../SelectionPopup"; import { TransactionButton } from "../ui/Button"; -import { Dialog } from "../ui/Dialog"; import { PoolInput } from "./PoolInput"; type Props = { pool: Pool; staked: bigint; + onSuccess?: () => void; }; -export const PoolIncentiveUnstake = ({ pool, staked }: Props) => { - const { poolIncentives } = useRouteLoaderData( - "routes/pools_.$id", - ) as SerializeFrom; - const [isClaimDialogOpen, setIsClaimDialogOpen] = useState(false); - - const nftIncentive = [...poolIncentives] - .sort((a, b) => Number(b.startTime) - Number(a.startTime)) - .find((poolIncentive) => poolIncentive.rewardToken?.isNFT); - +export const PoolIncentiveUnstake = ({ pool, staked, onSuccess }: Props) => { const [rawAmount, setRawAmount] = useState("0"); - const { isConnected, address } = useAccount(); + const { isConnected } = useAccount(); const amount = parseEther(rawAmount as NumberString); const hasAmount = amount > 0; - const { withdrawBatch, isLoading } = useWithdrawBatch({ - vaultAddress: nftIncentive?.rewardTokenAddress as Address | undefined, - }); - - const { data: nftRewardsBalance, refetch: nftRewardsRefetch } = - useTokenBalance({ - id: nftIncentive?.rewardTokenAddress as Address | undefined, - address, - }); - const { unstake } = useUnstake({ pool, amount, onSuccess: useCallback(() => { setRawAmount("0"); - nftRewardsRefetch(); - setIsClaimDialogOpen(true); - }, [nftRewardsRefetch]), + onSuccess?.(); + }, [onSuccess]), }); return ( @@ -73,27 +47,6 @@ export const PoolIncentiveUnstake = ({ pool, staked }: Props) => { > Unstake - {nftIncentive?.rewardToken && ( - {}}> - { - await withdrawBatch( - tokens.map((token) => ({ - id: BigInt(token.tokenId), - amount: BigInt(token.quantity), - collectionId: token.collectionAddr as Address, - })), - ); - setIsClaimDialogOpen(false); - }} - isSubmitDisabled={isLoading} - keepOpenOnSubmit - requiredAmount={Number(formatEther(nftRewardsBalance))} - /> - - )} ); }; diff --git a/app/routes/pools_.$id.tsx b/app/routes/pools_.$id.tsx index deee1f5..3564898 100644 --- a/app/routes/pools_.$id.tsx +++ b/app/routes/pools_.$id.tsx @@ -863,7 +863,11 @@ const PoolManagementView = ({ /> ) : null} {tab === "unstake" ? ( - + ) : null} );