import React, { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { ChevronRight, Cpu, GitBranch, Shield } from 'lucide-react'; import { NetworkStats } from './NetworkStats'; import { usePolkadot } from '../contexts/PolkadotContext'; import { formatBalance } from '../lib/wallet'; const HeroSection: React.FC = () => { const { t } = useTranslation(); const { api, isApiReady } = usePolkadot(); const [stats, setStats] = useState({ activeProposals: 0, totalVoters: 0, tokensStaked: '0', trustScore: 0 }); useEffect(() => { const fetchStats = async () => { if (!api || !isApiReady) return; try { // Fetch active referenda let activeProposals = 0; try { const referendaCount = await api.query.referenda.referendumCount(); activeProposals = referendaCount.toNumber(); } catch (err) { console.warn('Failed to fetch referenda:', err); } // Fetch total staked tokens let tokensStaked = '0'; try { const currentEra = await api.query.staking.currentEra(); if (currentEra.isSome) { const eraIndex = currentEra.unwrap().toNumber(); const totalStake = await api.query.staking.erasTotalStake(eraIndex); const formatted = formatBalance(totalStake.toString()); tokensStaked = `${formatted} HEZ`; } } catch (err) { console.warn('Failed to fetch total stake:', err); } // Count total voters from conviction voting let totalVoters = 0; try { // Get all voting keys and count unique voters const votingKeys = await api.query.convictionVoting.votingFor.keys(); // Each key represents a unique (account, track) pair // Count unique accounts const uniqueAccounts = new Set(votingKeys.map(key => key.args[0].toString())); totalVoters = uniqueAccounts.size; } catch (err) { console.warn('Failed to fetch voters:', err); } // Update stats setStats({ activeProposals, totalVoters, tokensStaked, trustScore: 0 // TODO: Calculate trust score }); console.log('✅ Hero stats updated:', { activeProposals, totalVoters, tokensStaked }); } catch (error) { console.error('Failed to fetch hero stats:', error); } }; fetchStats(); }, [api, isApiReady]); return (
{/* Background Image */}
DKstate Background
{/* Content */}
Substrate Parachain v1.0

PezkuwiChain

{t('hero.title')}

{t('hero.subtitle')}

{/* Live Network Stats */}
{stats.activeProposals}
{t('hero.stats.activeProposals')}
{stats.totalVoters || '-'}
{t('hero.stats.totalVoters')}
{stats.tokensStaked || '-'}
{t('hero.stats.tokensStaked')}
{stats.trustScore ? `${stats.trustScore}%` : '-'}
{t('hero.stats.trustScore')}
); }; export default HeroSection;