mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-06-13 23:51:01 +00:00
fix: replace trust score card with citizen count (Hejmara Kurd)
This commit is contained in:
@@ -1,23 +1,18 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { ChevronRight, Shield, LogIn } from 'lucide-react';
|
import { ChevronRight, Shield } from 'lucide-react';
|
||||||
import { usePezkuwi } from '../contexts/PezkuwiContext';
|
import { usePezkuwi } from '../contexts/PezkuwiContext';
|
||||||
import { useWallet } from '../contexts/WalletContext';
|
|
||||||
import { formatBalance } from '@pezkuwi/lib/wallet';
|
import { formatBalance } from '@pezkuwi/lib/wallet';
|
||||||
import { getTrustScore } from '@pezkuwi/lib/scores';
|
|
||||||
import { getCurrentEra } from '@pezkuwi/lib/staking';
|
import { getCurrentEra } from '@pezkuwi/lib/staking';
|
||||||
|
|
||||||
const HeroSection: React.FC = () => {
|
const HeroSection: React.FC = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const navigate = useNavigate();
|
const { api, isApiReady, assetHubApi, isAssetHubReady, peopleApi, isPeopleReady } = usePezkuwi();
|
||||||
const { api, isApiReady, assetHubApi, isAssetHubReady, peopleApi } = usePezkuwi();
|
|
||||||
const { selectedAccount } = useWallet();
|
|
||||||
const [stats, setStats] = useState({
|
const [stats, setStats] = useState({
|
||||||
activeProposals: 0,
|
activeProposals: 0,
|
||||||
totalVoters: 0,
|
totalVoters: 0,
|
||||||
tokensStaked: '0',
|
tokensStaked: '0',
|
||||||
trustScore: null as number | null
|
citizenCount: null as number | null
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fetch governance stats from Relay Chain
|
// Fetch governance stats from Relay Chain
|
||||||
@@ -75,25 +70,27 @@ const HeroSection: React.FC = () => {
|
|||||||
fetchStakingStats();
|
fetchStakingStats();
|
||||||
}, [assetHubApi, isAssetHubReady]);
|
}, [assetHubApi, isAssetHubReady]);
|
||||||
|
|
||||||
// Fetch trust score from People Chain
|
// Fetch citizen count from People Chain
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchTrustScore = async () => {
|
const fetchCitizenCount = async () => {
|
||||||
if (!selectedAccount?.address) {
|
if (!peopleApi || !isPeopleReady) return;
|
||||||
setStats(prev => ({ ...prev, trustScore: null }));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!peopleApi) return;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const score = await getTrustScore(peopleApi, selectedAccount.address);
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
setStats(prev => ({ ...prev, trustScore: score }));
|
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) {
|
} catch (err) {
|
||||||
if (import.meta.env.DEV) console.warn('Failed to fetch trust score:', err);
|
if (import.meta.env.DEV) console.warn('Failed to fetch citizen count:', err);
|
||||||
setStats(prev => ({ ...prev, trustScore: 0 }));
|
setStats(prev => ({ ...prev, citizenCount: 0 }));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchTrustScore();
|
fetchCitizenCount();
|
||||||
}, [peopleApi, selectedAccount]);
|
}, [peopleApi, isPeopleReady]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="relative min-h-screen flex items-center justify-center overflow-hidden bg-gray-950">
|
<section className="relative min-h-screen flex items-center justify-center overflow-hidden bg-gray-950">
|
||||||
@@ -139,18 +136,8 @@ const HeroSection: React.FC = () => {
|
|||||||
<div className="text-xs sm:text-sm text-gray-300 font-medium">{t('hero.stats.tokensStaked', 'Tokens Staked')}</div>
|
<div className="text-xs sm:text-sm text-gray-300 font-medium">{t('hero.stats.tokensStaked', 'Tokens Staked')}</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="bg-gray-900/70 backdrop-blur-md rounded-xl border border-green-500/40 p-4 sm:p-6 hover:border-green-500/60 transition-all">
|
<div className="bg-gray-900/70 backdrop-blur-md rounded-xl border border-green-500/40 p-4 sm:p-6 hover:border-green-500/60 transition-all">
|
||||||
{stats.trustScore !== null ? (
|
<div className="text-base sm:text-2xl font-bold text-green-400 mb-2">{stats.citizenCount !== null ? stats.citizenCount.toLocaleString() : '...'}</div>
|
||||||
<div className="text-base sm:text-2xl font-bold text-green-400 mb-2">{stats.trustScore}</div>
|
<div className="text-xs sm:text-sm text-gray-300 font-medium">Hejmara Kurd Lê Cîhanê</div>
|
||||||
) : (
|
|
||||||
<button
|
|
||||||
onClick={() => navigate('/login')}
|
|
||||||
className="text-xs sm:text-sm font-medium text-green-400 hover:text-green-300 transition-colors flex items-center gap-1 mx-auto mb-2"
|
|
||||||
>
|
|
||||||
<LogIn className="w-3.5 h-3.5" />
|
|
||||||
{t('hero.stats.loginToSee', 'Görmek için giriş yapın')}
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
<div className="text-xs sm:text-sm text-gray-300 font-medium">{t('hero.stats.trustScore', 'Trust Score')}</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user