Skip to content

Commit

Permalink
Merge pull request #33 from MonobikashDas/develop
Browse files Browse the repository at this point in the history
Fixed app crashing and language issue
  • Loading branch information
MonobikashDas authored Jun 8, 2022
2 parents 8fbd3d2 + 046f2d2 commit 888abbc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
24 changes: 17 additions & 7 deletions components/VcDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ export const VcDetails: React.FC<VcDetailsProps> = (props) => {
<TextItem
divider
label={t('fullName')}
text={props.vc?.verifiableCredential.credentialSubject.fullName}
text={getLocalizedField(
props.vc?.verifiableCredential.credentialSubject.fullName
)}
/>

<TextItem
Expand All @@ -96,19 +98,25 @@ export const VcDetails: React.FC<VcDetailsProps> = (props) => {
<TextItem
divider
label={t('dateOfBirth')}
text={props.vc?.verifiableCredential.credentialSubject.dateOfBirth}
text={getLocalizedField(
props.vc?.verifiableCredential.credentialSubject.dateOfBirth
)}
/>

<TextItem
divider
label={t('phoneNumber')}
text={props.vc?.verifiableCredential.credentialSubject.phone}
text={getLocalizedField(
props.vc?.verifiableCredential.credentialSubject.phone
)}
/>

<TextItem
divider
label={t('email')}
text={props.vc?.verifiableCredential.credentialSubject.email}
text={getLocalizedField(
props.vc?.verifiableCredential.credentialSubject.email
)}
/>

<TextItem
Expand Down Expand Up @@ -168,10 +176,12 @@ function getFullAddress(credential: CredentialSubject) {
}

function getLocalizedField(rawField: string | LocalizedField) {
if (typeof rawField === 'string') {
return rawField;
}
try {
const locales: LocalizedField[] =
typeof rawField === 'string' ? JSON.parse(rawField) : rawField;
return locales.find((locale) => locale.language === 'eng').value.trim();
const locales: LocalizedField[] = JSON.parse(JSON.stringify(rawField));
return locales[0].value;
} catch (e) {
return '';
}
Expand Down
16 changes: 15 additions & 1 deletion components/VcItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ export const VcItem: React.FC<VcItemProps> = (props) => {
}>
{!verifiableCredential
? ''
: verifiableCredential.credentialSubject.fullName +
: getLocalizedField(
verifiableCredential.credentialSubject.fullName
) +
' · ' +
generatedOn}
</Text>
Expand All @@ -117,3 +119,15 @@ interface VcItemProps {
selected?: boolean;
onPress?: (vcRef?: ActorRefFrom<typeof vcItemMachine>) => void;
}

function getLocalizedField(rawField: string | LocalizedField) {
if (typeof rawField === 'string') {
return rawField;
}
try {
const locales: LocalizedField[] = JSON.parse(JSON.stringify(rawField));
return locales[0].value;
} catch (e) {
return '';
}
}

0 comments on commit 888abbc

Please sign in to comment.