'use client' import { useState, useEffect } from 'react' import { useAuth } from '@/lib/AuthContext' import { ArrowUpRight, History } from 'lucide-react' import { useRouter } from 'next/navigation' export default function WalletPage() { const { token, user, loading: authLoading } = useAuth() const router = useRouter() const [amount, setAmount] = useState('') const [cashouts, setCashouts] = useState([]) const [loading, setLoading] = useState(false) useEffect(() => { if (!authLoading && !token) router.push('/login') }, [token, authLoading, router]) useEffect(() => { if (!token) return; fetch('/api/wallet', { headers: { 'Authorization': `Bearer ${token}` } }).then(r => r.json()).then(d => setCashouts(d.requests || [])).catch(() => {}) }, [token]) const handleCashout = async () => { if (!token || !amount) return setLoading(true) const res = await fetch('/api/wallet', { method: 'POST', headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ amountFlh: parseInt(amount) }) }) setLoading(false) const data = await res.json() if (res.ok) { setAmount(''); alert('Cashout submitted!') } else { alert(data.error) } } if (authLoading) return
Loading...
if (!token) return null return (

Wallet

Balance

{user?.flhBalance?.toLocaleString() || 0} FLH

Cash Out

Rate: 100 FLH = £0.80 (20% platform spread). Minimum 100 FLH.

setAmount(e.target.value)} min={100} className="flex-1 bg-[#0a0a0f] border border-gray-700 rounded px-3 py-2 text-sm focus:border-[#D4AF37] outline-none" />

History

{cashouts.length === 0 ? (

No cashout requests yet

) : ( cashouts.map(c => (
{c.amountFlh} FLH → £{c.fiatAmount.toFixed(2)} {c.status}
)) )}
) }