feat: add frontend fallback for staking and trust scores

Until runtime upgrade is deployed, calculate scores on frontend:

shared/lib/scores.ts:
- getFrontendStakingScore: Read stake from Relay Chain, track in localStorage
- getFrontendTrustScore: Calculate using pallet formula
- getAllScoresWithFallback: Combined score fetching with fallback

Formula (matching pezpallet-trust):
- weighted_sum = staking*100 + referral*300 + perwerde*300 + tiki*300
- trust_score = (staking * weighted_sum) / 100

Components updated:
- AccountBalance.tsx: Use getAllScoresWithFallback
- HeroSection.tsx: Use getTrustScoreWithFallback
This commit is contained in:
2026-02-07 00:44:04 +03:00
parent f93681ed96
commit 90b8204c25
3 changed files with 537 additions and 18 deletions
+8 -3
View File
@@ -8,7 +8,7 @@ import { AddTokenModal } from './AddTokenModal';
import { TransferModal } from './TransferModal';
import { XCMTeleportModal } from './XCMTeleportModal';
import { LPStakeModal } from './LPStakeModal';
import { getAllScores, type UserScores } from '@pezkuwi/lib/scores';
import { getAllScoresWithFallback, type UserScores } from '@pezkuwi/lib/scores';
interface TokenBalance {
assetId: number;
@@ -554,7 +554,7 @@ export const AccountBalance: React.FC = () => {
fetchBalance();
fetchTokenPrices(); // Fetch token USD prices from pools
// Fetch All Scores from blockchain
// Fetch All Scores from blockchain with frontend fallback
const fetchAllScores = async () => {
if (!api || !isApiReady || !selectedAccount?.address) {
setScores({
@@ -569,7 +569,12 @@ export const AccountBalance: React.FC = () => {
setLoadingScores(true);
try {
const userScores = await getAllScores(api, selectedAccount.address);
// Use fallback function: peopleApi for on-chain scores, api (Relay) for staking data
const userScores = await getAllScoresWithFallback(
peopleApi || null, // People Chain for referral, tiki, perwerde
api, // Relay Chain for staking data
selectedAccount.address
);
setScores(userScores);
} catch (err) {
if (import.meta.env.DEV) console.error('Failed to fetch scores:', err);