Skip to content

Commit 3ff656b

Browse files
authored
fix(IT Wallet): [SIW-2685] parse nationalities claim (#7182)
## Short description This PR adds a decoder for a simple list of strings, so the country codes of the nationality claim can be displayed correctly. ## List of changes proposed in this pull request - Added `SimpleListClaim` decoder - Removed redundant `else if` ## How to test Activate the Wallet using the new API v1.0 and ensure the eID preview and detail correctly display the nationalities. <img width="320" alt="eid_preview" src="https://github.com/user-attachments/assets/6fd1d782-4783-465a-bfd8-131ef69e7274" /> <img width="320" alt="eid_detail" src="https://github.com/user-attachments/assets/0a713ab2-99dc-47f3-8a8f-aa53411fa00e" />
1 parent c5ea48f commit 3ff656b

File tree

3 files changed

+63
-17
lines changed

3 files changed

+63
-17
lines changed

ts/features/itwallet/common/components/ItwCredentialClaim.tsx

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
PlaceOfBirthClaimType,
2424
SimpleDate,
2525
SimpleDateClaim,
26+
SimpleListClaim,
2627
StringClaim
2728
} from "../utils/itwClaimsUtils";
2829
import { ItwCredentialStatus } from "../utils/itwTypesUtils";
@@ -338,7 +339,8 @@ export const ItwCredentialClaim = ({
338339
const decoded = hidden ? HIDDEN_CLAIM_TEXT : _decoded;
339340
if (PlaceOfBirthClaim.is(decoded)) {
340341
return <PlaceOfBirthClaimItem label={claim.label} claim={decoded} />;
341-
} else if (SimpleDateClaim.is(decoded)) {
342+
}
343+
if (SimpleDateClaim.is(decoded)) {
342344
return (
343345
<DateClaimItem
344346
label={claim.label}
@@ -350,11 +352,14 @@ export const ItwCredentialClaim = ({
350352
}
351353
/>
352354
);
353-
} else if (ImageClaim.is(decoded)) {
355+
}
356+
if (ImageClaim.is(decoded)) {
354357
return <ImageClaimItem label={claim.label} claim={decoded} />;
355-
} else if (PdfClaim.is(decoded)) {
358+
}
359+
if (PdfClaim.is(decoded)) {
356360
return <AttachmentsClaimItem name={claim.label} />;
357-
} else if (DrivingPrivilegesClaim.is(decoded)) {
361+
}
362+
if (DrivingPrivilegesClaim.is(decoded)) {
358363
return decoded.map((elem, index) => (
359364
<Fragment key={`${index}_${claim.label}_${elem.driving_privilege}`}>
360365
{index !== 0 && <Divider />}
@@ -365,16 +370,27 @@ export const ItwCredentialClaim = ({
365370
/>
366371
</Fragment>
367372
));
368-
} else if (FiscalCodeClaim.is(decoded)) {
373+
}
374+
if (FiscalCodeClaim.is(decoded)) {
369375
const fiscalCode = pipe(
370376
decoded,
371377
extractFiscalCode,
372378
O.getOrElseW(() => decoded)
373379
);
374380
return <PlainTextClaimItem label={claim.label} claim={fiscalCode} />;
375-
} else if (BoolClaim.is(decoded)) {
376-
return <BoolClaimItem label={claim.label} claim={decoded} />; // m
377-
} else if (EmptyStringClaim.is(decoded)) {
381+
}
382+
if (BoolClaim.is(decoded)) {
383+
return <BoolClaimItem label={claim.label} claim={decoded} />;
384+
}
385+
if (SimpleListClaim.is(decoded)) {
386+
return (
387+
<PlainTextClaimItem
388+
label={claim.label}
389+
claim={decoded.join(", ")}
390+
/>
391+
);
392+
}
393+
if (EmptyStringClaim.is(decoded)) {
378394
return null; // We want to hide the claim if it's empty
379395
}
380396
if (StringClaim.is(decoded)) {
@@ -390,9 +406,9 @@ export const ItwCredentialClaim = ({
390406
credentialType={credentialType}
391407
/>
392408
); // must be the last one to be checked due to overlap with IPatternStringTag
393-
} else {
394-
return <UnknownClaimItem label={claim.label} _claim={decoded} />;
395409
}
410+
411+
return <UnknownClaimItem label={claim.label} _claim={decoded} />;
396412
}
397413
)
398414
);

ts/features/itwallet/common/utils/__tests__/itwClaimsUtils.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
getCredentialExpireDays,
88
getFiscalCodeFromCredential,
99
ImageClaim,
10-
SimpleDateClaim
10+
SimpleDateClaim,
11+
SimpleListClaim
1112
} from "../itwClaimsUtils";
1213
import { StoredCredential } from "../itwTypesUtils";
1314
import { ItwStoredCredentialsMocks } from "../itwMocksUtils";
@@ -237,3 +238,15 @@ describe("SimpleDateClaim", () => {
237238
}
238239
});
239240
});
241+
242+
describe("SimpleListClaim", () => {
243+
it.each([
244+
[["IT"], true],
245+
[["IT", "EN"], true],
246+
[[{ item: 1 }, { item: 2 }], false],
247+
["not_a_list", false],
248+
[123, false]
249+
])("should evaluate a claim of %p as %p", (data, expected) => {
250+
expect(SimpleListClaim.is(data)).toBe(expected);
251+
});
252+
});

