mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-04-24 14:17:56 +00:00
refactor(scores): remove frontend fallback, read all scores from blockchain
Remove all frontend staking/trust score calculation and localStorage fallback code. All scores now read directly from People Chain pallets (pezpallet-trust, pezpallet-referral, pezpallet-tiki). Trust pallet computes composite score on-chain.
This commit is contained in:
@@ -8,7 +8,7 @@ import { AddTokenModal } from './AddTokenModal';
|
||||
import { TransferModal } from './TransferModal';
|
||||
import { XCMTeleportModal } from './XCMTeleportModal';
|
||||
import { LPStakeModal } from './LPStakeModal';
|
||||
import { getAllScoresWithFallback, type UserScores } from '@pezkuwi/lib/scores';
|
||||
import { getAllScores, type UserScores } from '@pezkuwi/lib/scores';
|
||||
|
||||
interface TokenBalance {
|
||||
assetId: number;
|
||||
@@ -570,11 +570,7 @@ export const AccountBalance: React.FC = () => {
|
||||
setLoadingScores(true);
|
||||
try {
|
||||
// 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
|
||||
);
|
||||
const userScores = await getAllScores(peopleApi || null, selectedAccount.address);
|
||||
setScores(userScores);
|
||||
} catch (err) {
|
||||
if (import.meta.env.DEV) console.error('Failed to fetch scores:', err);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ChevronRight, Shield } from 'lucide-react';
|
||||
import { usePezkuwi } from '../contexts/PezkuwiContext';
|
||||
import { useWallet } from '../contexts/WalletContext'; // Import useWallet
|
||||
import { formatBalance } from '@pezkuwi/lib/wallet';
|
||||
import { getTrustScoreWithFallback } from '@pezkuwi/lib/scores';
|
||||
import { getTrustScore } from '@pezkuwi/lib/scores';
|
||||
|
||||
const HeroSection: React.FC = () => {
|
||||
const { t } = useTranslation();
|
||||
@@ -25,12 +25,9 @@ const HeroSection: React.FC = () => {
|
||||
if (selectedAccount?.address) {
|
||||
try {
|
||||
// Use frontend fallback for trust score
|
||||
const trustResult = await getTrustScoreWithFallback(
|
||||
peopleApi || null,
|
||||
api,
|
||||
selectedAccount.address
|
||||
);
|
||||
currentTrustScore = trustResult.trustScore;
|
||||
if (peopleApi) {
|
||||
currentTrustScore = await getTrustScore(peopleApi, selectedAccount.address);
|
||||
}
|
||||
} catch (err) {
|
||||
if (import.meta.env.DEV) console.warn('Failed to fetch trust score:', err);
|
||||
currentTrustScore = 0;
|
||||
|
||||
@@ -26,6 +26,7 @@ export const WalletModal: React.FC<WalletModalProps> = ({ isOpen, onClose }) =>
|
||||
disconnectWallet,
|
||||
api,
|
||||
isApiReady,
|
||||
peopleApi,
|
||||
error
|
||||
} = usePezkuwi();
|
||||
|
||||
@@ -77,7 +78,7 @@ export const WalletModal: React.FC<WalletModalProps> = ({ isOpen, onClose }) =>
|
||||
|
||||
setLoadingScores(true);
|
||||
try {
|
||||
const userScores = await getAllScores(api, selectedAccount.address);
|
||||
const userScores = await getAllScores(peopleApi || null, selectedAccount.address);
|
||||
setScores(userScores);
|
||||
} catch (err) {
|
||||
if (import.meta.env.DEV) console.error('Failed to fetch scores:', err);
|
||||
@@ -94,7 +95,7 @@ export const WalletModal: React.FC<WalletModalProps> = ({ isOpen, onClose }) =>
|
||||
};
|
||||
|
||||
fetchAllScores();
|
||||
}, [api, isApiReady, selectedAccount]);
|
||||
}, [api, isApiReady, peopleApi, selectedAccount]);
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={onClose}>
|
||||
|
||||
@@ -10,7 +10,7 @@ import { supabase } from '@/lib/supabase';
|
||||
import { User, Mail, Phone, Globe, MapPin, Calendar, Shield, AlertCircle, ArrowLeft, Award, Users, TrendingUp, UserMinus, Play, Loader2 } from 'lucide-react';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import { fetchUserTikis, getPrimaryRole, getTikiDisplayName, getTikiColor, getTikiEmoji, getUserRoleCategories, getAllTikiNFTDetails, generateCitizenNumber, type TikiNFTDetails } from '@pezkuwi/lib/tiki';
|
||||
import { getAllScoresWithFallback, getStakingScoreStatus, startScoreTracking, type UserScores, type StakingScoreStatus, formatDuration } from '@pezkuwi/lib/scores';
|
||||
import { getAllScores, getStakingScoreStatus, startScoreTracking, type UserScores, type StakingScoreStatus, formatDuration } from '@pezkuwi/lib/scores';
|
||||
import { web3FromAddress } from '@pezkuwi/extension-dapp';
|
||||
import { getKycStatus } from '@pezkuwi/lib/kyc';
|
||||
import { ReferralDashboard } from '@/components/referral/ReferralDashboard';
|
||||
@@ -111,7 +111,7 @@ export default function Dashboard() {
|
||||
// Fetch all scores with frontend fallback (until runtime upgrade)
|
||||
// - Trust, referral, tiki: People Chain (on-chain)
|
||||
// - Staking: Relay Chain with frontend fallback
|
||||
const allScores = await getAllScoresWithFallback(peopleApi, api, selectedAccount.address);
|
||||
const allScores = await getAllScores(peopleApi, selectedAccount.address);
|
||||
setScores(allScores);
|
||||
|
||||
// Fetch staking score tracking status
|
||||
|
||||
Reference in New Issue
Block a user