diff --git a/src/components/stake-form.tsx b/src/components/stake-form.tsx index 5d7b591..2170e25 100644 --- a/src/components/stake-form.tsx +++ b/src/components/stake-form.tsx @@ -49,6 +49,17 @@ export function StakeForm({ defaultMode = 'stake' }: StakeFormProps) { // Fetch all pools using the new hook const { poolDetails, loading: poolsLoading } = useGetAllPools(); + // Filter pools based on mode: stake mode shows only working pools, unstake shows all + const filteredPools = useMemo(() => { + if (!poolDetails) return null; + if (mode === 'stake') { + // Stake mode: only show working (non-killed) pools + return poolDetails.filter(pool => !pool.isKilled); + } + // Unstake mode: show all pools (working + killed) + return poolDetails; + }, [poolDetails, mode]); + // Get token details for the user const { tokenDetails, loading: tokensLoading } = useTokenDetails(address); @@ -190,6 +201,14 @@ export function StakeForm({ defaultMode = 'stake' }: StakeFormProps) { fetchTokenDetails(); }, [publicClient, selectedPool, mode, redeemAll]); + // Auto-enable Redeem All for killed pools in unstake mode + useEffect(() => { + if (mode === 'unstake' && selectedPool?.isKilled) { + setRedeemAll(true); + setSelectedToken(null); // Clear token selection for killed pools + } + }, [mode, selectedPool]); + // Close dropdowns when clicking outside useEffect(() => { const handleClickOutside = (event: MouseEvent) => { @@ -329,8 +348,8 @@ export function StakeForm({ defaultMode = 'stake' }: StakeFormProps) { {isPoolDropdownOpen && (
- {poolDetails && poolDetails.length > 0 ? ( - poolDetails.map((pool) => ( + {filteredPools && filteredPools.length > 0 ? ( + filteredPools.map((pool) => ( {isPoolDropdownOpen && (
- {poolDetails && poolDetails.length > 0 ? ( - poolDetails.map((pool) => ( + {filteredPools && filteredPools.length > 0 ? ( + filteredPools.map((pool) => ( diff --git a/src/hooks/usePartyPlanner.ts b/src/hooks/usePartyPlanner.ts index 0364c5d..c8f3bf2 100644 --- a/src/hooks/usePartyPlanner.ts +++ b/src/hooks/usePartyPlanner.ts @@ -379,6 +379,7 @@ export interface PoolDetails { tokens: readonly `0x${string}`[]; price?: string; // Formatted price string tvl?: string; // Formatted TVL string (e.g., "$1.2M") + isKilled: boolean; // Whether the pool has been killed } export function useGetAllPools(offset: number = 0, limit: number = 100) { @@ -457,10 +458,12 @@ export function useGetAllPools(offset: number = 0, limit: number = 100) { }).catch(() => false), ]); - // Only add pool if it's working + // Fetch pool price and TVL (only for working pools) + let priceStr: string | undefined; + let tvlStr: string | undefined; + if (isWorking) { // Fetch pool price (use first token as quote, index 0) - let priceStr: string | undefined; try { const priceRaw = await publicClient.readContract({ address: partyInfoAddress as `0x${string}`, @@ -489,7 +492,6 @@ export function useGetAllPools(offset: number = 0, limit: number = 100) { } // Calculate TVL (approximate by getting first token balance and doubling it) - let tvlStr: string | undefined; try { if (tokens && tokens.length > 0) { const firstTokenAddress = tokens[0]; @@ -519,16 +521,18 @@ export function useGetAllPools(offset: number = 0, limit: number = 100) { console.error(`Error fetching TVL for ${poolAddress}:`, err); tvlStr = undefined; } - - details.push({ - address: poolAddress, - name: name as string, - symbol: symbol as string, - tokens: tokens as readonly `0x${string}`[], - price: priceStr, - tvl: tvlStr, - }); } + + // Add all pools (both working and killed) + details.push({ + address: poolAddress, + name: name as string, + symbol: symbol as string, + tokens: tokens as readonly `0x${string}`[], + price: priceStr, + tvl: tvlStr, + isKilled: !isWorking, + }); } catch (err) { console.error('Error fetching pool details for', poolAddress, err); // Skip pools that fail to load