ts/features/itwallet/common/utils/itwClaimsUtils.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ export const ImageClaim = PatternString(PICTURE_URL_REGEX);
358358

359359
export const PdfClaim = PatternString(PDF_DATA_REGEX);
360360

361+
/**
362+
* Decoder for a simple list of string claims (for instance, nationality codes)
363+
*/
364+
export const SimpleListClaim = t.array(t.string);
365+
361366
/**
362367
* Decoder type for the claim field of the credential.
363368
* It includes all the possible types of claims and fallbacks to string.
@@ -381,6 +386,8 @@ export const ClaimValue = t.union([
381386
BoolClaim,
382387
// Otherwise parse an url value
383388
UrlClaim,
389+
// Otherwise parse a list of strings
390+
SimpleListClaim,
384391
// Otherwise fallback to string
385392
StringClaim,
386393
// Otherwise fallback to empty string
@@ -539,23 +546,33 @@ export const getClaimDisplayValue = (
539546
decoded => {
540547
if (PlaceOfBirthClaim.is(decoded)) {
541548
return `${decoded.locality} (${decoded.country})`;
542-
} else if (SimpleDateClaim.is(decoded)) {
549+
}
550+
if (SimpleDateClaim.is(decoded)) {
543551
return decoded.toString();
544-
} else if (ImageClaim.is(decoded)) {
552+
}
553+
if (ImageClaim.is(decoded)) {
545554
return decoded;
546-
} else if (DrivingPrivilegesClaim.is(decoded)) {
555+
}
556+
if (DrivingPrivilegesClaim.is(decoded)) {
547557
return decoded.map(e => e.driving_privilege);
548-
} else if (FiscalCodeClaim.is(decoded)) {
558+
}
559+
if (FiscalCodeClaim.is(decoded)) {
549560
return pipe(
550561
decoded,
551562
extractFiscalCode,
552563
O.getOrElseW(() => decoded)
553564
);
554-
} else if (BoolClaim.is(decoded)) {
565+
}
566+
if (BoolClaim.is(decoded)) {
555567
return I18n.t(
556568
`features.itWallet.presentation.credentialDetails.boolClaim.${decoded}`
557569
);
558-
} else if (StringClaim.is(decoded) || EmptyStringClaim.is(decoded)) {
570+
}
571+
if (
572+
SimpleListClaim.is(decoded) ||
573+
StringClaim.is(decoded) ||
574+
EmptyStringClaim.is(decoded)
575+
) {
559576
return decoded; // must be the last one to be checked due to overlap with IPatternStringTag
560577
}
561578

0 commit comments

Comments
 (0)