[INJIMOB-3381]: Check for different face fields and remove id during rendering (#2016)

* [INJIMOB-3381]: Check for different face fields and remove id during rendering

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3381]: Review comments addressed

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

* [INJIMOB-3381]: Face field null check updated

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>

---------

Signed-off-by: balachandarg-tw <balachandar.g@thoughtworks.com>
This commit is contained in:
balachandarg-tw
2025-07-15 17:01:22 +05:30
committed by GitHub
parent 28989d7f43
commit 9779972155
3 changed files with 53 additions and 4 deletions

View File

@@ -401,4 +401,6 @@ fileignoreconfig:
version: ""
- filename: shared/openID4VP/OpenID4VPHelper.ts
checksum: 2ab5f935ea3d1ec4d109d8614c2246f40e284594288566338f185611470e6928
- filename: components/VC/common/VCUtils.tsx
checksum: 221b56a2aeb73f39677cdb7c7528bfe17e49092ce785431d20b2cdfffb96d9cf
version: "1.0"

View File

@@ -159,6 +159,43 @@ export const getFieldName = (
return formatKeyLabel(field);
};
const ID = ['id'];
const IMAGE_KEYS = ['face', 'photo', 'picture', 'portrait', 'image'];
const EXCLUDED_FIELDS_FOR_RENDERING = [...ID, ...IMAGE_KEYS];
const shouldExcludeField = (field: string): boolean => {
const normalized = field.includes('~')
? field.split('~')[1]
: field.includes('.') || field.includes('[')
? field
.split('.')
.pop()
?.replace(/\[\d+\]/g, '') ?? field
: field;
return EXCLUDED_FIELDS_FOR_RENDERING.includes(normalized);
};
export function getFaceField(obj: any): string | null {
if (typeof obj !== 'object' || obj === null) return null;
for (const [key, value] of Object.entries(obj)) {
const normalizedKey = key.toLowerCase();
if (IMAGE_KEYS.includes(normalizedKey) && typeof value === 'string') {
return value;
}
if (typeof value === 'object') {
const found = getFaceField(value);
if (found) return found;
}
}
return null;
}
export function getAddressFields() {
return [
'addressLine1',
@@ -207,6 +244,8 @@ const renderFieldRecursively = (
.pop()
?.replace(/\[\d+\]/g, '') ?? key;
if (shouldExcludeField(shortKey)) return [];
if (value === null || value === undefined) return [];
// Handle arrays

View File

@@ -1,7 +1,10 @@
import {StateFrom} from 'xstate';
import {VCMetadata} from '../../../shared/VCMetadata';
import {VCItemMachine} from './VCItemMachine';
import {getMosipLogo} from '../../../components/VC/common/VCUtils';
import {
getFaceField,
getMosipLogo,
} from '../../../components/VC/common/VCUtils';
import {
Credential,
VerifiableCredential,
@@ -45,12 +48,17 @@ export function selectVerifiableCredentialData(
): VerifiableCredentialData {
const vcMetadata = new VCMetadata(state.context.vcMetadata);
const credentialSubject =
state.context.verifiableCredential?.credential?.credentialSubject ?? {};
const faceField =
getFaceField(credentialSubject) ??
state.context.credential?.biometrics?.face;
return {
vcMetadata: vcMetadata,
format: vcMetadata.format,
face:
state.context.verifiableCredential?.credential?.credentialSubject?.face ??
state.context.credential?.biometrics?.face,
face: faceField,
issuerLogo:
state.context.verifiableCredential?.issuerLogo ?? getMosipLogo(),
wellKnown: state.context.verifiableCredential?.wellKnown,