'use client' import React, { useState, useEffect } from 'react' interface ApiStatus { status: string service: string health: string } interface Balance { totalBalance: number availableBalance: number positions: Array<{ symbol: string amount: number value: number price: number }> } interface PriceData { prices: Array<{ symbol: string price: number change24h: number volume24h: number }> } export default function HomePage() { const [apiStatus, setApiStatus] = useState(null) const [balance, setBalance] = useState(null) const [prices, setPrices] = useState(null) const [loading, setLoading] = useState(true) const [tradeAmount, setTradeAmount] = useState('1.0') const [selectedSymbol, setSelectedSymbol] = useState('SOL') // Fetch data on component mount useEffect(() => { fetchData() }, []) const fetchData = async () => { try { setLoading(true) // Fetch API status const statusRes = await fetch('/api/status') if (statusRes.ok) { const statusData = await statusRes.json() setApiStatus(statusData) } // Fetch balance const balanceRes = await fetch('/api/balance') if (balanceRes.ok) { const balanceData = await balanceRes.json() setBalance(balanceData) } // Fetch prices const pricesRes = await fetch('/api/prices') if (pricesRes.ok) { const pricesData = await pricesRes.json() setPrices(pricesData) } } catch (error) { console.error('Failed to fetch data:', error) } finally { setLoading(false) } } const executeTrade = async (side: 'buy' | 'sell') => { try { const response = await fetch('/api/trading', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ symbol: selectedSymbol, side, amount: tradeAmount, type: 'market' }) }) const result = await response.json() if (result.success) { alert(`Trade executed: ${result.message}`) fetchData() // Refresh data after trade } else { alert(`Trade failed: ${result.error}`) } } catch (error) { alert('Trade execution failed') console.error(error) } } if (loading) { return (
Loading Bitquery Trading Dashboard...
) } return (

Bitquery Trading Dashboard

{/* Status and Balance */}

Account Status

✅ Bitquery API: {apiStatus?.status || 'Loading...'}
💰 Portfolio Value: ${balance?.totalBalance?.toFixed(2) || '0.00'}
📊 Available Balance: ${balance?.availableBalance?.toFixed(2) || '0.00'}

Quick Trade

setTradeAmount(e.target.value)} className="w-full bg-gray-700 border border-gray-600 rounded px-3 py-2" placeholder="1.0" />
{/* Token Prices */}

Live Prices (Bitquery)

{prices?.prices?.map((token) => (
{token.symbol} = 0 ? 'text-green-400' : 'text-red-400'}`}> {token.change24h >= 0 ? '+' : ''}{token.change24h.toFixed(2)}%
${token.price.toFixed(2)}
Vol: ${(token.volume24h / 1000000).toFixed(1)}M
))}
{/* Positions */} {balance?.positions && balance.positions.length > 0 && (

Your Positions

{balance.positions.map((position) => (
{position.symbol} {position.amount} tokens
${position.value.toFixed(2)}
${position.price.toFixed(2)} each
))}
)}
) }