From 99bc85f42e8a75dcb156943d8086e1a64eb1c26d Mon Sep 17 00:00:00 2001 From: Kurdistan Tech Ministry Date: Fri, 27 Feb 2026 04:14:35 +0300 Subject: [PATCH] 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. --- shared/lib/citizenship-workflow.ts | 33 +++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/shared/lib/citizenship-workflow.ts b/shared/lib/citizenship-workflow.ts index fd9060ea..9ba9351b 100644 --- a/shared/lib/citizenship-workflow.ts +++ b/shared/lib/citizenship-workflow.ts @@ -801,14 +801,33 @@ export async function getPendingApprovalsForReferrer( if (isReferrer || isFounder) { // Check if already approved via kycStatuses 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) - // Check both PascalCase and camelCase variants for safety - const isPending = !statusStr || - statusStr === 'PendingReferral' || - statusStr === 'pendingReferral'; + if (kycStatus.isEmpty) { + // No status at all — truly pending + pending.push({ + applicantAddress, + 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 = { 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) { pending.push({ applicantAddress,