import { useState, useEffect } from 'react'; import { Badge } from '../ui/Badge'; import { TrendingUp, TrendingDown, Target, BarChart3 } from 'lucide-react'; import { getApiUrl } from '@/config/api'; export default function PerformanceTrackingPanel() { const [stats, setStats] = useState({ totalSignals: 0, highConviction: 0, currentlyTracking: 0, winRate: { all: 64.2, highScore: 76.3, tapeAligned: 71.8, patternMatched: 79.1 }, avgPerformance: { avgWinner: 2.3, avgLoser: -1.2, rrRatio: 1.9, expectancy: 1.1 } }); useEffect(() => { const fetchStats = async () => { try { const response = await fetch(getApiUrl('/api/performance/stats')); // Check if response is ok if (!response.ok) { // If endpoint doesn't exist (404), silently fail and keep default stats if (response.status === 404) { console.warn('Performance stats endpoint not available'); return; } throw new Error(`HTTP ${response.status}: ${response.statusText}`); } const result = await response.json(); if (result.success && result.data) { setStats({ totalSignals: result.data.totalSignals || 0, highConviction: result.data.highConviction || 0, currentlyTracking: result.data.currentlyTracking || 0, winRate: { all: result.data.winRate?.all || 0, highScore: result.data.winRate?.highScore || 0, tapeAligned: result.data.winRate?.tapeAligned || 0, patternMatched: result.data.winRate?.patternMatched || 0 }, avgPerformance: { avgWinner: result.data.avgPerformance?.avgWinner || 0, avgLoser: result.data.avgPerformance?.avgLoser || 0, rrRatio: result.data.avgPerformance?.rrRatio || 0, expectancy: result.data.avgPerformance?.expectancy || 0 } }); } else { throw new Error(result.error || 'Failed to fetch stats'); } } catch (error) { // Only log if it's not a 404 (endpoint doesn't exist) if (!error.message.includes('404')) { console.error('Failed to fetch performance stats:', error); } // Keep existing stats on error (don't reset to 0) } }; fetchStats(); // Refresh every 5 minutes const interval = setInterval(fetchStats, 5 * 60 * 1000); return () => clearInterval(interval); }, []); return (