import { cn } from "~/lib/utils"; import { Flame, TrendingUp, TrendingDown, Star } from "lucide-react"; import { Button } from "@/routes/ui/button"; import { ChainIcon } from "../components/shared/ChainIcon"; export interface TrendingToken { symbol: string; name: string; chain: string; contractAddress?: string; price: number; priceChange24h: number; priceChange1h?: number; volume24h?: number; liquidity?: number; rank?: number; } export interface TrendingTokensWidgetProps { /** List of trending tokens */ tokens: TrendingToken[]; /** Filter by chain (optional) */ chain?: string; /** Timeframe for trending data */ timeframe?: string; /** Callback when token is clicked */ onTokenClick?: (token: TrendingToken) => void; /** Callback when add to watchlist is clicked */ onAddToWatchlist?: (token: TrendingToken) => void; /** Additional class names */ className?: string; } const formatPrice = (price: number): string => { if (price < 0.00001) return `$${price.toExponential(2)}`; if (price < 1) return `$${price.toFixed(6)}`; return `$${price.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`; }; const formatLargeNumber = (num: number): string => { if (num >= 1e9) return `$${(num / 1e9).toFixed(2)}B`; if (num >= 1e6) return `$${(num / 1e6).toFixed(2)}M`; if (num >= 1e3) return `$${(num / 1e3).toFixed(2)}K`; return `$${num.toFixed(2)}`; }; /** * TrendingTokensWidget - Displays trending/hot tokens inline in chat * Used when AI responds to "what's hot on Solana?" or "show trending tokens" */ export function TrendingTokensWidget({ tokens, chain = "All Chains", timeframe = "24h", onTokenClick, onAddToWatchlist, className, }: TrendingTokensWidgetProps) { return (
{/* Header */}
Trending on {chain} {timeframe}
{/* Token List */} {tokens.length === 0 ? (

No trending tokens found

) : (
{tokens.map((token, index) => (
onTokenClick?.(token)} >
#{token.rank || index + 1}
{token.symbol}
{token.name}

{formatPrice(token.price)}

= 0 ? "text-green-500" : "text-red-500" )}> {token.priceChange24h >= 0 ? ( ) : ( )} {token.priceChange24h >= 0 ? "+" : ""}{token.priceChange24h.toFixed(1)}%

{token.volume24h && (

Vol

{formatLargeNumber(token.volume24h)}

)}
))}
)}
); }