mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-04-22 05:37:56 +00:00
fix: handle all kycStatus formats in pending approvals check
toJSON() for Substrate enums can return string, object ({"approved":null}),
or number (enum index). Previous code assumed string only, causing already
approved applications to appear as pending.
This commit is contained in:
@@ -801,14 +801,33 @@ export async function getPendingApprovalsForReferrer(
|
|||||||
if (isReferrer || isFounder) {
|
if (isReferrer || isFounder) {
|
||||||
// Check if already approved via kycStatuses
|
// Check if already approved via kycStatuses
|
||||||
const kycStatus = await api.query.identityKyc.kycStatuses(applicantAddress);
|
const kycStatus = await api.query.identityKyc.kycStatuses(applicantAddress);
|
||||||
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 (kycStatus.isEmpty) {
|
||||||
// Check both PascalCase and camelCase variants for safety
|
// No status at all — truly pending
|
||||||
const isPending = !statusStr ||
|
pending.push({
|
||||||
statusStr === 'PendingReferral' ||
|
applicantAddress,
|
||||||
statusStr === 'pendingReferral';
|
identityHash: (appData.identityHash as string) || ''
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse status — toJSON() can return string, object, or number:
|
||||||
|
// string: "PendingReferral" / "pendingReferral"
|
||||||
|
// object: { "pendingReferral": null }
|
||||||
|
// number: enum index (0=PendingReferral, 1=ReferrerApproved, 2=Approved, 3=Revoked)
|
||||||
|
const statusJson = kycStatus.toJSON?.() ?? kycStatus.toString();
|
||||||
|
let statusKey = '';
|
||||||
|
if (typeof statusJson === 'string') {
|
||||||
|
statusKey = statusJson.toLowerCase();
|
||||||
|
} else if (typeof statusJson === 'object' && statusJson !== null) {
|
||||||
|
statusKey = Object.keys(statusJson)[0]?.toLowerCase() ?? '';
|
||||||
|
} else if (typeof statusJson === 'number') {
|
||||||
|
const enumMap: Record<number, string> = { 0: 'pendingreferral', 1: 'referrerapproved', 2: 'approved', 3: 'revoked' };
|
||||||
|
statusKey = enumMap[statusJson] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only show as pending if status is actually PendingReferral
|
||||||
|
const isPending = statusKey === 'pendingreferral';
|
||||||
if (isPending) {
|
if (isPending) {
|
||||||
pending.push({
|
pending.push({
|
||||||
applicantAddress,
|
applicantAddress,
|
||||||
|
|||||||
Reference in New Issue
Block a user