import { cn } from "~/lib/utils"; import { Zap, TrendingUp, TrendingDown, RefreshCw, ExternalLink } from "lucide-react"; import { Button } from "@/routes/ui/button"; import { ChainIcon } from "../components/shared/ChainIcon"; export interface LiveTokenPriceData { chain: string; tokenAddress: string; tokenSymbol?: string; tokenName?: string; priceUsd?: string; priceNative?: string; priceChange5m?: number; priceChange1h?: number; priceChange6h?: number; priceChange24h?: number; volume24h?: number; liquidityUsd?: number; marketCap?: number; fdv?: number; dex?: string; pairUrl?: string; error?: string; } export interface LiveTokenPriceWidgetProps { /** Live token price data */ data: LiveTokenPriceData; /** Whether data is loading */ isLoading?: boolean; /** Callback when view on DexScreener is clicked */ onViewDexScreener?: () => void; /** Additional class names */ className?: string; } const formatPrice = (price: string | undefined): string => { if (!price || price === "N/A") return "N/A"; const num = parseFloat(price); if (isNaN(num)) return price; if (num < 0.00001) return `$${num.toExponential(2)}`; if (num < 1) return `$${num.toFixed(6)}`; return `$${num.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`; }; const PriceChange = ({ value, label }: { value: number | undefined; label: string }) => { if (value === undefined || value === null) return null; const isPositive = value >= 0; return (

{label}

{isPositive ? "+" : ""}{value.toFixed(2)}%

); }; /** * LiveTokenPriceWidget - Displays real-time token price inline in chat * Used when AI fetches current/live price data */ export function LiveTokenPriceWidget({ data, isLoading = false, onViewDexScreener, className, }: LiveTokenPriceWidgetProps) { const handleOpenDexScreener = () => { if (onViewDexScreener) { onViewDexScreener(); } else if (data.pairUrl) { window.open(data.pairUrl, "_blank"); } else if (data.tokenAddress) { window.open(`https://dexscreener.com/${data.chain}/${data.tokenAddress}`, "_blank"); } }; return (
{/* Header */}
Live Price {isLoading ? ( Fetching... ) : ( Real-time )}
{data.error ? (
⚠️ {data.error}
) : ( <> {/* Token Header */}
{data.tokenSymbol || "Token"} {data.tokenName && ( {data.tokenName} )}
{formatPrice(data.priceUsd)} {data.priceChange24h !== undefined && ( = 0 ? "text-green-500" : "text-red-500" )}> {data.priceChange24h >= 0 ? ( ) : ( )} {data.priceChange24h >= 0 ? "+" : ""}{data.priceChange24h.toFixed(2)}% )}
{/* Price Changes */}
{/* Action */} )}
); }