import { useState } from 'react' import useMangoStats from '../../hooks/useMangoStats' import Chart from '../Chart' const icons = { BTC: '/assets/icons/btc.svg', ETH: '/assets/icons/eth.svg', SOL: '/assets/icons/sol.svg', SRM: '/assets/icons/srm.svg', USDT: '/assets/icons/usdt.svg', USDC: '/assets/icons/usdc.svg', WUSDT: '/assets/icons/usdt.svg', } const dailyStartTime = new Date(Date.now() - 1 * 24 * 60 * 60 * 1000).getTime() const weeklyStartTime = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).getTime() const getAverageStats = (stats, startFrom, type) => { const timeFilteredStats = stats.filter( (d) => new Date(d.time).getTime() > startFrom ) const sum = timeFilteredStats.map((s) => s[type]).reduce((a, b) => a + b, 0) const avg = sum / timeFilteredStats.length || 0 return (avg * 100).toFixed(4) } const AverageInterest = ({ periodLabel, statTypeLabel, interest }) => { return ( <>
{periodLabel}
{statTypeLabel}
{interest}%
) } export default function StatsAssets() { const [selectedAsset, setSelectedAsset] = useState('BTC') const { latestStats, stats } = useMangoStats() const selectedStatsData = stats.filter( (stat) => stat.symbol === selectedAsset ) return ( <>
{latestStats.map((stat) => (
setSelectedAsset(stat.symbol)} key={stat.symbol as string} > {stat.symbol}
))}
x && x.toLocaleString(undefined, { maximumFractionDigits: 2 }) } type="area" />
`${(x * 100).toFixed(5)}%`} type="bar" />
x && x.toLocaleString(undefined, { maximumFractionDigits: 2 }) } type="area" />
`${(x * 100).toFixed(5)}%`} type="bar" />
) } const AssetHeader = ({ asset }) => { switch (asset) { case 'BTC': return (
{icons[asset]} Bitcoin
) case 'ETH': return (
{icons[asset]} Ethereum
) case 'SOL': return (
{icons[asset]} Solana
) case 'SRM': return (
{icons[asset]} Serum
) case 'USDC': return (
{icons[asset]} USD Coin
) default: return (
{icons[asset]} Bitcoin
) } }