Skip to content

Commit

Permalink
Merge pull request #377 from Concordium/restore-identity-special-display
Browse files Browse the repository at this point in the history
Restore identity special handlings
  • Loading branch information
orhoj authored Sep 4, 2023
2 parents 34df8b5 + 9fa7777 commit 059e632
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
useStatementHeader,
useStatementValue,
useStatementName,
isoToCountryName,
} from './utils';

export type StatementLine = {
Expand Down Expand Up @@ -188,7 +187,7 @@ export function DisplayRevealStatement({
className,
onInvalid,
}: DisplayRevealStatementProps) {
const { t, i18n } = useTranslation('idProofRequest', { keyPrefix: 'displayStatement' });
const { t } = useTranslation('idProofRequest', { keyPrefix: 'displayStatement' });
const getAttributeName = useGetAttributeName();
const displayAttribute = useDisplayAttributeValue();
const attributes =
Expand All @@ -197,11 +196,7 @@ export function DisplayRevealStatement({

const lines: StatementLine[] = statements.map((s) => {
const raw = attributes[s.attributeTag];
let value = displayAttribute(s.attributeTag, attributes[s.attributeTag] ?? '');

if (value && ['countryOfResidence', 'nationality', 'idDocIssuer'].includes(s.attributeTag)) {
value = isoToCountryName(i18n.resolvedLanguage)(value);
}
const value = displayAttribute(s.attributeTag, attributes[s.attributeTag] ?? '');

return {
attribute: getAttributeName(s.attributeTag),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import { useDisplayAttributeValue } from '@popup/shared/utils/identity-helpers';
import { ConfirmedIdentity, WalletCredential } from '@shared/storage/types';
import React, { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { SecretStatement, useStatementName, useStatementValue } from '../IdProofRequest/DisplayStatement/utils';
import CredentialSelector from './CredentialSelector';
import { DisplayRevealStatements } from './Display/DisplayRevealStatements';
import { DisplaySecretStatements } from './Display/DisplaySecretStatements';
import { OverwriteSecretLine } from './Display/utils';
import { DisplayCredentialStatementProps, SecretStatementV2 } from './utils';

export function DisplayAccount({ option }: { option: WalletCredential }) {
Expand Down Expand Up @@ -66,6 +68,15 @@ export default function AccountStatement({
}
}, []);

const accountCreateSecretLine: OverwriteSecretLine = (statement: SecretStatementV2) => {
const value = useStatementValue(statement as SecretStatement);
const attribute = useStatementName(statement as SecretStatement);
return {
attribute,
value,
};
};

if (!identity) {
return null;
}
Expand Down Expand Up @@ -98,6 +109,7 @@ export default function AccountStatement({
statements={secrets}
formatAttribute={displayAttribute}
schema={IDENTITY_SUBJECT_SCHEMA as CredentialSchemaSubject}
overwriteSecretLine={accountCreateSecretLine}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,23 @@ export function DisplaySecretStatements<Attribute extends AttributeType>({
statements,
attributes,
className,
overwriteSecretLine = () => ({}),
formatAttribute = defaultFormatAttribute,
}: DisplayProps<SecretStatementV2, Attribute>) {
const { t } = useTranslation('web3IdProofRequest', { keyPrefix: 'displayStatement' });
const header = t('headers.secret');

const lines = statements.map((s) => {
const value = getStatementValue(s, schema, t, formatAttribute);
const title = getPropertyTitle(s.attributeTag, schema);
const attribute = getPropertyTitle(s.attributeTag, schema);
const description = getStatementDescription(s, schema, t, formatAttribute);

return {
attribute: title,
value,
isRequirementMet: canProveAtomicStatement(s, attributes),
attribute,
description,
...overwriteSecretLine(s),
isRequirementMet: canProveAtomicStatement(s, attributes),
};
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import { AttributeType, CredentialSchemaSubject } from '@concordium/web-sdk';
import { withDateAndTime } from '@shared/utils/time-helpers';
import { ClassName } from 'wallet-common-helpers';
import { SecretStatementV2 } from '../utils';

export function getPropertyTitle(attributeTag: string, schemaSubject: CredentialSchemaSubject) {
// TODO use localization here
const property = schemaSubject.properties.attributes.properties[attributeTag];
return property ? property.title : attributeTag;
}

export type OverwriteSecretLine = (statement: SecretStatementV2) => {
attribute?: string;
value?: string;
description?: string;
};

export type DisplayProps<StatementType, Attribute> = ClassName & {
statements: StatementType[];
attributes: Record<string, Attribute>;
schema: CredentialSchemaSubject;
className: string;
formatAttribute?: (key: string, value: Attribute) => string;
overwriteSecretLine?: OverwriteSecretLine;
};

export function defaultFormatAttribute<Attribute extends AttributeType>(_: string, value: Attribute) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ConfirmedIdentity, CreationStatus, Identity } from '@shared/storage/typ
import { useAtomValue } from 'jotai';
import { TFunction, useTranslation } from 'react-i18next';
import { formatDate } from 'wallet-common-helpers';
import { isoToCountryName } from '@popup/pages/IdProofRequest/DisplayStatement/utils';
import sharedTranslations from '../i18n/en';

export function useGetAttributeName() {
Expand Down Expand Up @@ -76,6 +77,10 @@ export function useDisplayAttributeValue() {
return formatGender(parseInt(value, 10), t);
case 'idDocType':
return formatDocumentType(value, t);
case 'countryOfResidence':
case 'nationality':
case 'idDocIssuer':
return isoToCountryName(i18n.resolvedLanguage)(value);
default:
return value;
}
Expand Down

0 comments on commit 059e632

Please sign in to comment.