diff --git a/web/src/components/TrustScoreCalculator.tsx b/web/src/components/TrustScoreCalculator.tsx index 414c2c19..a004372e 100644 --- a/web/src/components/TrustScoreCalculator.tsx +++ b/web/src/components/TrustScoreCalculator.tsx @@ -26,12 +26,13 @@ const TrustScoreCalculator: React.FC = () => { return 2.0; }; - // Calculate referral score + // Calculate referral score (matches pezpallet-referral tiered scoring) const getReferralScore = (count: number) => { if (count === 0) return 0; - if (count <= 5) return count * 4; - if (count <= 20) return 20 + ((count - 5) * 2); - return 50; + if (count <= 10) return count * 10; + if (count <= 50) return 100 + ((count - 10) * 5); + if (count <= 100) return 300 + ((count - 50) * 4); + return 500; }; useEffect(() => { @@ -120,7 +121,7 @@ const TrustScoreCalculator: React.FC = () => { setReferralCount(parseInt(e.target.value) || 0)} className="w-full mt-2 px-4 py-2 bg-gray-800 text-white rounded-lg border border-gray-700 focus:border-cyan-500 focus:outline-none" @@ -157,7 +158,7 @@ const TrustScoreCalculator: React.FC = () => { setTikiScore(parseInt(e.target.value))} className="w-full" diff --git a/web/src/components/governance/GovernanceOverview.tsx b/web/src/components/governance/GovernanceOverview.tsx index 486f6d65..989e8f47 100644 --- a/web/src/components/governance/GovernanceOverview.tsx +++ b/web/src/components/governance/GovernanceOverview.tsx @@ -1,15 +1,14 @@ import React, { useState, useEffect } from 'react'; import { - Vote, Users, Gavel, FileText, TrendingUpIcon, - CheckCircle, - PieChart, Activity, Shield + Users, Gavel, FileText, TrendingUpIcon, + Shield } from 'lucide-react'; import { Card, CardContent, CardHeader, CardTitle } from '../ui/card'; import { Badge } from '../ui/badge'; -import { Progress } from '../ui/progress'; import { usePezkuwi } from '../../contexts/PezkuwiContext'; import { formatBalance } from '@pezkuwi/lib/wallet'; import { LoadingState } from '@pezkuwi/components/AsyncComponent'; +import { getActiveElections, getActiveProposals, getParliamentMembers, getDiwanMembers } from '@pezkuwi/lib/welati'; interface GovernanceStats { activeProposals: number; @@ -17,8 +16,11 @@ interface GovernanceStats { totalVoters: number; participationRate: number; parliamentMembers: number; + parliamentMax: number; diwanMembers: number; - nextElection: string; + diwanMax: number; + pendingVotes: number; + diwanPendingReviews: number; treasuryBalance: string; } @@ -30,8 +32,11 @@ const GovernanceOverview: React.FC = () => { totalVoters: 0, participationRate: 0, parliamentMembers: 0, + parliamentMax: 201, diwanMembers: 0, - nextElection: '-', + diwanMax: 9, + pendingVotes: 0, + diwanPendingReviews: 0, treasuryBalance: '0 HEZ' }); const [loading, setLoading] = useState(true); @@ -44,17 +49,53 @@ const GovernanceOverview: React.FC = () => { } try { - if (import.meta.env.DEV) console.log('📊 Fetching governance data from blockchain...'); + if (import.meta.env.DEV) console.log('Fetching governance data from blockchain...'); setLoading(true); - // Fetch active referenda (proposals) + // Fetch active proposals via welati let activeProposals = 0; + let pendingVotes = 0; + let diwanPendingReviews = 0; try { - const referendaCount = await api.query.referenda.referendumCount(); - if (import.meta.env.DEV) console.log('Referenda count:', referendaCount.toNumber()); - activeProposals = referendaCount.toNumber(); + const proposals = await getActiveProposals(api); + activeProposals = proposals.length; + pendingVotes = proposals.length; + diwanPendingReviews = proposals.filter( + p => p.decisionType === 'ConstitutionalReview' || p.decisionType === 'ConstitutionalUnanimous' + ).length; + if (import.meta.env.DEV) console.log('Active proposals:', activeProposals); } catch (err) { - if (import.meta.env.DEV) console.warn('Failed to fetch referenda count:', err); + if (import.meta.env.DEV) console.warn('Failed to fetch proposals:', err); + } + + // Fetch active elections via welati + let activeElections = 0; + try { + const elections = await getActiveElections(api); + activeElections = elections.length; + if (import.meta.env.DEV) console.log('Active elections:', activeElections); + } catch (err) { + if (import.meta.env.DEV) console.warn('Failed to fetch elections:', err); + } + + // Fetch parliament members via welati + let parliamentMembers = 0; + try { + const members = await getParliamentMembers(api); + parliamentMembers = members.length; + if (import.meta.env.DEV) console.log('Parliament members:', parliamentMembers); + } catch (err) { + if (import.meta.env.DEV) console.warn('Failed to fetch parliament members:', err); + } + + // Fetch diwan members via welati + let diwanMembers = 0; + try { + const members = await getDiwanMembers(api); + diwanMembers = members.length; + if (import.meta.env.DEV) console.log('Diwan members:', diwanMembers); + } catch (err) { + if (import.meta.env.DEV) console.warn('Failed to fetch diwan members:', err); } // Fetch treasury balance @@ -70,31 +111,25 @@ const GovernanceOverview: React.FC = () => { if (import.meta.env.DEV) console.warn('Failed to fetch treasury balance:', err); } - // Fetch council members - let parliamentMembers = 0; - try { - const members = await api.query.council.members(); - parliamentMembers = members.length; - if (import.meta.env.DEV) console.log('Council members:', parliamentMembers); - } catch (err) { - if (import.meta.env.DEV) console.warn('Failed to fetch council members:', err); - } - - // Update stats setStats({ activeProposals, - activeElections: 0, // Not implemented yet - totalVoters: 0, // Will be calculated from conviction voting + activeElections, + totalVoters: 0, participationRate: 0, parliamentMembers, - diwanMembers: 0, // Not implemented yet - nextElection: '-', + parliamentMax: 201, + diwanMembers, + diwanMax: 9, + pendingVotes, + diwanPendingReviews, treasuryBalance }); - if (import.meta.env.DEV) console.log('✅ Governance data updated:', { + if (import.meta.env.DEV) console.log('Governance data updated:', { activeProposals, + activeElections, parliamentMembers, + diwanMembers, treasuryBalance }); } catch (error) { @@ -107,23 +142,6 @@ const GovernanceOverview: React.FC = () => { fetchGovernanceData(); }, [api, isApiReady]); - const [recentActivity] = useState([ - { type: 'proposal', action: 'New proposal submitted', title: 'Treasury Allocation Update', time: '2 hours ago' }, - { type: 'vote', action: 'Vote cast', title: 'Infrastructure Development Fund', time: '3 hours ago' }, - { type: 'election', action: 'Election started', title: 'Parliamentary Elections 2024', time: '1 day ago' }, - { type: 'approved', action: 'Proposal approved', title: 'Community Grant Program', time: '2 days ago' } - ]); - - const getActivityIcon = (type: string) => { - switch(type) { - case 'proposal': return ; - case 'vote': return ; - case 'election': return ; - case 'approved': return ; - default: return ; - } - }; - if (loading) { return ; } @@ -138,7 +156,6 @@ const GovernanceOverview: React.FC = () => {

