From 4e85e28bce235d521c43fcc3e6a0817c1323b0ea Mon Sep 17 00:00:00 2001 From: Kurdistan Tech Ministry Date: Thu, 20 Nov 2025 19:10:38 +0300 Subject: [PATCH] fix: fetch referral scores from correct pallet storage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed getReferralScore() to read from pallet_referral::ReferralCount instead of non-existent pallet_trust::ReferralScores. Changes: - Read referral count from api.query.referral.referralCount - Implement proper score calculation logic: * 0 referrals: 0 points * 1-5 referrals: count × 4 points * 6-20 referrals: 20 + (count - 5) × 2 points * 21+ referrals: capped at 50 points - Add detailed documentation explaining score calculation - Remove warning spam in production (only warn in dev mode) This fixes the console warning "Referral scores not available in trust pallet" by using the actual pallet_referral storage that already exists and is properly maintained. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- shared/lib/scores.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/shared/lib/scores.ts b/shared/lib/scores.ts index 99cbf29e..bea005b2 100644 --- a/shared/lib/scores.ts +++ b/shared/lib/scores.ts @@ -125,25 +125,33 @@ export async function getTrustScoreDetails( /** * Fetch user's referral score - * pallet_trust::ReferralScores storage + * Reads from pallet_referral::ReferralCount storage + * + * Score calculation based on referral count: + * - 0 referrals: 0 points + * - 1-5 referrals: count × 4 points (4, 8, 12, 16, 20) + * - 6-20 referrals: 20 + (count - 5) × 2 points + * - 21+ referrals: capped at 50 points */ export async function getReferralScore( api: ApiPromise, address: string ): Promise { try { - if (!api?.query?.trust?.referralScores) { - console.warn('Referral scores not available in trust pallet'); + if (!api?.query?.referral?.referralCount) { + if (import.meta.env.DEV) console.warn('Referral pallet not available'); return 0; } - const score = await api.query.trust.referralScores(address); + const count = await api.query.referral.referralCount(address); + const referralCount = Number(count.toString()); - if (score.isEmpty) { - return 0; - } + // Calculate score based on referral count + if (referralCount === 0) return 0; + if (referralCount <= 5) return referralCount * 4; + if (referralCount <= 20) return 20 + ((referralCount - 5) * 2); + return 50; // Capped at 50 points - return Number(score.toString()); } catch (error) { console.error('Error fetching referral score:', error); return 0;