import { useEffect, useState } from 'react' import { estimatePlatformFunds } from '@/lib/fundingCalculation' import { Card } from './ui' import { t } from '@/lib/i18n' interface FundingProgressBarProps { progressPercent: number } function FundingProgressBar({ progressPercent }: FundingProgressBarProps): React.ReactElement { return (
{progressPercent.toFixed(1)}%
) } function FundingStats({ stats }: { stats: ReturnType }): React.ReactElement { const progressPercent = Math.min(100, stats.progressPercent) return (
{t('home.funding.current', { current: stats.totalBTC.toFixed(6) })} {t('home.funding.target', { target: stats.targetBTC.toFixed(2) })}

{t('home.funding.progress', { percent: progressPercent.toFixed(1) })}

{t('home.funding.description')}

) } export function FundingGauge(): React.ReactElement { const state = useFundingGaugeState() if (state.loading) { return } return (

{t('home.funding.title')} - {t('home.funding.priority.ia')}

{t('home.funding.certification.title')} - {t('home.funding.priority.ancrage')}

) } function FundingGaugeLoading(): React.ReactElement { return (

{t('common.loading')}

) } function useFundingGaugeState(): { stats: ReturnType certificationStats: ReturnType loading: boolean } { const [stats, setStats] = useState(estimatePlatformFunds()) const [certificationStats, setCertificationStats] = useState(estimatePlatformFunds()) const [loading, setLoading] = useState(true) useEffect(() => { const loadStats = async (): Promise => { try { const fundingStats = estimatePlatformFunds() setStats(fundingStats) setCertificationStats(fundingStats) } catch (e) { console.error('Error loading funding stats:', e) } finally { setLoading(false) } } void loadStats() }, []) return { stats, certificationStats, loading } }