Active Proposals

{stats.activeProposals}

-

+3 this week

@@ -153,7 +170,6 @@ const GovernanceOverview: React.FC = () => {

Active Elections

{stats.activeElections}

-

Next in {stats.nextElection}

@@ -166,9 +182,8 @@ const GovernanceOverview: React.FC = () => {
-

Participation Rate

-

{stats.participationRate}%

- +

Total Voters

+

{stats.totalVoters}

@@ -206,21 +221,17 @@ const GovernanceOverview: React.FC = () => {
Active Members - {stats.parliamentMembers}/27 -
-
- Current Session - In Session + {stats.parliamentMembers}/{stats.parliamentMax}
+ {stats.activeElections > 0 && ( +
+ Elections + Active +
+ )}
Pending Votes - 5 -
-
-
- Quorum Status - Met (85%) -
+ {stats.pendingVotes}
@@ -230,94 +241,25 @@ const GovernanceOverview: React.FC = () => { - Dîwan (Constitutional Court) + Diwan (Constitutional Court)
Active Judges - {stats.diwanMembers}/9 + {stats.diwanMembers}/{stats.diwanMax}
Pending Reviews - 3 -
-
- Recent Decisions - 12 -
-
-
- Next Hearing - Tomorrow, 14:00 UTC -
+ {stats.diwanPendingReviews}
- - {/* Recent Activity */} - - - - - Recent Governance Activity - - - -
- {recentActivity.map((activity, index) => ( -
- {getActivityIcon(activity.type)} -
-

{activity.action}

-

{activity.title}

-
- {activity.time} -
- ))} -
-
-
- - {/* Voting Power Distribution */} - - - - - Voting Power Distribution - - - -
-
-
- Direct Votes - 45% -
- -
-
-
- Delegated Votes - 35% -
- -
-
-
- Proxy Votes - 20% -
- -
-
-
-
); }; -export default GovernanceOverview; \ No newline at end of file +export default GovernanceOverview;