mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-04-22 02:07:55 +00:00
fix: convert hex AccountId to SS58 in referral/KYC queries
toJSON() returns hex format for AccountId fields but comparison was against SS58 addresses, causing referrer matching to always fail. - citizenship-workflow: encodeAddress for referrer in getPendingApprovals - citizenship-workflow: handle both PascalCase and camelCase KycStatus - referral: encodeAddress for referrer in getMyReferrals and getReferralInfo
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
// Handles citizenship verification, status checks, and workflow logic
|
||||
|
||||
import type { ApiPromise } from '@pezkuwi/api';
|
||||
import { encodeAddress } from '@pezkuwi/util-crypto';
|
||||
import { getSigner } from '@/lib/get-signer';
|
||||
import type { InjectedAccountWithMeta } from '@pezkuwi/extension-inject/types';
|
||||
|
||||
@@ -785,16 +786,30 @@ export async function getPendingApprovalsForReferrer(
|
||||
// An application is "pending" if it exists in applications but is NOT yet
|
||||
// approved in kycStatuses. Check referrer matches current user, or current
|
||||
// user is the founder (can approve any application).
|
||||
const isReferrer = appData.referrer?.toString() === referrerAddress;
|
||||
// Note: toJSON() returns hex for AccountId fields, convert to SS58 for comparison
|
||||
let referrerSS58 = '';
|
||||
try {
|
||||
if (appData.referrer) {
|
||||
referrerSS58 = encodeAddress(appData.referrer as string, 42);
|
||||
}
|
||||
} catch {
|
||||
referrerSS58 = appData.referrer?.toString() ?? '';
|
||||
}
|
||||
const isReferrer = referrerSS58 === referrerAddress;
|
||||
const isFounder = referrerAddress === FOUNDER_ADDRESS;
|
||||
|
||||
if (isReferrer || isFounder) {
|
||||
// Check if already approved via kycStatuses
|
||||
const kycStatus = await api.query.identityKyc.kycStatuses(applicantAddress);
|
||||
const statusStr = kycStatus.isEmpty ? null : kycStatus.toString();
|
||||
const statusJson = kycStatus.isEmpty ? null : kycStatus.toJSON?.() ?? kycStatus.toString();
|
||||
const statusStr = typeof statusJson === 'string' ? statusJson : null;
|
||||
|
||||
// Pending = not yet approved (no status or PendingReferral)
|
||||
if (!statusStr || statusStr === 'PendingReferral') {
|
||||
// Check both PascalCase and camelCase variants for safety
|
||||
const isPending = !statusStr ||
|
||||
statusStr === 'PendingReferral' ||
|
||||
statusStr === 'pendingReferral';
|
||||
if (isPending) {
|
||||
pending.push({
|
||||
applicantAddress,
|
||||
identityHash: (appData.identityHash as string) || ''
|
||||
|
||||
+15
-2
@@ -1,4 +1,5 @@
|
||||
import type { ApiPromise } from '@pezkuwi/api';
|
||||
import { encodeAddress } from '@pezkuwi/util-crypto';
|
||||
import type { InjectedAccountWithMeta } from '@pezkuwi/extension-inject/types';
|
||||
import type { Signer } from '@pezkuwi/api/types';
|
||||
|
||||
@@ -162,8 +163,13 @@ export async function getReferralInfo(
|
||||
}
|
||||
|
||||
const data = result.toJSON() as any;
|
||||
// toJSON() returns hex for AccountId, convert to SS58
|
||||
let referrerSS58 = data.referrer ?? '';
|
||||
try {
|
||||
if (data.referrer) referrerSS58 = encodeAddress(data.referrer, 42);
|
||||
} catch { /* keep hex as fallback */ }
|
||||
return {
|
||||
referrer: data.referrer,
|
||||
referrer: referrerSS58,
|
||||
createdAt: parseInt(data.createdAt),
|
||||
};
|
||||
} catch (error) {
|
||||
@@ -265,7 +271,14 @@ export async function getMyReferrals(
|
||||
.filter(([_key, value]) => {
|
||||
if (value.isEmpty) return false;
|
||||
const data = value.toJSON() as any;
|
||||
return data.referrer === referrerAddress;
|
||||
// toJSON() returns hex for AccountId, convert to SS58 for comparison
|
||||
let refSS58 = '';
|
||||
try {
|
||||
if (data.referrer) refSS58 = encodeAddress(data.referrer, 42);
|
||||
} catch {
|
||||
refSS58 = data.referrer ?? '';
|
||||
}
|
||||
return refSS58 === referrerAddress;
|
||||
})
|
||||
.map(([key]) => {
|
||||
// Extract the referred address from the storage key
|
||||
|
||||
Reference in New Issue
Block a user