'use client'; import { useState } from 'react'; import { motion } from 'framer-motion'; import { ArrowUpRight, ArrowDownRight, TrendingUp, AlertTriangle, ChevronUp } from 'lucide-react'; import { useDataKeys } from '@/hooks/useDataStore'; export default function GlobalTicker() { const { stocks, financial_source } = useDataKeys(['stocks', 'financial_source'] as const); const entries = Object.entries(stocks || {}); const fallback = financial_source === 'yfinance'; if (entries.length === 0) return null; // Render a single ticker item const renderItem = ([ticker, info]: [string, any], index: number) => { // Determine color based on price action let colorClass = 'text-white'; if (info.change_percent > 0) colorClass = 'text-green-400'; if (info.change_percent < 0) colorClass = 'text-red-400'; const isCryptoHighlight = ticker === 'BTC' || ticker === 'ETH'; return (
{isCryptoHighlight && } {ticker} ${(info.price ?? 0).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })} {info.up ? : info.change_percent < 0 ? : } {Math.abs(info.change_percent ?? 0).toFixed(2)}%
); }; return (
{fallback && (
SYS WARN: FINNHUB API KEY MISSING — YAHOO FALLBACK ACTIVE (LIMITED)
)} {/* The scrolling container */} {/* Render the list twice for seamless infinite scrolling */}
{entries.map((item, i) => renderItem(item, i))}
{entries.map((item, i) => renderItem(item, i + entries.length))}
); }