mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-06-13 20:21:01 +00:00
fix: use getAllScoresWithFallback in Dashboard.tsx
Both AccountBalance.tsx and Dashboard.tsx now use the same frontend fallback for trust score calculation until runtime upgrade.
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 684 KiB |
@@ -1,91 +0,0 @@
|
|||||||
import { ApiPromise, WsProvider } from '@pezkuwi/api';
|
|
||||||
|
|
||||||
async function checkAllPools() {
|
|
||||||
const provider = new WsProvider('wss://asset-hub-rpc.pezkuwichain.io');
|
|
||||||
const api = await ApiPromise.create({ provider });
|
|
||||||
|
|
||||||
console.log('Connected to Asset Hub\n');
|
|
||||||
|
|
||||||
const userAddress = '5CyuFfbF95rzBxru7c9yEsX4XmQXUxpLUcbj9RLg9K1cGiiF';
|
|
||||||
|
|
||||||
// Get all pools
|
|
||||||
const poolKeys = await api.query.assetConversion.pools.keys();
|
|
||||||
console.log('=== ALL POOLS ===');
|
|
||||||
console.log('Total pools found:', poolKeys.length, '\n');
|
|
||||||
|
|
||||||
for (const key of poolKeys) {
|
|
||||||
const poolPair = key.args[0];
|
|
||||||
console.log('Pool key:', JSON.stringify(poolPair.toHuman()));
|
|
||||||
|
|
||||||
const poolInfo = await api.query.assetConversion.pools(poolPair);
|
|
||||||
if (!poolInfo.isEmpty) {
|
|
||||||
const poolData = poolInfo.unwrap().toJSON();
|
|
||||||
console.log('LP Token ID:', poolData.lpToken);
|
|
||||||
|
|
||||||
// Get LP supply
|
|
||||||
const lpAsset = await api.query.poolAssets.asset(poolData.lpToken);
|
|
||||||
if (lpAsset.isSome) {
|
|
||||||
const supply = lpAsset.unwrap().toJSON().supply;
|
|
||||||
console.log('Total LP Supply:', Number(BigInt(supply)) / 1e12);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get user's LP balance
|
|
||||||
const userLp = await api.query.poolAssets.account(poolData.lpToken, userAddress);
|
|
||||||
if (userLp.isSome) {
|
|
||||||
const balance = userLp.unwrap().toJSON().balance;
|
|
||||||
console.log('User LP Balance:', Number(BigInt(balance)) / 1e12);
|
|
||||||
} else {
|
|
||||||
console.log('User LP Balance: 0');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to get price
|
|
||||||
try {
|
|
||||||
const asset1 = poolPair[0];
|
|
||||||
const asset2 = poolPair[1];
|
|
||||||
const oneUnit = BigInt(1e12);
|
|
||||||
const quote = await api.call.assetConversionApi.quotePriceExactTokensForTokens(
|
|
||||||
asset1,
|
|
||||||
asset2,
|
|
||||||
oneUnit.toString(),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
if (quote && !quote.isNone) {
|
|
||||||
console.log('Price (1 asset1 -> asset2):', Number(BigInt(quote.unwrap().toString())) / 1e12);
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// Try with 6 decimals for USDT
|
|
||||||
try {
|
|
||||||
const asset1 = poolPair[0];
|
|
||||||
const asset2 = poolPair[1];
|
|
||||||
const oneUnit = BigInt(1e12);
|
|
||||||
const quote = await api.call.assetConversionApi.quotePriceExactTokensForTokens(
|
|
||||||
asset1,
|
|
||||||
asset2,
|
|
||||||
oneUnit.toString(),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
if (quote && !quote.isNone) {
|
|
||||||
console.log('Price (1 asset1 -> asset2):', Number(BigInt(quote.unwrap().toString())) / 1e6, 'USDT');
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
console.log('Could not get price');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
console.log('---');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check all LP token balances for user
|
|
||||||
console.log('\n=== USER LP TOKEN BALANCES ===');
|
|
||||||
for (let lpId = 0; lpId < 5; lpId++) {
|
|
||||||
const userLp = await api.query.poolAssets.account(lpId, userAddress);
|
|
||||||
if (userLp.isSome) {
|
|
||||||
const balance = userLp.unwrap().toJSON().balance;
|
|
||||||
console.log(`LP Token ${lpId}: ${Number(BigInt(balance)) / 1e12}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await api.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
checkAllPools().catch(console.error);
|
|
||||||
@@ -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 { 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 { useToast } from '@/hooks/use-toast';
|
||||||
import { fetchUserTikis, getPrimaryRole, getTikiDisplayName, getTikiColor, getTikiEmoji, getUserRoleCategories, getAllTikiNFTDetails, generateCitizenNumber, type TikiNFTDetails } from '@pezkuwi/lib/tiki';
|
import { fetchUserTikis, getPrimaryRole, getTikiDisplayName, getTikiColor, getTikiEmoji, getUserRoleCategories, getAllTikiNFTDetails, generateCitizenNumber, type TikiNFTDetails } from '@pezkuwi/lib/tiki';
|
||||||
import { getAllScores, getStakingScoreStatus, startScoreTracking, type UserScores, type StakingScoreStatus, formatDuration } from '@pezkuwi/lib/scores';
|
import { getAllScoresWithFallback, getStakingScoreStatus, startScoreTracking, type UserScores, type StakingScoreStatus, formatDuration } from '@pezkuwi/lib/scores';
|
||||||
import { web3FromAddress } from '@pezkuwi/extension-dapp';
|
import { web3FromAddress } from '@pezkuwi/extension-dapp';
|
||||||
import { getKycStatus } from '@pezkuwi/lib/kyc';
|
import { getKycStatus } from '@pezkuwi/lib/kyc';
|
||||||
import { ReferralDashboard } from '@/components/referral/ReferralDashboard';
|
import { ReferralDashboard } from '@/components/referral/ReferralDashboard';
|
||||||
@@ -108,10 +108,10 @@ export default function Dashboard() {
|
|||||||
|
|
||||||
setLoadingScores(true);
|
setLoadingScores(true);
|
||||||
try {
|
try {
|
||||||
// Fetch all scores from blockchain (includes trust, referral, staking, tiki)
|
// Fetch all scores with frontend fallback (until runtime upgrade)
|
||||||
// - Trust, referral, tiki, stakingScore: People Chain
|
// - Trust, referral, tiki: People Chain (on-chain)
|
||||||
// - Staking amount: Relay Chain (staking.ledger)
|
// - Staking: Relay Chain with frontend fallback
|
||||||
const allScores = await getAllScores(peopleApi, selectedAccount.address, api);
|
const allScores = await getAllScoresWithFallback(peopleApi, api, selectedAccount.address);
|
||||||
setScores(allScores);
|
setScores(allScores);
|
||||||
|
|
||||||
// Fetch staking score tracking status
|
// Fetch staking score tracking status
|
||||||
@@ -452,7 +452,7 @@ export default function Dashboard() {
|
|||||||
{loadingScores ? '...' : scores.trustScore}
|
{loadingScores ? '...' : scores.trustScore}
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-muted-foreground">
|
<p className="text-xs text-muted-foreground">
|
||||||
From pallet_trust
|
Frontend calculation
|
||||||
</p>
|
</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
Reference in New Issue
Block a user