146 lines
5.7 KiB
TypeScript
146 lines
5.7 KiB
TypeScript
'use client'
|
|
|
|
import { useState, useEffect } from 'react'
|
|
import sdk from '@farcaster/frame-sdk'
|
|
import { TrendingUp, TrendingDown, Award, Target } from 'lucide-react'
|
|
|
|
interface Stats {
|
|
totalVotes: number
|
|
totalWins: number
|
|
totalLosses: number
|
|
winRate: number
|
|
totalEarnings: number
|
|
totalSpent: number
|
|
netProfit: number
|
|
currentStreak: number
|
|
bestStreak: number
|
|
avgVoteAmount: number
|
|
recentVotes: Array<{
|
|
pollId: string
|
|
question: string
|
|
won: boolean
|
|
amount: number
|
|
timestamp: number
|
|
}>
|
|
}
|
|
|
|
export default function StatsPage() {
|
|
const [stats, setStats] = useState<Stats | null>(null)
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
useEffect(() => {
|
|
sdk.context.then(ctx => {
|
|
if (ctx?.user?.fid) {
|
|
fetch(`/api/user/${ctx.user.fid}/stats`)
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
setStats(data)
|
|
setLoading(false)
|
|
})
|
|
}
|
|
})
|
|
}, [])
|
|
|
|
if (loading) return <div className="min-h-screen bg-gradient-to-b from-celo-dark to-black text-white p-4 flex items-center justify-center">Loading...</div>
|
|
if (!stats) return <div className="min-h-screen bg-gradient-to-b from-celo-dark to-black text-white p-4 flex items-center justify-center">No stats available</div>
|
|
|
|
return (
|
|
<div className="min-h-screen bg-gradient-to-b from-celo-dark to-black text-white p-4">
|
|
<div className="max-w-4xl mx-auto space-y-6">
|
|
<h1 className="text-3xl font-bold">📊 Your Stats</h1>
|
|
|
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
|
<div className="bg-white/10 rounded-xl p-4">
|
|
<div className="text-2xl font-bold">{stats.totalVotes}</div>
|
|
<div className="text-sm text-gray-400">Total Votes</div>
|
|
</div>
|
|
<div className="bg-white/10 rounded-xl p-4">
|
|
<div className="text-2xl font-bold text-celo-green">{stats.totalWins}</div>
|
|
<div className="text-sm text-gray-400">Wins</div>
|
|
</div>
|
|
<div className="bg-white/10 rounded-xl p-4">
|
|
<div className="text-2xl font-bold text-red-400">{stats.totalLosses}</div>
|
|
<div className="text-sm text-gray-400">Losses</div>
|
|
</div>
|
|
<div className="bg-white/10 rounded-xl p-4">
|
|
<div className="text-2xl font-bold">{stats.winRate}%</div>
|
|
<div className="text-sm text-gray-400">Win Rate</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="bg-white/10 rounded-xl p-6">
|
|
<h2 className="text-xl font-semibold mb-4">💰 Financial Summary</h2>
|
|
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
|
<div>
|
|
<div className="text-sm text-gray-400">Total Earnings</div>
|
|
<div className="text-2xl font-bold text-celo-green">{stats.totalEarnings.toFixed(2)} cUSD</div>
|
|
</div>
|
|
<div>
|
|
<div className="text-sm text-gray-400">Total Spent</div>
|
|
<div className="text-2xl font-bold text-red-400">{stats.totalSpent.toFixed(2)} cUSD</div>
|
|
</div>
|
|
<div>
|
|
<div className="text-sm text-gray-400">Net Profit</div>
|
|
<div className={`text-2xl font-bold ${stats.netProfit >= 0 ? 'text-celo-green' : 'text-red-400'}`}>
|
|
{stats.netProfit >= 0 ? '+' : ''}{stats.netProfit.toFixed(2)} cUSD
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
<div className="bg-white/10 rounded-xl p-6">
|
|
<div className="flex items-center gap-2 mb-4">
|
|
<Award className="text-celo-yellow" />
|
|
<h2 className="text-xl font-semibold">Streaks</h2>
|
|
</div>
|
|
<div className="space-y-3">
|
|
<div>
|
|
<div className="text-sm text-gray-400">Current Streak</div>
|
|
<div className="text-2xl font-bold">{stats.currentStreak}🔥</div>
|
|
</div>
|
|
<div>
|
|
<div className="text-sm text-gray-400">Best Streak</div>
|
|
<div className="text-2xl font-bold text-celo-yellow">{stats.bestStreak}🔥</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="bg-white/10 rounded-xl p-6">
|
|
<div className="flex items-center gap-2 mb-4">
|
|
<Target className="text-celo-green" />
|
|
<h2 className="text-xl font-semibold">Averages</h2>
|
|
</div>
|
|
<div className="space-y-3">
|
|
<div>
|
|
<div className="text-sm text-gray-400">Avg Vote Amount</div>
|
|
<div className="text-2xl font-bold">{stats.avgVoteAmount.toFixed(2)} cUSD</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="bg-white/10 rounded-xl p-6">
|
|
<h2 className="text-xl font-semibold mb-4">📈 Recent Activity</h2>
|
|
<div className="space-y-3">
|
|
{stats.recentVotes.map((vote, idx) => (
|
|
<div key={idx} className="flex items-center justify-between bg-white/5 rounded-lg p-3">
|
|
<div className="flex-1">
|
|
<p className="font-medium">{vote.question}</p>
|
|
<p className="text-sm text-gray-400">{new Date(vote.timestamp).toLocaleDateString()}</p>
|
|
</div>
|
|
<div className="text-right">
|
|
<div className={`font-semibold ${vote.won ? 'text-celo-green' : 'text-red-400'}`}>
|
|
{vote.won ? '+' : '-'}{vote.amount.toFixed(2)} cUSD
|
|
</div>
|
|
<div className="text-sm">{vote.won ? '✅ Won' : '❌ Lost'}</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|