From 77f777dbcdb9e165162c4e5ba65ae6b30994d01c Mon Sep 17 00:00:00 2001 From: Kurdistan Tech Ministry Date: Sat, 1 Nov 2025 10:33:04 +0300 Subject: [PATCH] feat: Add total voters and tokens staked from blockchain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fetch total staked tokens from pallet_staking.erasTotalStake() - Count unique voters from pallet_conviction_voting.votingFor.keys() - Display real-time data instead of hardcoded values - Shows '-' when data is unavailable (e.g. no current era) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/components/HeroSection.tsx | 37 ++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/components/HeroSection.tsx b/src/components/HeroSection.tsx index b871622e..5ef812c2 100644 --- a/src/components/HeroSection.tsx +++ b/src/components/HeroSection.tsx @@ -29,13 +29,46 @@ const HeroSection: React.FC = () => { 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: 0, // TODO: Calculate from conviction voting - tokensStaked: '0', // TODO: Get from staking pallet + 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); }