mirror of
https://github.com/mosip/inji-wallet.git
synced 2026-01-09 13:38:01 -05:00
* [INJIMOB-2381] update package.json and resolve dependencies for react 0.73.0 Signed-off-by: Abhishek Paul <paul.apaul.abhishek.ap@gmail.com> * [INJIMOB-2381] setup for 0.73.6 Signed-off-by: Abhishek Paul <paul.apaul.abhishek.ap@gmail.com> * [INJIMOB-2381] fix font & image not loading issue changes include - move common image assets to android & iOS folders - update gradle version to 8.2 - add expo-font asset for Inter regular - replace useFont with expo-font - remove flipper (reason: 0.74 react native decoupled flipper) - npm package updates - close icon changed to close text in QRScanner.tsx Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> Signed-off-by: Abhishek Paul <paul.apaul.abhishek.ap@gmail.com> * [INJIMOB-2381] update android:mosip script as per updated react native version Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] fix android build failure issue Changes include: - rename android assets folder as per convention - remove unused biometrics dependency - use env from react-native-dotenv as per module registered in babel config - revert conversion of close icon to image in QRScanner component Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] fix iOS build issue Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] rm unused local images linking in adnroid Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] fix splash screen not rendering issue in android Issue: Local assets were not loaded via React Native Image component in android, to fix this @react-native/assets-registry has been added Reference: https://github.com/expo/expo/issues/31240#issuecomment-2459049911 Other changes: - remove usage of expo-image as we dont have any explicit usecase for expo-image and its unused Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] rm unused intro slider image assets Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] revert back using local font assets in android Reason: Previously expo-font was used for fonts, to bring back the same compatiblity it is bought back Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] use GestureHandlerRootView in root level to handle gestures ref - https://docs.swmansion.com/react-native-gesture-handler/docs/1.x/#js Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] remove custom assets and linking for images in iOS Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] use default parameters instead of defaultProps Reason: React 18 has marked defaultProps as deprecated and it is removed in React 19 version. To avoid the issue of deprated usage, its modified. Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] remove unused terminal option in android build script Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] remove font assets in android Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] optimize import Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] fix failing test Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] set package.resolved version to 2 Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] fix setting of camera view in face scanner Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] fix setting of camera view in face compare Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] remove flipper config file Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] remove unused debug logs Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] refactor use component instead of type Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] refactor use GestureHandlerRootView only on root level Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] refactor remove unused config linking of font assets Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] refactor remove unused image assets Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] fix camera persmission issue in QRScanner use expo-camera to request and getstatus of camera permission instead of expo-barcode-scanner to avoid multiple re-renders of scan screen in flow of camera permission denial Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] remove package expo-barcode-scanner expo-barcode-scanner is deprecated and its suggested to use expo-camera to handle the scanning flows. The existing bar-code-scanner implementations have been replaced with expo-camera. Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] use extracted enums instead of legacy expo-camera Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] remove patch for react-native-0.71.8 Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] revert date-fs version to 2.28.0 date-fns is not supporting filipino langauge, so we are maintaining patch for that. The patch created is for version 2.28.0 and updating the version of date-fns is causing conflicts in patch application if updated as well. To avoid this issue, version is kept as 2.28.0 Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] update readme Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] remove usage of legacy expo-camera in getting image type Other changes - remove resolutions block from package.json - sync pbxproj Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> * [INJIMOB-2381] add active prop to expo-camera as per suggestions expo-camera suggests "Only one Camera preview can be active at any given time. If you have multiple screens in your app, you should unmount Camera components whenever a screen is unfocused.". To handle this active prop is used which is set to false on unMount of the component whenever rendering Camera from expo-camera Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> --------- Signed-off-by: Abhishek Paul <paul.apaul.abhishek.ap@gmail.com> Signed-off-by: KiruthikaJeyashankar <kiruthikavjshankar@gmail.com> Signed-off-by: adityankannan-tw <109274996+adityankannan-tw@users.noreply.github.com> Co-authored-by: Abhishek Paul <paul.apaul.abhishek.ap@gmail.com> Co-authored-by: adityankannan-tw <109274996+adityankannan-tw@users.noreply.github.com>
339 lines
9.1 KiB
TypeScript
339 lines
9.1 KiB
TypeScript
import {
|
|
Credential,
|
|
CredentialSubject,
|
|
CredentialTypes,
|
|
IssuerWellknownResponse,
|
|
VerifiableCredential,
|
|
} from '../../../machines/VerifiableCredential/VCMetaMachine/vc';
|
|
import i18n, {getLocalizedField} from '../../../i18n';
|
|
import {Row} from '../../ui';
|
|
import {VCItemField} from './VCItemField';
|
|
import React from 'react';
|
|
import {Theme} from '../../ui/styleUtils';
|
|
import {CREDENTIAL_REGISTRY_EDIT} from 'react-native-dotenv';
|
|
import {VCVerification} from '../../VCVerification';
|
|
import {MIMOTO_BASE_URL} from '../../../shared/constants';
|
|
import {VCItemDetailsProps} from '../Views/VCDetailView';
|
|
import {
|
|
getDisplayObjectForCurrentLanguage,
|
|
getMatchingCredentialIssuerMetadata,
|
|
} from '../../../shared/openId4VCI/Utils';
|
|
import {VCFormat} from '../../../shared/VCFormat';
|
|
import {displayType} from '../../../machines/Issuers/IssuersMachine';
|
|
|
|
export const CARD_VIEW_DEFAULT_FIELDS = ['fullName'];
|
|
export const DETAIL_VIEW_DEFAULT_FIELDS = [
|
|
'fullName',
|
|
'gender',
|
|
'phone',
|
|
'dateOfBirth',
|
|
'email',
|
|
'address',
|
|
];
|
|
|
|
//todo UIN & VID to be removed once we get the fields in the wellknown endpoint
|
|
export const CARD_VIEW_ADD_ON_FIELDS = ['UIN', 'VID'];
|
|
export const DETAIL_VIEW_ADD_ON_FIELDS = [
|
|
'status',
|
|
'credentialRegistry',
|
|
'idType',
|
|
];
|
|
|
|
export const DETAIL_VIEW_BOTTOM_SECTION_FIELDS = [
|
|
'email',
|
|
'address',
|
|
'credentialRegistry',
|
|
];
|
|
|
|
export const KEY_TYPE_FIELD = 'keytype';
|
|
export const BOTTOM_SECTION_FIELDS_WITH_DETAILED_ADDRESS_FIELDS = [
|
|
...getAddressFields(),
|
|
'email',
|
|
'credentialRegistry',
|
|
];
|
|
|
|
function iterateMsoMdocFor(
|
|
credential,
|
|
namespace: string,
|
|
element: 'elementIdentifier' | 'elementValue',
|
|
fieldName: string,
|
|
) {
|
|
const foundItem = credential['issuerSigned']['nameSpaces'][namespace].find(
|
|
element => {
|
|
return element.elementIdentifier === fieldName;
|
|
},
|
|
);
|
|
return foundItem[element];
|
|
}
|
|
|
|
export const getFieldValue = (
|
|
verifiableCredential: Credential,
|
|
field: string,
|
|
wellknown: any,
|
|
props: any,
|
|
display: Display,
|
|
format: string,
|
|
) => {
|
|
switch (field) {
|
|
case 'status':
|
|
return (
|
|
<VCVerification
|
|
display={display}
|
|
vcMetadata={props.verifiableCredentialData.vcMetadata}
|
|
/>
|
|
);
|
|
case 'idType':
|
|
return getCredentialType(wellknown);
|
|
case 'credentialRegistry':
|
|
return props?.vc?.credentialRegistry;
|
|
case 'address':
|
|
return getLocalizedField(
|
|
getFullAddress(verifiableCredential?.credentialSubject),
|
|
);
|
|
default: {
|
|
if (format === VCFormat.ldp_vc) {
|
|
const fieldValue = verifiableCredential?.credentialSubject[field];
|
|
if (Array.isArray(fieldValue) && typeof fieldValue[0] !== 'object') {
|
|
return fieldValue.join(', ');
|
|
}
|
|
return getLocalizedField(fieldValue);
|
|
} else if (format === VCFormat.mso_mdoc) {
|
|
const splitField = field.split('~');
|
|
if (splitField.length > 1) {
|
|
const [namespace, fieldName] = splitField;
|
|
return iterateMsoMdocFor(
|
|
verifiableCredential,
|
|
namespace,
|
|
'elementValue',
|
|
fieldName,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
export const getFieldName = (
|
|
field: string,
|
|
wellknown: any,
|
|
format: string,
|
|
): string => {
|
|
if (wellknown) {
|
|
if (format === VCFormat.ldp_vc) {
|
|
const credentialDefinition = wellknown.credential_definition;
|
|
if (!credentialDefinition) {
|
|
console.error(
|
|
'Credential definition is not available for the selected credential type',
|
|
);
|
|
}
|
|
let fieldObj = credentialDefinition?.credentialSubject?.[field];
|
|
if (fieldObj) {
|
|
if (fieldObj.display && fieldObj.display.length > 0) {
|
|
const newFieldObj = fieldObj.display.map(obj => ({
|
|
language: obj.locale,
|
|
value: obj.name,
|
|
}));
|
|
return getLocalizedField(newFieldObj);
|
|
}
|
|
return field;
|
|
}
|
|
} else if (format === VCFormat.mso_mdoc) {
|
|
const splitField = field.split('~');
|
|
if (splitField.length > 1) {
|
|
const [namespace, fieldName] = splitField;
|
|
const fieldObj = wellknown.claims?.[namespace]?.[fieldName];
|
|
if (fieldObj) {
|
|
if (fieldObj.display && fieldObj.display.length > 0) {
|
|
const newFieldObj = fieldObj.display.map(obj => ({
|
|
language: obj.locale,
|
|
value: obj.name,
|
|
}));
|
|
return getLocalizedField(newFieldObj);
|
|
}
|
|
return fieldName;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return i18n.t(`VcDetails:${field}`);
|
|
};
|
|
|
|
export function getAddressFields() {
|
|
return [
|
|
'addressLine1',
|
|
'addressLine2',
|
|
'addressLine3',
|
|
'city',
|
|
'province',
|
|
'region',
|
|
'postalCode',
|
|
];
|
|
}
|
|
|
|
function getFullAddress(credential: CredentialSubject) {
|
|
if (!credential) {
|
|
return '';
|
|
}
|
|
|
|
const fields = getAddressFields();
|
|
|
|
return fields
|
|
.map(field => getLocalizedField(credential[field]))
|
|
.filter(Boolean)
|
|
.join(', ');
|
|
}
|
|
|
|
export const fieldItemIterator = (
|
|
fields: any[],
|
|
verifiableCredential: VerifiableCredential | Credential,
|
|
wellknown: any,
|
|
display: Display,
|
|
props: VCItemDetailsProps,
|
|
) => {
|
|
const fieldNameColor = display.getTextColor(Theme.Colors.DetailsLabel);
|
|
const fieldValueColor = display.getTextColor(Theme.Colors.Details);
|
|
return fields.map(field => {
|
|
const fieldName = getFieldName(
|
|
field,
|
|
wellknown,
|
|
props.verifiableCredentialData.vcMetadata.format,
|
|
);
|
|
const fieldValue = getFieldValue(
|
|
verifiableCredential,
|
|
field,
|
|
wellknown,
|
|
props,
|
|
display,
|
|
props.verifiableCredentialData.vcMetadata.format,
|
|
);
|
|
if (
|
|
(field === 'credentialRegistry' &&
|
|
CREDENTIAL_REGISTRY_EDIT === 'false') ||
|
|
!fieldValue
|
|
)
|
|
return;
|
|
return (
|
|
<Row
|
|
key={field}
|
|
style={{flexDirection: 'row', flex: 1}}
|
|
align="space-between"
|
|
margin="0 8 15 0">
|
|
<VCItemField
|
|
key={field}
|
|
fieldName={fieldName}
|
|
fieldValue={fieldValue}
|
|
fieldNameColor={fieldNameColor}
|
|
fieldValueColor={fieldValueColor}
|
|
testID={field}
|
|
/>
|
|
</Row>
|
|
);
|
|
});
|
|
};
|
|
|
|
export const isVCLoaded = (
|
|
verifiableCredential: Credential | null,
|
|
fields: string[],
|
|
) => {
|
|
return verifiableCredential != null && fields.length > 0;
|
|
};
|
|
|
|
export const getMosipLogo = () => {
|
|
return {
|
|
url: `${MIMOTO_BASE_URL}/inji/mosip-logo.png`,
|
|
alt_text: 'a square logo of mosip',
|
|
};
|
|
};
|
|
|
|
/**
|
|
*
|
|
* @param wellknown (either supportedCredential's wellknown or whole well known response of issuer)
|
|
* @param credentialConfigurationId
|
|
* @returns credential type translations (Eg - National ID)
|
|
*
|
|
*/
|
|
export const getCredentialType = (
|
|
supportedCredentialsWellknown: CredentialTypes,
|
|
): string => {
|
|
if (!!!supportedCredentialsWellknown) {
|
|
return i18n.t('VcDetails:identityCard');
|
|
}
|
|
if (supportedCredentialsWellknown['display']) {
|
|
const wellknownDisplayProperty = getDisplayObjectForCurrentLanguage(
|
|
supportedCredentialsWellknown.display,
|
|
);
|
|
return wellknownDisplayProperty.name;
|
|
}
|
|
if (supportedCredentialsWellknown.format === VCFormat.ldp_vc) {
|
|
const types = supportedCredentialsWellknown.credential_definition
|
|
.type as string[];
|
|
return types[types.length - 1];
|
|
} else {
|
|
return i18n.t('VcDetails:identityCard');
|
|
}
|
|
};
|
|
|
|
export const getCredentialTypeFromWellKnown = (
|
|
wellknown: IssuerWellknownResponse,
|
|
credentialConfigurationId: string | undefined = undefined,
|
|
): string => {
|
|
try {
|
|
if (credentialConfigurationId !== undefined) {
|
|
const supportedCredentialsWellknown = getMatchingCredentialIssuerMetadata(
|
|
wellknown,
|
|
credentialConfigurationId,
|
|
);
|
|
return getCredentialType(supportedCredentialsWellknown);
|
|
}
|
|
console.error(
|
|
'credentialConfigurationId not available for fetching the Credential type',
|
|
);
|
|
throw new Error(
|
|
`Invalid credentialConfigurationId - ${credentialConfigurationId} passed`,
|
|
);
|
|
} catch (error) {
|
|
return i18n.t('VcDetails:identityCard');
|
|
}
|
|
};
|
|
|
|
export class Display {
|
|
private readonly textColor: string | undefined = undefined;
|
|
private readonly backgroundColor: {backgroundColor: string};
|
|
private readonly backgroundImage: { uri: string } | undefined = undefined;
|
|
|
|
private defaultBackgroundColor = Theme.Colors.whiteBackgroundColor;
|
|
|
|
constructor(wellknown: any) {
|
|
const wellknownDisplayProperty = wellknown?.display
|
|
? getDisplayObjectForCurrentLanguage(wellknown.display)
|
|
: {};
|
|
|
|
if (!!!Object.keys(wellknownDisplayProperty).length) {
|
|
this.backgroundColor = {
|
|
backgroundColor: this.defaultBackgroundColor,
|
|
};
|
|
return;
|
|
}
|
|
|
|
const display = wellknownDisplayProperty as displayType;
|
|
|
|
this.backgroundColor = {
|
|
backgroundColor: display.background_color ?? this.defaultBackgroundColor,
|
|
};
|
|
this.backgroundImage = display.background_image;
|
|
this.textColor = display.text_color;
|
|
}
|
|
|
|
getTextColor(defaultColor: string): string {
|
|
return this.textColor ?? defaultColor;
|
|
}
|
|
|
|
getBackgroundColor(): {backgroundColor: string} {
|
|
return this.backgroundColor;
|
|
}
|
|
|
|
getBackgroundImage(defaultBackgroundImage: string) {
|
|
return this.backgroundImage ?? defaultBackgroundImage;
|
|
}
|
|
}
|