Claude b14e50aa95
feat: Modernize Core Components with Glassmorphism & Real API Integration
Completely redesigned core dashboard components with:

## Components Modernized:
1. UnifiedBotControl - Bot control center
   - Real API integration (startBot, stopBot)
   - WebSocket real-time status updates
   - Modern glassmorphism design with gradients
   - Separate DEX & Polymarket controls
   - Interactive sliders for configuration
   - Success/error toast messages
   - Loading states with spinners
   - Emergency stop functionality

2. BotStatus - Live bot status display
   - Real-time WebSocket updates
   - API polling every 10s
   - Glassmorphism cards for DEX & Polymarket
   - Status indicators (RUNNING/STOPPED/ERROR)
   - Wallet balance display
   - Total trades counter
   - Network info display
   - Last trade timestamps

3. TradingHistory - Recent trades with animations
   - WebSocket for instant trade updates
   - API integration with refresh
   - Animated trade cards with hover effects
   - Color-coded P&L indicators
   - Profit/loss/pending status badges
   - Empty state with icon
   - Skeleton loading states
   - "View All" navigation button

## Design Features:
โœจ Glassmorphism with backdrop-blur
๐ŸŽจ Gradient backgrounds (purple, blue, cyan, pink)
๐ŸŒˆ Color-coded status indicators
๐Ÿ’ซ Smooth hover transitions
๐Ÿ“Š Modern card layouts
๐Ÿ”„ Loading skeletons
โœ… Success/error messages
๐Ÿ“ฑ Fully responsive

## Technical Improvements:
- All components use real API client
- WebSocket integration for live updates
- Proper TypeScript typing
- Error boundary handling
- Loading states everywhere
- Auto-refresh intervals
- Smooth animations

No more placeholder data - everything connected to backend!
2025-11-12 01:13:44 +00:00

173 lines
6.7 KiB
TypeScript

'use client';
import { useEffect, useState } from 'react';
import api from '@/lib/apiClient';
import useWebSocket from '@/lib/useWebSocket';
interface Trade {
id: string;
timestamp: number;
type: string;
tokenIn: string;
tokenOut: string;
amountIn: number;
amountOut: number;
profitLoss?: number;
outcome?: string;
}
export default function TradingHistory() {
const { lastTrade } = useWebSocket();
const [trades, setTrades] = useState<Trade[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
fetchTrades();
}, []);
// Add new trade from WebSocket
useEffect(() => {
if (lastTrade) {
setTrades((prev) => [lastTrade as any, ...prev].slice(0, 10));
}
}, [lastTrade]);
const fetchTrades = async () => {
try {
const data = await api.getTradeHistory({ limit: 10 });
setTrades(data.trades || []);
setError(null);
} catch (err: any) {
setError(err.message || 'Failed to fetch trades');
} finally {
setLoading(false);
}
};
return (
<div className="relative">
{/* Glassmorphism Background */}
<div className="absolute inset-0 bg-gradient-to-br from-indigo-500/10 via-purple-500/10 to-pink-500/10 rounded-2xl backdrop-blur-xl" />
<div className="relative bg-slate-800/50 backdrop-blur-xl border border-indigo-500/20 rounded-2xl p-6 shadow-2xl">
{/* Header */}
<div className="flex items-center justify-between mb-6">
<div className="flex items-center gap-3">
<div className="w-10 h-10 bg-gradient-to-br from-indigo-500 to-purple-500 rounded-xl flex items-center justify-center">
<span className="text-xl">๐Ÿ“ˆ</span>
</div>
<div>
<h2 className="text-xl font-bold text-white">Recent Trades</h2>
<p className="text-xs text-slate-400">Last 10 transactions</p>
</div>
</div>
<button
onClick={fetchTrades}
className="px-4 py-2 bg-slate-700 hover:bg-slate-600 text-white rounded-lg text-sm font-medium transition-colors"
>
๐Ÿ”„ Refresh
</button>
</div>
{/* Error Display */}
{error && (
<div className="mb-4 p-3 bg-red-500/20 border border-red-500/30 rounded-lg">
<p className="text-red-400 text-sm">โš  {error}</p>
</div>
)}
{/* Loading State */}
{loading ? (
<div className="space-y-3">
{[...Array(5)].map((_, i) => (
<div key={i} className="bg-slate-900/50 rounded-lg p-4 animate-pulse">
<div className="h-4 bg-slate-700 rounded w-3/4 mb-2" />
<div className="h-3 bg-slate-700 rounded w-1/2" />
</div>
))}
</div>
) : trades.length === 0 ? (
<div className="text-center py-12">
<div className="text-6xl mb-4">๐Ÿ“Š</div>
<p className="text-slate-400 mb-2">No trades yet</p>
<p className="text-sm text-slate-500">Trades will appear here once the bot starts trading</p>
</div>
) : (
<div className="space-y-3">
{trades.map((trade, index) => (
<div
key={trade.id || index}
className="relative group"
>
<div className="absolute inset-0 bg-gradient-to-r from-indigo-500/10 to-purple-500/10 rounded-xl blur opacity-0 group-hover:opacity-100 transition-opacity" />
<div className="relative bg-slate-900/50 backdrop-blur-sm border border-slate-700 hover:border-indigo-500/50 rounded-xl p-4 transition-all">
<div className="flex items-center justify-between mb-2">
<div className="flex items-center gap-3">
<div className={`w-8 h-8 rounded-lg flex items-center justify-center ${
trade.outcome === 'profit'
? 'bg-green-500/20 text-green-400'
: trade.outcome === 'loss'
? 'bg-red-500/20 text-red-400'
: 'bg-yellow-500/20 text-yellow-400'
}`}>
{trade.outcome === 'profit' ? 'โ†—' : trade.outcome === 'loss' ? 'โ†˜' : 'โ†’'}
</div>
<div>
<div className="text-sm font-semibold text-white">
{trade.tokenIn} โ†’ {trade.tokenOut}
</div>
<div className="text-xs text-slate-400">
{new Date(trade.timestamp).toLocaleString()}
</div>
</div>
</div>
{trade.profitLoss !== undefined && (
<div className={`text-sm font-bold ${
trade.profitLoss > 0 ? 'text-green-400' : 'text-red-400'
}`}>
{trade.profitLoss > 0 ? '+' : ''}{trade.profitLoss.toFixed(4)} BNB
</div>
)}
</div>
<div className="flex items-center gap-4 text-xs text-slate-400">
<div className="flex items-center gap-1">
<span>In:</span>
<span className="text-white font-medium">{trade.amountIn.toFixed(4)}</span>
</div>
<div className="flex items-center gap-1">
<span>Out:</span>
<span className="text-white font-medium">{trade.amountOut.toFixed(4)}</span>
</div>
<div className={`ml-auto px-2 py-1 rounded text-xs font-bold ${
trade.outcome === 'profit'
? 'bg-green-500/20 text-green-400'
: trade.outcome === 'loss'
? 'bg-red-500/20 text-red-400'
: 'bg-yellow-500/20 text-yellow-400'
}`}>
{trade.outcome || 'pending'}
</div>
</div>
</div>
</div>
))}
</div>
)}
{/* View All Button */}
{trades.length > 0 && (
<div className="mt-6 text-center">
<button
onClick={() => window.location.href = '/trades'}
className="px-6 py-2 bg-gradient-to-r from-indigo-600 to-purple-600 hover:from-indigo-700 hover:to-purple-700 text-white rounded-lg font-medium transition-all"
>
View All Trades โ†’
</button>
</div>
)}
</div>
</div>
);
}