Skip to content

Commit

Permalink
Merge pull request #713 from tw-mosip/internal-release-19-04-23
Browse files Browse the repository at this point in the history
Release 24-03-2023 changes
  • Loading branch information
ravikp authored Apr 20, 2023
2 parents 4e4cc17 + 9b386c7 commit 7e091d8
Show file tree
Hide file tree
Showing 16 changed files with 618 additions and 148 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/android-custom-build.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: ID PASS - MOSIP Resident Application Custom build

env:
backendServiceDefaultUrl: https://api.qa-121.mosip.net/residentmobileapp
backendServiceDefaultUrl: https://api.qa-121.mosip.net

on:
workflow_dispatch:
inputs:
backendServiceUrl:
description: 'Backend service URL'
required: true
default: 'https://api.qa-121.mosip.net/residentmobileapp'
default: 'https://api.qa-121.mosip.net'
type: string
theme:
description: 'Application Theme'
Expand Down
4 changes: 2 additions & 2 deletions components/LanguageSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { SUPPORTED_LANGUAGES } from '../i18n';
import { I18nManager, View } from 'react-native';
import { Picker } from './ui/Picker';
import AsyncStorage from '@react-native-async-storage/async-storage';
import Storage from '../shared/storage';
import { useTranslation } from 'react-i18next';
import i18next from 'i18next';
import RNRestart from 'react-native-restart';
Expand All @@ -16,7 +16,7 @@ export const LanguageSelector: React.FC<LanguageSelectorProps> = (props) => {
const changeLanguage = async (language: string) => {
if (language !== i18n.language) {
await i18n.changeLanguage(language).then(async () => {
await AsyncStorage.setItem('language', i18n.language);
await Storage.setItem('language', i18n.language);
const isRTL = i18next.dir(language) === 'rtl' ? true : false;
if (isRTL !== I18nManager.isRTL) {
try {
Expand Down
15 changes: 2 additions & 13 deletions components/VcDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import * as DateFnsLocale from '../lib/date-fns/locale';
import { useTranslation } from 'react-i18next';
import { Image, ImageBackground, View } from 'react-native';
import { Icon } from 'react-native-elements';
import { VC, CredentialSubject, LocalizedField } from '../types/vc';
import { VC, CredentialSubject } from '../types/vc';
import { Button, Column, Row, Text } from './ui';
import { Theme } from './ui/styleUtils';
import { TextItem } from './ui/TextItem';
import { VcItemTags } from './VcItemTags';
import VerifiedIcon from './VerifiedIcon';
import { getLocalizedField } from '../i18n';

export const VcDetails: React.FC<VcDetailsProps> = (props) => {
const { t, i18n } = useTranslation('VcDetails');
Expand Down Expand Up @@ -345,15 +346,3 @@ function getFullAddress(credential: CredentialSubject) {
.filter(Boolean)
.join(', ');
}

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 '';
}
}
14 changes: 1 addition & 13 deletions components/VcItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import { Theme } from './ui/styleUtils';
import { RotatingIcon } from './RotatingIcon';
import { GlobalContext } from '../shared/GlobalContext';
import { useTranslation } from 'react-i18next';
import { LocalizedField } from '../types/vc';
import { VcItemTags } from './VcItemTags';
import VerifiedIcon from './VerifiedIcon';
import { getLocalizedField } from '../i18n';

const getDetails = (arg1, arg2, verifiableCredential) => {
if (arg1 === 'Status') {
Expand Down Expand Up @@ -304,15 +304,3 @@ interface VcItemProps {
onShow?: (vcRef?: ActorRefFrom<typeof vcItemMachine>) => void;
activeTab?: string;
}

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 '';
}
}
14 changes: 1 addition & 13 deletions components/VidItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Column, Row, Text } from './ui';
import { Theme } from './ui/styleUtils';
import { RotatingIcon } from './RotatingIcon';
import { GlobalContext } from '../shared/GlobalContext';
import { LocalizedField } from '../types/vc';
import { getLocalizedField } from '../i18n';

export const VidItem: React.FC<VcItemProps> = (props) => {
const { appService } = useContext(GlobalContext);
Expand Down Expand Up @@ -105,15 +105,3 @@ 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 '';
}
}
56 changes: 54 additions & 2 deletions i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import ar from './locales/ara.json';
import hi from './locales/hin.json';
import kn from './locales/kan.json';
import ta from './locales/tam.json';
import AsyncStorage from '@react-native-async-storage/async-storage';
import Storage from './shared/storage';

const resources = { en, fil, ar, hi, kn, ta };
import { iso6393To1 } from 'iso-639-3';
import { LocalizedField } from './types/vc';

const languageCodeMap = {};

export const SUPPORTED_LANGUAGES = {
en: 'English',
Expand All @@ -31,9 +35,10 @@ i18next
supportedLngs: Object.keys(SUPPORTED_LANGUAGES),
})
.then(async () => {
const language = await AsyncStorage.getItem('language');
const language = await Storage.getItem('language');
if (language !== i18next.language) {
i18next.changeLanguage(language);
populateLanguageCodeMap();
}
});

Expand All @@ -43,3 +48,50 @@ function getLanguageCode(code: string) {
const [language] = code.split('-');
return language;
}

export function getVCDetailsForCurrentLanguage(locales) {
const currentLanguage = i18next.language;
const vcDetailsForCurrentLanguage = locales.filter(
(obj) => obj.language === languageCodeMap[currentLanguage]
);
return vcDetailsForCurrentLanguage[0]?.value
? vcDetailsForCurrentLanguage[0].value
: locales[0]?.value;
}

// This method gets the value from iso-639-3 package, which contains key value pairs of three letter language codes[key] and two letter langugae code[value]. These values are according to iso standards.
// The response received from the server is three letter language code and the value in the inji code base is two letter language code. Hence the conversion is done.
function getThreeLetterLanguageCode(twoLetterLanguageCode) {
return Object.keys(iso6393To1).find(
(key) => iso6393To1[key] === twoLetterLanguageCode
);
}

function populateLanguageCodeMap() {
const supportedLanguages = Object.keys(SUPPORTED_LANGUAGES);
supportedLanguages.forEach((languageCode) => {
let threeLetterLanguageCode = languageCode;

if (isTwoLetterLanguageCode(languageCode)) {
threeLetterLanguageCode = getThreeLetterLanguageCode(languageCode);
}
languageCodeMap[languageCode] = threeLetterLanguageCode;
});
}

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

function isTwoLetterLanguageCode(languageCode) {
return languageCode.length == 2;
}
28 changes: 18 additions & 10 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ PODS:
- GoogleUtilitiesLegacy (1.3.2):
- GoogleSymbolUtilities (~> 1.1)
- GzipSwift (5.1.1)
- mosip-inji-face-sdk (0.1.7):
- MMKV (1.2.13):
- MMKVCore (~> 1.2.13)
- MMKVCore (1.2.15)
- mosip-inji-face-sdk (0.1.12):
- React-Core
- NearbyMessages (1.1.1):
- GoogleInterchangeUtilities (~> 1.2)
Expand Down Expand Up @@ -272,9 +275,12 @@ PODS:
- React-jsi (= 0.64.4)
- React-perflogger (= 0.64.4)
- React-jsinspector (0.64.4)
- react-native-mmkv-storage (0.8.0):
- MMKV (= 1.2.13)
- React-Core
- react-native-netinfo (7.1.3):
- React-Core
- react-native-openid4vp-ble (0.3.9):
- react-native-openid4vp-ble (0.3.11):
- CrcSwift (~> 0.0.3)
- GzipSwift
- React-Core
Expand Down Expand Up @@ -352,8 +358,6 @@ PODS:
- React-perflogger (= 0.64.4)
- RNBluetoothStateManager (1.3.4):
- React-Core
- RNCAsyncStorage (1.15.17):
- React-Core
- RNCPicker (2.2.1):
- React-Core
- RNDeviceInfo (8.7.1):
Expand Down Expand Up @@ -427,6 +431,7 @@ DEPENDENCIES:
- React-jsi (from `../node_modules/react-native/ReactCommon/jsi`)
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
- react-native-mmkv-storage (from `../node_modules/react-native-mmkv-storage`)
- "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)"
- react-native-openid4vp-ble (from `../node_modules/react-native-openid4vp-ble`)
- react-native-restart (from `../node_modules/react-native-restart`)
Expand All @@ -446,7 +451,6 @@ DEPENDENCIES:
- React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- RNBluetoothStateManager (from `../node_modules/react-native-bluetooth-state-manager`)
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
- "RNCPicker (from `../node_modules/@react-native-picker/picker`)"
- RNDeviceInfo (from `../node_modules/react-native-device-info`)
- RNFS (from `../node_modules/react-native-fs`)
Expand All @@ -469,6 +473,8 @@ SPEC REPOS:
- GoogleSymbolUtilities
- GoogleUtilitiesLegacy
- GzipSwift
- MMKV
- MMKVCore
- NearbyMessages
- ZXingObjC

Expand Down Expand Up @@ -551,6 +557,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/jsiexecutor"
React-jsinspector:
:path: "../node_modules/react-native/ReactCommon/jsinspector"
react-native-mmkv-storage:
:path: "../node_modules/react-native-mmkv-storage"
react-native-netinfo:
:path: "../node_modules/@react-native-community/netinfo"
react-native-openid4vp-ble:
Expand Down Expand Up @@ -589,8 +597,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon"
RNBluetoothStateManager:
:path: "../node_modules/react-native-bluetooth-state-manager"
RNCAsyncStorage:
:path: "../node_modules/@react-native-async-storage/async-storage"
RNCPicker:
:path: "../node_modules/@react-native-picker/picker"
RNDeviceInfo:
Expand Down Expand Up @@ -647,7 +653,9 @@ SPEC CHECKSUMS:
GoogleSymbolUtilities: 631ee17048aa5e9ab133470d768ea997a5ef9b96
GoogleUtilitiesLegacy: 5501bedec1646bd284286eb5fc9453f7e23a12f4
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
mosip-inji-face-sdk: a1355473a393f2cdd6d927c51af4363be6d97d9f
MMKV: aac95d817a100479445633f2b3ed8961b4ac5043
MMKVCore: ddf41b9d9262f058419f9ba7598719af56c02cd3
mosip-inji-face-sdk: d5bc0fb66721c25450f92d3297efcb2cf0117271
NearbyMessages: bd9e88f2df7fbab78be58fed58580d5d5bd62cbf
Permission-BluetoothPeripheral: 67708853584bb9208c76d36d0e0ea4eafb97ea5b
Permission-Camera: bf6791b17c7f614b6826019fcfdcc286d3a107f6
Expand All @@ -664,8 +672,9 @@ SPEC CHECKSUMS:
React-jsi: 64f80675a66899bf0f4a58b8e3908966fa516234
React-jsiexecutor: 8c077bef1c64430b6034f27df1000d194551e2eb
React-jsinspector: d4f6973dd474357dbaaf6f52f31ffc713bf3e766
react-native-mmkv-storage: 8ba3c0216a6df283ece11205b442a3e435aec4e5
react-native-netinfo: 42c0965fca99069b92e3f7360ab2d425985e5104
react-native-openid4vp-ble: ca0d953933922f55ba18027e2dec7d64d36e1dc3
react-native-openid4vp-ble: 98e3371b181b695a44f446f55d7c25c63fe0aa5f
react-native-restart: 45c8dca02491980f2958595333cbccd6877cb57e
react-native-rsa-native: 12132eb627797529fdb1f0d22fd0f8f9678df64a
react-native-safe-area-context: 584dc04881deb49474363f3be89e4ca0e854c057
Expand All @@ -683,7 +692,6 @@ SPEC CHECKSUMS:
React-runtimeexecutor: 5b441857030bb6c3abaa7517f333cb01875ae499
ReactCommon: b4a65d2d6e9eeffd4b32dde1245962b3f43907d0
RNBluetoothStateManager: ae6a26260cbdf1827b58bd3bcc563527d61e6488
RNCAsyncStorage: 6bd5a7ba3dde1c3facba418aa273f449bdc5437a
RNCPicker: cb57c823d5ce8d2d0b5dfb45ad97b737260dc59e
RNDeviceInfo: aad3c663b25752a52bf8fce93f2354001dd185aa
RNFS: 4ac0f0ea233904cb798630b3c077808c06931688
Expand Down
34 changes: 17 additions & 17 deletions machines/store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Keychain from 'react-native-keychain';
import CryptoJS from 'crypto-js';
import AsyncStorage from '@react-native-async-storage/async-storage';
import Storage from '../shared/storage';
import binaryToBase64 from 'react-native/Libraries/Utilities/binaryToBase64';
import { EventFrom, Receiver, sendParent, send, sendUpdate } from 'xstate';
import { createModel } from 'xstate/lib/model';
Expand Down Expand Up @@ -283,8 +283,8 @@ export async function setItem(
) {
try {
const data = JSON.stringify(value);
const encrypted = encryptJson(encryptionKey, data);
await AsyncStorage.setItem(key, encrypted);
const encryptedData = encryptJson(encryptionKey, data);
await Storage.setItem(key, encryptedData);
} catch (e) {
console.error('error setItem:', e);
throw e;
Expand All @@ -297,11 +297,10 @@ export async function getItem(
encryptionKey: string
) {
try {
const data = await AsyncStorage.getItem(key);
const data = await Storage.getItem(key);
if (data != null) {
const decrypted = decryptJson(encryptionKey, data);

return JSON.parse(decrypted);
const decryptedData = decryptJson(encryptionKey, data);
return JSON.parse(decryptedData);
} else {
return defaultValue;
}
Expand Down Expand Up @@ -348,9 +347,9 @@ export async function removeItem(
encryptionKey: string
) {
try {
const data = await AsyncStorage.getItem(key);
const decrypted = decryptJson(encryptionKey, data);
const list = JSON.parse(decrypted);
const data = await Storage.getItem(key);
const decryptedData = decryptJson(encryptionKey, data);
const list = JSON.parse(decryptedData);
const vcKeyArray = value.split(':');
const finalVcKeyArray = vcKeyArray.pop();
const finalVcKey = vcKeyArray.join(':');
Expand All @@ -372,9 +371,9 @@ export async function removeItems(
encryptionKey: string
) {
try {
const data = await AsyncStorage.getItem(key);
const decrypted = decryptJson(encryptionKey, data);
const list = JSON.parse(decrypted);
const data = await Storage.getItem(key);
const decryptedData = decryptJson(encryptionKey, data);
const list = JSON.parse(decryptedData);
const newList = list.filter(function (vc: string) {
return !values.find(function (vcKey: string) {
const vcKeyArray = vcKey.split(':');
Expand All @@ -394,20 +393,21 @@ export async function removeItems(

export async function clear() {
try {
await AsyncStorage.clear();
console.log('entire storage gets cleared.');
await Storage.clear();
} catch (e) {
console.error('error clear:', e);
throw e;
}
}

export function encryptJson(encryptionKey: string, data: string): string {
function encryptJson(encryptionKey: string, data: string): string {
return CryptoJS.AES.encrypt(data, encryptionKey).toString();
}

export function decryptJson(encryptionKey: string, encrypted: string): string {
function decryptJson(encryptionKey: string, encryptedData: string): string {
try {
return CryptoJS.AES.decrypt(encrypted, encryptionKey).toString(
return CryptoJS.AES.decrypt(encryptedData, encryptionKey).toString(
CryptoJS.enc.Utf8
);
} catch (e) {
Expand Down
Loading

0 comments on commit 7e091d8

Please sign in to comment.