mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-06-13 19:11:01 +00:00
feat: Add total voters and tokens staked from blockchain
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -29,13 +29,46 @@ const HeroSection: React.FC = () => {
|
|||||||
console.warn('Failed to fetch referenda:', 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
|
// Update stats
|
||||||
setStats({
|
setStats({
|
||||||
activeProposals,
|
activeProposals,
|
||||||
totalVoters: 0, // TODO: Calculate from conviction voting
|
totalVoters,
|
||||||
tokensStaked: '0', // TODO: Get from staking pallet
|
tokensStaked,
|
||||||
trustScore: 0 // TODO: Calculate trust score
|
trustScore: 0 // TODO: Calculate trust score
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('✅ Hero stats updated:', {
|
||||||
|
activeProposals,
|
||||||
|
totalVoters,
|
||||||
|
tokensStaked
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch hero stats:', error);
|
console.error('Failed to fetch hero stats:', error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user