fix: use dynamic SS58 prefix in referral/KYC address encoding

Replace hardcoded SS58 prefix 42 with api.registry.chainSS58 ?? 42
for robustness in getPendingApprovalsForReferrer, getReferralInfo,
and getMyReferrals functions.
This commit is contained in:
2026-02-28 01:59:04 +03:00
parent fd57a75fd9
commit a8505a4d50
2 changed files with 4 additions and 3 deletions
+2 -1
View File
@@ -790,7 +790,8 @@ export async function getPendingApprovalsForReferrer(
let referrerSS58 = '';
try {
if (appData.referrer) {
referrerSS58 = encodeAddress(appData.referrer as string, 42);
const ss58Prefix = api.registry.chainSS58 ?? 42;
referrerSS58 = encodeAddress(appData.referrer as string, ss58Prefix);
}
} catch {
referrerSS58 = appData.referrer?.toString() ?? '';
+2 -2
View File
@@ -166,7 +166,7 @@ export async function getReferralInfo(
// toJSON() returns hex for AccountId, convert to SS58
let referrerSS58 = data.referrer ?? '';
try {
if (data.referrer) referrerSS58 = encodeAddress(data.referrer, 42);
if (data.referrer) referrerSS58 = encodeAddress(data.referrer, api.registry.chainSS58 ?? 42);
} catch { /* keep hex as fallback */ }
return {
referrer: referrerSS58,
@@ -274,7 +274,7 @@ export async function getMyReferrals(
// toJSON() returns hex for AccountId, convert to SS58 for comparison
let refSS58 = '';
try {
if (data.referrer) refSS58 = encodeAddress(data.referrer, 42);
if (data.referrer) refSS58 = encodeAddress(data.referrer, api.registry.chainSS58 ?? 42);
} catch {
refSS58 = data.referrer ?? '';
}