mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-06-13 21:31:01 +00:00
fix: correct trust score divisor to 10000 and show both relay+PEZ treasury balances
This commit is contained in:
@@ -47,7 +47,7 @@ const TrustScoreCalculator: React.FC = () => {
|
|||||||
perwerdeScore * 300 +
|
perwerdeScore * 300 +
|
||||||
tikiScore * 300;
|
tikiScore * 300;
|
||||||
|
|
||||||
const score = (adjustedStaking * weightedSum) / 1000;
|
const score = (adjustedStaking * weightedSum) / 10000;
|
||||||
setFinalScore(Math.round(score));
|
setFinalScore(Math.round(score));
|
||||||
}, [stakedAmount, stakingMonths, referralCount, perwerdeScore, tikiScore]);
|
}, [stakedAmount, stakingMonths, referralCount, perwerdeScore, tikiScore]);
|
||||||
|
|
||||||
@@ -203,7 +203,7 @@ const TrustScoreCalculator: React.FC = () => {
|
|||||||
tiki × 300
|
tiki × 300
|
||||||
</div>
|
</div>
|
||||||
<div className="text-cyan-400">
|
<div className="text-cyan-400">
|
||||||
final_score = staking × weighted_sum / 1000
|
final_score = staking × weighted_sum / 10000
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -21,11 +21,16 @@ interface GovernanceStats {
|
|||||||
diwanMax: number;
|
diwanMax: number;
|
||||||
pendingVotes: number;
|
pendingVotes: number;
|
||||||
diwanPendingReviews: number;
|
diwanPendingReviews: number;
|
||||||
treasuryBalance: string;
|
relayTreasuryBalance: string;
|
||||||
|
pezTreasuryBalance: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Treasury addresses derived from PalletId
|
||||||
|
const RELAY_TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z'; // py/trsry
|
||||||
|
const PEZ_TREASURY = '5EYCAe5iipewaoUvoNr8ttcKqj5czZPBvVAex6uWbT6HxQNU'; // pez/trea (Asset Hub)
|
||||||
|
|
||||||
const GovernanceOverview: React.FC = () => {
|
const GovernanceOverview: React.FC = () => {
|
||||||
const { api, isApiReady } = usePezkuwi();
|
const { api, isApiReady, assetHubApi, isAssetHubReady } = usePezkuwi();
|
||||||
const [stats, setStats] = useState<GovernanceStats>({
|
const [stats, setStats] = useState<GovernanceStats>({
|
||||||
activeProposals: 0,
|
activeProposals: 0,
|
||||||
activeElections: 0,
|
activeElections: 0,
|
||||||
@@ -37,7 +42,8 @@ const GovernanceOverview: React.FC = () => {
|
|||||||
diwanMax: 9,
|
diwanMax: 9,
|
||||||
pendingVotes: 0,
|
pendingVotes: 0,
|
||||||
diwanPendingReviews: 0,
|
diwanPendingReviews: 0,
|
||||||
treasuryBalance: '0 HEZ'
|
relayTreasuryBalance: '0 HEZ',
|
||||||
|
pezTreasuryBalance: '0 PEZ'
|
||||||
});
|
});
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
@@ -98,17 +104,31 @@ const GovernanceOverview: React.FC = () => {
|
|||||||
if (import.meta.env.DEV) console.warn('Failed to fetch diwan members:', err);
|
if (import.meta.env.DEV) console.warn('Failed to fetch diwan members:', err);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch treasury balance
|
// Fetch Relay Chain treasury balance (native HEZ)
|
||||||
let treasuryBalance = '0 HEZ';
|
let relayTreasuryBalance = '0 HEZ';
|
||||||
try {
|
try {
|
||||||
const treasuryAccount = await api.query.system.account(
|
const treasuryAccount = await api.query.system.account(RELAY_TREASURY);
|
||||||
'5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z' // Treasury pallet address
|
|
||||||
);
|
|
||||||
const balance = treasuryAccount.data.free.toString();
|
const balance = treasuryAccount.data.free.toString();
|
||||||
treasuryBalance = `${formatBalance(balance)} HEZ`;
|
relayTreasuryBalance = `${formatBalance(balance)} HEZ`;
|
||||||
if (import.meta.env.DEV) console.log('Treasury balance:', treasuryBalance);
|
if (import.meta.env.DEV) console.log('Relay treasury balance:', relayTreasuryBalance);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (import.meta.env.DEV) console.warn('Failed to fetch treasury balance:', err);
|
if (import.meta.env.DEV) console.warn('Failed to fetch relay treasury balance:', err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch PEZ Treasury balance (PEZ token, asset ID 1, on Asset Hub)
|
||||||
|
let pezTreasuryBalance = '0 PEZ';
|
||||||
|
try {
|
||||||
|
if (assetHubApi && isAssetHubReady) {
|
||||||
|
const pezBalance = await assetHubApi.query.assets.account(1, PEZ_TREASURY);
|
||||||
|
if (pezBalance.isSome) {
|
||||||
|
const balanceData = (pezBalance.unwrap() as any).toJSON();
|
||||||
|
const rawBalance = (balanceData.balance ?? balanceData.free ?? '0').toString();
|
||||||
|
pezTreasuryBalance = `${formatBalance(rawBalance)} PEZ`;
|
||||||
|
}
|
||||||
|
if (import.meta.env.DEV) console.log('PEZ treasury balance:', pezTreasuryBalance);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (import.meta.env.DEV) console.warn('Failed to fetch PEZ treasury balance:', err);
|
||||||
}
|
}
|
||||||
|
|
||||||
setStats({
|
setStats({
|
||||||
@@ -122,7 +142,8 @@ const GovernanceOverview: React.FC = () => {
|
|||||||
diwanMax: 9,
|
diwanMax: 9,
|
||||||
pendingVotes,
|
pendingVotes,
|
||||||
diwanPendingReviews,
|
diwanPendingReviews,
|
||||||
treasuryBalance
|
relayTreasuryBalance,
|
||||||
|
pezTreasuryBalance
|
||||||
});
|
});
|
||||||
|
|
||||||
if (import.meta.env.DEV) console.log('Governance data updated:', {
|
if (import.meta.env.DEV) console.log('Governance data updated:', {
|
||||||
@@ -130,7 +151,8 @@ const GovernanceOverview: React.FC = () => {
|
|||||||
activeElections,
|
activeElections,
|
||||||
parliamentMembers,
|
parliamentMembers,
|
||||||
diwanMembers,
|
diwanMembers,
|
||||||
treasuryBalance
|
relayTreasuryBalance,
|
||||||
|
pezTreasuryBalance
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (import.meta.env.DEV) console.error('Failed to fetch governance data:', error);
|
if (import.meta.env.DEV) console.error('Failed to fetch governance data:', error);
|
||||||
@@ -140,7 +162,7 @@ const GovernanceOverview: React.FC = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fetchGovernanceData();
|
fetchGovernanceData();
|
||||||
}, [api, isApiReady]);
|
}, [api, isApiReady, assetHubApi, isAssetHubReady]);
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <LoadingState message="Loading governance data..." />;
|
return <LoadingState message="Loading governance data..." />;
|
||||||
@@ -196,9 +218,9 @@ const GovernanceOverview: React.FC = () => {
|
|||||||
<CardContent className="p-6">
|
<CardContent className="p-6">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<div>
|
<div>
|
||||||
<p className="text-gray-400 text-sm">Treasury Balance</p>
|
<p className="text-gray-400 text-sm">Treasury</p>
|
||||||
<p className="text-2xl font-bold text-white mt-1">{stats.treasuryBalance}</p>
|
<p className="text-lg font-bold text-white mt-1">{stats.pezTreasuryBalance}</p>
|
||||||
<p className="text-xs text-yellow-400 mt-2">Available for proposals</p>
|
<p className="text-sm text-gray-400 mt-1">{stats.relayTreasuryBalance}</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="p-3 bg-yellow-500/10 rounded-lg">
|
<div className="p-3 bg-yellow-500/10 rounded-lg">
|
||||||
<Shield className="w-6 h-6 text-yellow-400" />
|
<Shield className="w-6 h-6 text-yellow-400" />
|
||||||
|
|||||||
Reference in New Issue
Block a user