Complete Phase 2 Task 6/8 - TradingView Chart Integration
Implementation Details:
- Created TradingViewChart component (350+ lines) using lightweight-charts
- Real OHLCV candlestick charts from price feed API (/api/prices/:tokenId/ohlcv)
- Multiple intervals: 1m, 5m, 15m, 1h, 4h, 1d with auto-refresh
- Volume histogram overlay with color-coded bars
- Interactive controls: zoom, pan, crosshair, interval switcher
- Dark theme matching platform design
- WebSocket-ready for real-time price updates
Integration:
- Positions page: Chart button (๐) for each position's token address
- Polymarket page: Chart button for each market ID
- Uses REAL token addresses and market IDs - NO mock data
- Removed all demo/placeholder files (charts/page.tsx, docs)
Technical:
- Uses price feed service's getOHLCV() method
- Auto-refresh intervals match selected timeframe
- Proper cleanup on component unmount
- Error handling with retry functionality
- Loading states during data fetch
Phase 2 Progress: 75% (6/8 tasks complete)
Files Modified: 3 (positions page, polymarket dashboard, chart component)
Code Added: ~400 lines production code
692 lines
27 KiB
TypeScript
692 lines
27 KiB
TypeScript
/**
|
|
* Polymarket Prediction Markets Dashboard
|
|
* Shows trending markets, AI analysis, positions, and cross-platform opportunities
|
|
*/
|
|
|
|
'use client';
|
|
|
|
import { useState, useEffect } from 'react';
|
|
import {
|
|
getPolymarketMarkets,
|
|
getPolymarketBalance,
|
|
getPolymarketPositions,
|
|
getPolymarketOrders,
|
|
getCrossPlatformOpportunities,
|
|
analyzePolymarketMarket,
|
|
getPolymarketHistory,
|
|
getPolymarketBettingStats,
|
|
getPolymarketLeaderboard,
|
|
PolymarketMarket,
|
|
PolymarketBalance,
|
|
PolymarketPosition,
|
|
PolymarketOrder,
|
|
CrossPlatformOpportunity,
|
|
AIMarketAnalysis,
|
|
PolymarketBet,
|
|
BettingStats,
|
|
Leaderboard,
|
|
TopTrader,
|
|
} from '@/lib/api';
|
|
import { usePolling } from '@/hooks/usePolling';
|
|
import TradingViewChart from '@/components/TradingViewChart';
|
|
|
|
interface MarketWithAnalysis extends PolymarketMarket {
|
|
analysis?: AIMarketAnalysis;
|
|
analyzing?: boolean;
|
|
}
|
|
|
|
export default function PolymarketDashboard() {
|
|
const [markets, setMarkets] = useState<MarketWithAnalysis[]>([]);
|
|
const [balance, setBalance] = useState<PolymarketBalance | null>(null);
|
|
const [positions, setPositions] = useState<PolymarketPosition[]>([]);
|
|
const [orders, setOrders] = useState<PolymarketOrder[]>([]);
|
|
const [opportunities, setOpportunities] = useState<CrossPlatformOpportunity[]>([]);
|
|
const [betHistory, setBetHistory] = useState<PolymarketBet[]>([]);
|
|
const [bettingStats, setBettingStats] = useState<BettingStats | null>(null);
|
|
const [leaderboard, setLeaderboard] = useState<Leaderboard | null>(null);
|
|
const [loading, setLoading] = useState(true);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [selectedMarket, setSelectedMarket] = useState<string | null>(null);
|
|
const [selectedMarketForChart, setSelectedMarketForChart] = useState<PolymarketMarket | null>(null);
|
|
const [activeTab, setActiveTab] = useState<'markets' | 'leaderboard'>('markets');
|
|
|
|
// Load initial data
|
|
useEffect(() => {
|
|
loadAllData();
|
|
}, []);
|
|
|
|
// Poll for updates every 30 seconds
|
|
usePolling(async () => {
|
|
await loadAllData();
|
|
}, 30000);
|
|
|
|
const loadAllData = async () => {
|
|
try {
|
|
setLoading(true);
|
|
setError(null);
|
|
|
|
const [marketsData, balanceData, positionsData, ordersData, oppsData, historyData, statsData, leaderboardData] = await Promise.all([
|
|
getPolymarketMarkets(10),
|
|
getPolymarketBalance(),
|
|
getPolymarketPositions(),
|
|
getPolymarketOrders(),
|
|
getCrossPlatformOpportunities(),
|
|
getPolymarketHistory(20),
|
|
getPolymarketBettingStats(),
|
|
getPolymarketLeaderboard(),
|
|
]);
|
|
|
|
setMarkets(marketsData.map(m => ({ ...m, analyzing: false })));
|
|
setBalance(balanceData);
|
|
setPositions(positionsData);
|
|
setOrders(ordersData);
|
|
setOpportunities(oppsData);
|
|
setBetHistory(historyData);
|
|
setBettingStats(statsData);
|
|
setLeaderboard(leaderboardData);
|
|
} catch (err: any) {
|
|
console.error('Failed to load Polymarket data:', err);
|
|
setError(err.message || 'Failed to load data');
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
const analyzeMarket = async (market: PolymarketMarket) => {
|
|
try {
|
|
// Mark as analyzing
|
|
setMarkets(prev =>
|
|
prev.map(m => (m.id === market.id ? { ...m, analyzing: true } : m))
|
|
);
|
|
|
|
const result = await analyzePolymarketMarket(market.id, market.question);
|
|
|
|
// Update with analysis
|
|
setMarkets(prev =>
|
|
prev.map(m =>
|
|
m.id === market.id
|
|
? { ...m, analysis: result.analysis, analyzing: false }
|
|
: m
|
|
)
|
|
);
|
|
|
|
setSelectedMarket(market.id);
|
|
} catch (err: any) {
|
|
console.error('Failed to analyze market:', err);
|
|
setMarkets(prev =>
|
|
prev.map(m => (m.id === market.id ? { ...m, analyzing: false } : m))
|
|
);
|
|
setError(err.message || 'Failed to analyze market');
|
|
}
|
|
};
|
|
|
|
const getRecommendationColor = (recommendation: string) => {
|
|
switch (recommendation) {
|
|
case 'STRONG_BUY':
|
|
return 'text-green-400 bg-green-900/30';
|
|
case 'BUY':
|
|
return 'text-green-300 bg-green-900/20';
|
|
case 'HOLD':
|
|
return 'text-yellow-300 bg-yellow-900/20';
|
|
case 'SELL':
|
|
return 'text-red-300 bg-red-900/20';
|
|
case 'STRONG_SELL':
|
|
return 'text-red-400 bg-red-900/30';
|
|
default:
|
|
return 'text-gray-300 bg-gray-900/20';
|
|
}
|
|
};
|
|
|
|
const getRiskLevelColor = (risk: string) => {
|
|
switch (risk) {
|
|
case 'LOW':
|
|
return 'text-green-400';
|
|
case 'MEDIUM':
|
|
return 'text-yellow-400';
|
|
case 'HIGH':
|
|
return 'text-red-400';
|
|
default:
|
|
return 'text-gray-400';
|
|
}
|
|
};
|
|
|
|
if (loading && markets.length === 0) {
|
|
return (
|
|
<div className="flex items-center justify-center min-h-[400px]">
|
|
<div className="text-center">
|
|
<div className="text-4xl mb-4">๐ฎ</div>
|
|
<p className="text-gray-400">Loading Polymarket data...</p>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
{/* Header */}
|
|
<div className="flex items-center justify-between">
|
|
<div>
|
|
<h2 className="text-3xl font-bold">๐ฎ Polymarket Prediction Markets</h2>
|
|
<p className="text-gray-400 mt-1">AI-powered market analysis on Polygon</p>
|
|
</div>
|
|
<button
|
|
onClick={loadAllData}
|
|
className="btn-secondary"
|
|
disabled={loading}
|
|
>
|
|
{loading ? 'โณ Refreshing...' : '๐ Refresh'}
|
|
</button>
|
|
</div>
|
|
|
|
{/* Tab Navigation */}
|
|
<div className="flex space-x-2 border-b border-gray-700">
|
|
<button
|
|
onClick={() => setActiveTab('markets')}
|
|
className={`px-6 py-3 font-semibold transition-all ${
|
|
activeTab === 'markets'
|
|
? 'border-b-2 border-blue-500 text-blue-500'
|
|
: 'text-gray-400 hover:text-gray-200'
|
|
}`}
|
|
>
|
|
๐ Markets
|
|
</button>
|
|
<button
|
|
onClick={() => setActiveTab('leaderboard')}
|
|
className={`px-6 py-3 font-semibold transition-all ${
|
|
activeTab === 'leaderboard'
|
|
? 'border-b-2 border-blue-500 text-blue-500'
|
|
: 'text-gray-400 hover:text-gray-200'
|
|
}`}
|
|
>
|
|
๐ Top Traders
|
|
</button>
|
|
</div>
|
|
|
|
{/* Error Display */}
|
|
{error && (
|
|
<div className="bg-red-900/20 border border-red-500 rounded-lg p-4">
|
|
<div className="flex items-center">
|
|
<span className="text-xl mr-3">โ</span>
|
|
<p className="text-red-400">{error}</p>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* Balance & Stats Cards */}
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
{balance && (
|
|
<div className="card p-6">
|
|
<h3 className="text-xl font-bold mb-4">๐ฐ Wallet Balance</h3>
|
|
<div className="grid grid-cols-2 gap-4">
|
|
<div>
|
|
<p className="text-gray-400 text-sm">MATIC</p>
|
|
<p className="text-2xl font-bold">{balance.matic.toFixed(4)}</p>
|
|
</div>
|
|
<div>
|
|
<p className="text-gray-400 text-sm">USDC</p>
|
|
<p className="text-2xl font-bold">${balance.usdc.toFixed(2)}</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{bettingStats && (
|
|
<div className="card p-6">
|
|
<h3 className="text-xl font-bold mb-4">๐ Betting Stats (Greenfield)</h3>
|
|
<div className="grid grid-cols-2 gap-4">
|
|
<div>
|
|
<p className="text-gray-400 text-sm">Total Bets</p>
|
|
<p className="text-2xl font-bold">{bettingStats.totalBets}</p>
|
|
</div>
|
|
<div>
|
|
<p className="text-gray-400 text-sm">Win Rate</p>
|
|
<p className="text-2xl font-bold text-green-400">
|
|
{bettingStats.winRate.toFixed(1)}%
|
|
</p>
|
|
</div>
|
|
<div>
|
|
<p className="text-gray-400 text-sm">Total P&L</p>
|
|
<p className={`text-2xl font-bold ${bettingStats.totalProfit >= 0 ? 'text-green-400' : 'text-red-400'}`}>
|
|
{bettingStats.totalProfit >= 0 ? '+' : ''}${bettingStats.totalProfit.toFixed(2)}
|
|
</p>
|
|
</div>
|
|
<div>
|
|
<p className="text-gray-400 text-sm">Volume</p>
|
|
<p className="text-2xl font-bold">${bettingStats.totalVolume.toFixed(0)}</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* Markets Tab */}
|
|
{activeTab === 'markets' && (
|
|
<>
|
|
{/* Price Chart for Selected Market */}
|
|
{selectedMarketForChart && (
|
|
<div className="card p-6 mb-6">
|
|
<div className="flex justify-between items-center mb-4">
|
|
<div>
|
|
<h3 className="text-xl font-semibold text-white">
|
|
{selectedMarketForChart.question}
|
|
</h3>
|
|
<p className="text-sm text-gray-400">Market ID: {selectedMarketForChart.id}</p>
|
|
</div>
|
|
<button
|
|
onClick={() => setSelectedMarketForChart(null)}
|
|
className="text-gray-400 hover:text-white transition-colors text-2xl"
|
|
>
|
|
โ
|
|
</button>
|
|
</div>
|
|
<TradingViewChart
|
|
tokenId={selectedMarketForChart.id}
|
|
interval="1h"
|
|
height={500}
|
|
showVolumeChart={true}
|
|
/>
|
|
</div>
|
|
)}
|
|
|
|
{/* Trending Markets with AI Analysis */}
|
|
<div className="card p-6">
|
|
<h3 className="text-xl font-bold mb-4">๐ Trending Markets</h3>
|
|
<div className="space-y-3">
|
|
{markets.map((market) => (
|
|
<div
|
|
key={market.id}
|
|
className="bg-gray-800/50 rounded-lg p-4 hover:bg-gray-800/70 transition-colors"
|
|
>
|
|
<div className="flex justify-between items-start mb-2">
|
|
<div className="flex-1">
|
|
<h4 className="font-semibold text-lg mb-1">{market.question}</h4>
|
|
<div className="flex gap-4 text-sm text-gray-400">
|
|
{market.volume && (
|
|
<span>Volume: ${parseFloat(market.volume).toLocaleString()}</span>
|
|
)}
|
|
{market.liquidity && (
|
|
<span>Liquidity: ${parseFloat(market.liquidity).toLocaleString()}</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
<div className="flex gap-2">
|
|
<button
|
|
onClick={() => setSelectedMarketForChart(market)}
|
|
className="btn-secondary px-4 py-2 text-sm"
|
|
title="View price chart"
|
|
>
|
|
๐ Chart
|
|
</button>
|
|
<button
|
|
onClick={() => analyzeMarket(market)}
|
|
disabled={market.analyzing}
|
|
className="btn-primary px-4 py-2 text-sm disabled:opacity-50"
|
|
>
|
|
{market.analyzing ? '๐ค Analyzing...' : '๐ง AI Analysis'}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* AI Analysis Results */}
|
|
{market.analysis && selectedMarket === market.id && (
|
|
<div className="mt-4 pt-4 border-t border-gray-700">
|
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-3 mb-3">
|
|
<div>
|
|
<p className="text-xs text-gray-400">Recommendation</p>
|
|
<p className={`font-bold px-2 py-1 rounded text-sm ${getRecommendationColor(market.analysis.recommendation)}`}>
|
|
{market.analysis.recommendation}
|
|
</p>
|
|
</div>
|
|
<div>
|
|
<p className="text-xs text-gray-400">Confidence</p>
|
|
<p className="font-bold text-sm">
|
|
{(market.analysis.confidence * 100).toFixed(1)}%
|
|
</p>
|
|
</div>
|
|
<div>
|
|
<p className="text-xs text-gray-400">Risk Level</p>
|
|
<p className={`font-bold text-sm ${getRiskLevelColor(market.analysis.riskLevel)}`}>
|
|
{market.analysis.riskLevel}
|
|
</p>
|
|
</div>
|
|
<div>
|
|
<p className="text-xs text-gray-400">Suggested Price</p>
|
|
<p className="font-bold text-sm">
|
|
{(market.analysis.suggestedPrice * 100).toFixed(1)}%
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div className="bg-gray-900/50 rounded p-3">
|
|
<p className="text-sm font-semibold mb-1">๐ก AI Reasoning:</p>
|
|
<p className="text-sm text-gray-300">{market.analysis.reasoning}</p>
|
|
</div>
|
|
{market.analysis.suggestedSize > 0 && (
|
|
<div className="mt-2 text-sm">
|
|
<span className="text-gray-400">Suggested Position: </span>
|
|
<span className="font-bold">
|
|
${market.analysis.suggestedSize.toFixed(2)} USDC
|
|
</span>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Cross-Platform Opportunities */}
|
|
{opportunities.length > 0 && (
|
|
<div className="card p-6">
|
|
<h3 className="text-xl font-bold mb-4">๐ Cross-Platform Opportunities</h3>
|
|
<div className="space-y-3">
|
|
{opportunities.slice(0, 5).map((opp, idx) => (
|
|
<div
|
|
key={idx}
|
|
className="bg-gradient-to-r from-blue-900/20 to-purple-900/20 rounded-lg p-4 border border-blue-500/30"
|
|
>
|
|
<div className="flex justify-between items-start mb-2">
|
|
<div>
|
|
<div className="flex items-center gap-2 mb-1">
|
|
<span className="px-2 py-1 bg-blue-500/20 rounded text-xs font-bold">
|
|
{opp.type}
|
|
</span>
|
|
<span className={`text-sm ${getRiskLevelColor(opp.riskLevel)}`}>
|
|
{opp.riskLevel} Risk
|
|
</span>
|
|
</div>
|
|
<p className="text-sm mb-1">{opp.description}</p>
|
|
<p className="text-xs text-gray-400">{opp.action}</p>
|
|
</div>
|
|
<div className="text-right">
|
|
<p className="text-xs text-gray-400">Expected Profit</p>
|
|
<p className="text-xl font-bold text-green-400">
|
|
+{opp.expectedProfit.toFixed(2)}%
|
|
</p>
|
|
<p className="text-xs text-gray-400">
|
|
{(opp.confidence * 100).toFixed(0)}% confident
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* Current Positions */}
|
|
{positions.length > 0 && (
|
|
<div className="card p-6">
|
|
<h3 className="text-xl font-bold mb-4">๐ Active Positions</h3>
|
|
<div className="space-y-3">
|
|
{positions.map((pos, idx) => (
|
|
<div key={idx} className="bg-gray-800/50 rounded-lg p-4">
|
|
<div className="flex justify-between items-start">
|
|
<div>
|
|
<h4 className="font-semibold">{pos.marketQuestion}</h4>
|
|
<p className="text-sm text-gray-400">Outcome: {pos.outcome}</p>
|
|
<p className="text-sm">
|
|
Size: {pos.size} @ {(pos.avgPrice * 100).toFixed(1)}%
|
|
</p>
|
|
</div>
|
|
{pos.pnl !== undefined && (
|
|
<div className="text-right">
|
|
<p className="text-xs text-gray-400">P&L</p>
|
|
<p className={`text-lg font-bold ${pos.pnl >= 0 ? 'text-green-400' : 'text-red-400'}`}>
|
|
{pos.pnl >= 0 ? '+' : ''}${pos.pnl.toFixed(2)}
|
|
</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* Open Orders */}
|
|
{orders.length > 0 && (
|
|
<div className="card p-6">
|
|
<h3 className="text-xl font-bold mb-4">๐ Open Orders</h3>
|
|
<div className="space-y-2">
|
|
{orders.map((order) => (
|
|
<div key={order.id} className="bg-gray-800/50 rounded p-3 text-sm">
|
|
<div className="flex justify-between">
|
|
<div>
|
|
<span className={order.side === 'BUY' ? 'text-green-400' : 'text-red-400'}>
|
|
{order.side}
|
|
</span>
|
|
{' '}
|
|
{order.size} @ {(order.price * 100).toFixed(1)}%
|
|
</div>
|
|
<div className="text-gray-400">
|
|
Filled: {order.filled}/{order.size}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* Bet History from Greenfield */}
|
|
{betHistory.length > 0 && (
|
|
<div className="card p-6">
|
|
<h3 className="text-xl font-bold mb-4">๐ Bet History (Stored on Greenfield)</h3>
|
|
<div className="space-y-3">
|
|
{betHistory.slice(0, 10).map((bet) => (
|
|
<div key={bet.id} className="bg-gray-800/50 rounded-lg p-4">
|
|
<div className="flex justify-between items-start mb-2">
|
|
<div className="flex-1">
|
|
<h4 className="font-semibold text-sm">{bet.marketQuestion}</h4>
|
|
<div className="flex gap-3 text-xs text-gray-400 mt-1">
|
|
<span>{bet.outcome}</span>
|
|
<span className={bet.side === 'BUY' ? 'text-green-400' : 'text-red-400'}>
|
|
{bet.side}
|
|
</span>
|
|
<span>${bet.size.toFixed(2)} @ {(bet.price * 100).toFixed(1)}%</span>
|
|
<span className={`px-2 py-0.5 rounded ${
|
|
bet.status === 'OPEN' ? 'bg-blue-900/30 text-blue-400' :
|
|
bet.status === 'CLOSED' ? 'bg-gray-700 text-gray-300' :
|
|
'bg-yellow-900/30 text-yellow-400'
|
|
}`}>
|
|
{bet.status}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<div className="text-right ml-4">
|
|
{bet.profitLoss !== undefined && (
|
|
<>
|
|
<p className={`font-bold ${bet.profitLoss >= 0 ? 'text-green-400' : 'text-red-400'}`}>
|
|
{bet.profitLoss >= 0 ? '+' : ''}${bet.profitLoss.toFixed(2)}
|
|
</p>
|
|
{bet.profitLossPercent !== undefined && (
|
|
<p className="text-xs text-gray-400">
|
|
{bet.profitLossPercent >= 0 ? '+' : ''}{bet.profitLossPercent.toFixed(1)}%
|
|
</p>
|
|
)}
|
|
</>
|
|
)}
|
|
{bet.outcome_result && (
|
|
<p className={`text-xs mt-1 ${
|
|
bet.outcome_result === 'WIN' ? 'text-green-400' :
|
|
bet.outcome_result === 'LOSS' ? 'text-red-400' :
|
|
'text-yellow-400'
|
|
}`}>
|
|
{bet.outcome_result}
|
|
</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
{bet.aiAnalysis && (
|
|
<div className="mt-2 pt-2 border-t border-gray-700">
|
|
<p className="text-xs text-gray-400">
|
|
AI: {bet.aiAnalysis.recommendation} ({(bet.aiAnalysis.confidence * 100).toFixed(0)}% confident)
|
|
</p>
|
|
</div>
|
|
)}
|
|
<p className="text-xs text-gray-500 mt-1">
|
|
{new Date(bet.timestamp).toLocaleString()} โข ๐ข Stored on Greenfield
|
|
</p>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* Empty States */}
|
|
{positions.length === 0 && orders.length === 0 && betHistory.length === 0 && !loading && (
|
|
<div className="card p-8 text-center">
|
|
<div className="text-4xl mb-3">๐ฏ</div>
|
|
<p className="text-gray-400">No active positions, orders, or bet history</p>
|
|
<p className="text-sm text-gray-500 mt-1">
|
|
Analyze markets above to find trading opportunities
|
|
</p>
|
|
<p className="text-xs text-gray-500 mt-2">
|
|
All bets are automatically saved to BNB Greenfield for immortal storage
|
|
</p>
|
|
</div>
|
|
)}
|
|
</>
|
|
)}
|
|
|
|
{/* Leaderboard Tab */}
|
|
{activeTab === 'leaderboard' && leaderboard && (
|
|
<>
|
|
{/* Top by Profit */}
|
|
<div className="card p-6">
|
|
<h3 className="text-xl font-bold mb-4">๐ฐ Top Traders by Profit</h3>
|
|
<div className="space-y-2">
|
|
{leaderboard.topByProfit.slice(0, 10).map((trader) => (
|
|
<div
|
|
key={trader.address}
|
|
className="bg-gray-800/50 rounded-lg p-4 hover:bg-gray-800/70 transition-colors"
|
|
>
|
|
<div className="flex items-center justify-between">
|
|
<div className="flex items-center gap-4">
|
|
<div className="text-2xl font-bold text-gray-400">
|
|
#{trader.rank}
|
|
</div>
|
|
<div>
|
|
<p className="font-mono text-sm text-gray-300">
|
|
{trader.address.slice(0, 6)}...{trader.address.slice(-4)}
|
|
</p>
|
|
<div className="flex gap-3 text-xs text-gray-400 mt-1">
|
|
<span>{trader.totalTrades} trades</span>
|
|
<span className="text-green-400">{trader.winRate.toFixed(1)}% win rate</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="text-right">
|
|
<p className={`text-xl font-bold ${trader.totalProfit >= 0 ? 'text-green-400' : 'text-red-400'}`}>
|
|
{trader.totalProfit >= 0 ? '+' : ''}${trader.totalProfit.toLocaleString()}
|
|
</p>
|
|
<p className="text-sm text-gray-400">
|
|
{trader.totalProfitPercent.toFixed(1)}% ROI
|
|
</p>
|
|
<p className="text-xs text-gray-500">
|
|
${trader.totalVolume.toLocaleString()} volume
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Grid of Win Rate and Volume */}
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
{/* Top by Win Rate */}
|
|
<div className="card p-6">
|
|
<h3 className="text-xl font-bold mb-4">๐ฏ Top by Win Rate</h3>
|
|
<div className="space-y-2">
|
|
{leaderboard.topByWinRate.slice(0, 5).map((trader) => (
|
|
<div
|
|
key={trader.address}
|
|
className="bg-gray-800/50 rounded-lg p-3"
|
|
>
|
|
<div className="flex items-center justify-between">
|
|
<div>
|
|
<p className="font-mono text-xs">
|
|
{trader.address.slice(0, 6)}...{trader.address.slice(-4)}
|
|
</p>
|
|
<p className="text-xs text-gray-400">
|
|
{trader.totalTrades} trades
|
|
</p>
|
|
</div>
|
|
<div className="text-right">
|
|
<p className="text-lg font-bold text-green-400">
|
|
{trader.winRate.toFixed(1)}%
|
|
</p>
|
|
<p className="text-xs text-gray-400">
|
|
{trader.winningTrades}W / {trader.losingTrades}L
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Top by Volume */}
|
|
<div className="card p-6">
|
|
<h3 className="text-xl font-bold mb-4">๐ Top by Volume</h3>
|
|
<div className="space-y-2">
|
|
{leaderboard.topByVolume.slice(0, 5).map((trader) => (
|
|
<div
|
|
key={trader.address}
|
|
className="bg-gray-800/50 rounded-lg p-3"
|
|
>
|
|
<div className="flex items-center justify-between">
|
|
<div>
|
|
<p className="font-mono text-xs">
|
|
{trader.address.slice(0, 6)}...{trader.address.slice(-4)}
|
|
</p>
|
|
<p className="text-xs text-gray-400">
|
|
{trader.totalTrades} trades
|
|
</p>
|
|
</div>
|
|
<div className="text-right">
|
|
<p className="text-lg font-bold text-blue-400">
|
|
${trader.totalVolume.toLocaleString()}
|
|
</p>
|
|
<p className="text-xs text-gray-400">
|
|
{trader.openPositions} open
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Learn from Top Traders Info */}
|
|
<div className="card p-6 bg-gradient-to-r from-purple-900/20 to-blue-900/20 border border-purple-500/30">
|
|
<div className="flex items-start gap-4">
|
|
<div className="text-4xl">๐</div>
|
|
<div>
|
|
<h3 className="text-lg font-bold mb-2">Learn from the Best</h3>
|
|
<p className="text-sm text-gray-300 mb-3">
|
|
These top traders have proven track records on Polymarket. Our AI can analyze their strategies and positions to improve predictions.
|
|
</p>
|
|
<div className="flex gap-3 text-xs">
|
|
<span className="px-3 py-1 bg-green-900/30 text-green-400 rounded">
|
|
โ High Win Rates
|
|
</span>
|
|
<span className="px-3 py-1 bg-blue-900/30 text-blue-400 rounded">
|
|
โ Proven Profits
|
|
</span>
|
|
<span className="px-3 py-1 bg-purple-900/30 text-purple-400 rounded">
|
|
โ Active Traders
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|