import { useState } from "react"; import type { TokenData } from "../context/PageContextProvider"; import { Button } from "@/routes/ui/button"; import { cn } from "~/lib/utils"; import { TrendingUp, TrendingDown, Shield, Users, AlertTriangle, Star, Copy, Check } from "lucide-react"; import { ChainIcon } from "../components/shared/ChainIcon"; export type QuickActionType = "safety" | "holders" | "predict" | "rug"; export interface EnhancedTokenData extends TokenData { priceChange24h?: number; marketCap?: string; } interface TokenInfoCardProps { tokenData: EnhancedTokenData; /** Whether token is in user's watchlist */ isInWatchlist?: boolean; /** Callback when quick action button is clicked (generic handler) */ onQuickAction?: (action: QuickActionType, tokenData: EnhancedTokenData) => void; /** Callback when watchlist button is clicked */ onToggleWatchlist?: (tokenData: EnhancedTokenData) => void; /** Alternative: Direct callback for add to watchlist */ onAddToWatchlist?: () => void; /** Alternative: Direct callback for safety check */ onSafetyCheck?: () => void; /** Alternative: Direct callback for rug check */ onRugCheck?: () => void; } /** * TokenInfoCard - Enhanced token info card for DexScreener pages * * Features: * - Price with 24h change indicator (▲/▼) * - Market cap display * - Add to watchlist button * - 4 quick actions: Safety, Holders, Predict, Rug Check * - Copy contract address * - Chain-specific icon */ export function TokenInfoCard({ tokenData, isInWatchlist = false, onQuickAction, onToggleWatchlist, onAddToWatchlist, onSafetyCheck, onRugCheck, }: TokenInfoCardProps) { const [copied, setCopied] = useState(false); const handleQuickAction = (action: QuickActionType) => { // Use specific callbacks if provided, otherwise fall back to generic handler if (action === "safety" && onSafetyCheck) { onSafetyCheck(); } else if (action === "rug" && onRugCheck) { onRugCheck(); } else if (onQuickAction) { onQuickAction(action, tokenData); } else { console.log("Quick action:", action, tokenData); } }; const handleCopyAddress = async () => { try { await navigator.clipboard.writeText(tokenData.pairAddress); setCopied(true); setTimeout(() => setCopied(false), 2000); } catch (err) { console.error("Failed to copy address:", err); } }; const handleToggleWatchlist = () => { // Use specific callback if provided, otherwise fall back to generic handler if (onAddToWatchlist) { onAddToWatchlist(); } else if (onToggleWatchlist) { onToggleWatchlist(tokenData); } }; const priceChange = tokenData.priceChange24h; const isPositive = priceChange !== undefined && priceChange > 0; const isNegative = priceChange !== undefined && priceChange < 0; return (
{tokenData.volume24h || "—"}
{tokenData.liquidity || "—"}
{tokenData.marketCap || "—"}
{tokenData.chain}