From 210fb0946960594375aa14f43e1b2b6043780c46 Mon Sep 17 00:00:00 2001 From: Kurdistan Tech Ministry Date: Tue, 17 Feb 2026 03:11:21 +0300 Subject: [PATCH] fix: hero stats - format staked tokens, real trust score, active-only proposals --- web/src/components/HeroSection.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/web/src/components/HeroSection.tsx b/web/src/components/HeroSection.tsx index 165f2daa..1d33e9ed 100644 --- a/web/src/components/HeroSection.tsx +++ b/web/src/components/HeroSection.tsx @@ -14,14 +14,14 @@ const HeroSection: React.FC = () => { activeProposals: 0, totalVoters: 0, tokensStaked: '0', - trustScore: 0 + trustScore: null as number | null }); useEffect(() => { const fetchStats = async () => { if (!api || !isApiReady) return; - let currentTrustScore = 0; // Default if not fetched or no account + let currentTrustScore: number | null = null; // null = not logged in if (selectedAccount?.address) { try { // Use frontend fallback for trust score @@ -35,11 +35,14 @@ const HeroSection: React.FC = () => { } try { - // Fetch active referenda + // Fetch active (ongoing) referenda only let activeProposals = 0; try { - const referendaCount = await api.query.referenda.referendumCount(); - activeProposals = referendaCount.toNumber(); + 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); } @@ -52,7 +55,10 @@ const HeroSection: React.FC = () => { const eraIndex = currentEra.unwrap().toNumber(); const totalStake = await api.query.staking.erasTotalStake(eraIndex); const formatted = formatBalance(totalStake.toString()); - tokensStaked = `${formatted} HEZ`; + 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:', err); @@ -137,7 +143,7 @@ const HeroSection: React.FC = () => {
{t('hero.stats.tokensStaked', 'Tokens Staked')}
-
{stats.trustScore}%
+
{stats.trustScore !== null ? stats.trustScore : t('hero.stats.loginToSee', 'Login')}
{t('hero.stats.trustScore', 'Trust Score')}