import React, { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { ChevronRight, Shield } from 'lucide-react'; import { usePezkuwi } from '../contexts/PezkuwiContext'; import { formatBalance } from '@pezkuwi/lib/wallet'; const HeroSection: React.FC = () => { const { t } = useTranslation(); const { api, isApiReady, assetHubApi, isAssetHubReady, peopleApi, isPeopleReady } = usePezkuwi(); const [stats, setStats] = useState({ activeProposals: 0, totalVoters: 0, tokensStaked: '0', citizenCount: null as number | null }); // Fetch governance stats from Relay Chain useEffect(() => { const fetchGovernanceStats = async () => { if (!api || !isApiReady) return; let activeProposals = 0; try { const entries = await api.query.referenda.referendumInfoFor.entries(); activeProposals = entries.filter(([, info]) => { const data = info.toJSON(); return data && typeof data === 'object' && 'ongoing' in data; }).length; } catch (err) { if (import.meta.env.DEV) console.warn('Failed to fetch referenda:', err); } let totalVoters = 0; try { const votingKeys = await api.query.convictionVoting.votingFor.keys(); const uniqueAccounts = new Set(votingKeys.map(key => key.args[0].toString())); totalVoters = uniqueAccounts.size; } catch (err) { if (import.meta.env.DEV) console.warn('Failed to fetch voters:', err); } setStats(prev => ({ ...prev, activeProposals, totalVoters })); }; fetchGovernanceStats(); }, [api, isApiReady]); // Fetch staking stats from Asset Hub useEffect(() => { const fetchStakingStats = async () => { if (!assetHubApi || !isAssetHubReady) return; let tokensStaked = '0'; try { // Sum active stakes from all ledger entries const ledgers = await assetHubApi.query.staking.ledger.entries(); let totalActive = BigInt(0); for (const [, ledger] of ledgers) { if (!ledger.isEmpty) { // eslint-disable-next-line @typescript-eslint/no-explicit-any const data = (ledger as any).unwrap?.() ? (ledger as any).unwrap().toJSON() : (ledger as any).toJSON(); totalActive += BigInt(data?.active ?? data?.total ?? '0'); } } const formatted = formatBalance(totalActive.toString()); const [whole, frac] = formatted.split('.'); const formattedWhole = Number(whole).toLocaleString(); const formattedFrac = (frac || '00').slice(0, 2); tokensStaked = `${formattedWhole}.${formattedFrac} HEZ`; } catch (err) { if (import.meta.env.DEV) console.warn('Failed to fetch total stake from AH:', err); } setStats(prev => ({ ...prev, tokensStaked })); }; fetchStakingStats(); }, [assetHubApi, isAssetHubReady]); // Fetch citizen count from People Chain useEffect(() => { const fetchCitizenCount = async () => { if (!peopleApi || !isPeopleReady) return; try { // eslint-disable-next-line @typescript-eslint/no-explicit-any if (!(peopleApi.query as any)?.tiki?.citizenNft) { setStats(prev => ({ ...prev, citizenCount: 0 })); return; } // eslint-disable-next-line @typescript-eslint/no-explicit-any const entries = await (peopleApi.query as any).tiki.citizenNft.entries(); setStats(prev => ({ ...prev, citizenCount: entries.length })); } catch (err) { if (import.meta.env.DEV) console.warn('Failed to fetch citizen count:', err); setStats(prev => ({ ...prev, citizenCount: 0 })); } }; fetchCitizenCount(); }, [peopleApi, isPeopleReady]); return (
{/* Background Image */}
DKstate Background
{/* Content */}
Digital Kurdistan State v1.0

PezkuwiChain

{t('hero.title', 'Blockchain Governance Platform')}

{t('hero.subtitle', 'Democratic and transparent governance with blockchain technology')}

{stats.activeProposals}
{t('hero.stats.activeProposals', 'Active Proposals')}
{stats.totalVoters.toLocaleString()}
{t('hero.stats.totalVoters', 'Total Voters')}
{stats.tokensStaked}
{t('hero.stats.tokensStaked', 'Tokens Staked')}
{stats.citizenCount !== null ? stats.citizenCount.toLocaleString() : '...'}
Hejmara Kurd Lê Cîhanê
); }; export default HeroSection;