Skip to content

Commit

Permalink
fix(Inji 332): reset UIN field in add vc modal and set AddVcModal dro…
Browse files Browse the repository at this point in the history
…pdown to VID (#864)

* fix(INJI-332): reset the UIN field in AddVcModal after downloading the VC using AID and show VID in dropdown

* refactor(INJI-332): remove unnecessary formatting changes

* fix(INJI-332): change default value of getIndividualId response to UIN in getVcModal

Signed-off-by: PuBHARGAVI <[email protected]>

* remove project.pbxproj changes

* Revert "remove project.pbxproj changes"

This reverts commit ba7d9ec.

* fix(INJI-332): reset the project.pbxproj file

Signed-off-by: PuBHARGAVI <[email protected]>

---------

Signed-off-by: PuBHARGAVI <[email protected]>
  • Loading branch information
PuBHARGAVI authored Oct 13, 2023
1 parent 080ef3d commit 0537cf6
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 93 deletions.
2 changes: 1 addition & 1 deletion ios/Inji.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -557,4 +557,4 @@
/* End XCConfigurationList section */
};
rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */;
}
}
54 changes: 1 addition & 53 deletions machines/store.typegen.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,5 @@
// This file was automatically generated. Edits will be overwritten

<<<<<<< HEAD
// This file was automatically generated. Edits will be overwritten

export interface Typegen0 {
'@@xstate/typegen': true;
internalEvents: {
"done.invoke._store": { type: "done.invoke._store"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." };
"done.invoke.store.resettingStorage:invocation[0]": { type: "done.invoke.store.resettingStorage:invocation[0]"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." };
"error.platform._store": { type: "error.platform._store"; data: unknown };
"xstate.init": { type: "xstate.init" };
};
invokeSrcNameMap: {
"checkStorageInitialisedOrNot": "done.invoke.store.checkStorageInitialisation:invocation[0]";
"clear": "done.invoke.store.resettingStorage:invocation[0]";
"generateEncryptionKey": "done.invoke.store.generatingEncryptionKey:invocation[0]";
"getEncryptionKey": "done.invoke.store.gettingEncryptionKey:invocation[0]";
"hasAndroidEncryptionKey": "done.invoke.store.checkEncryptionKey:invocation[0]";
"store": "done.invoke._store";
};
missingImplementations: {
actions: "logKey";
delays: never;
guards: never;
services: never;
};
eventsCausingActions: {
"forwardStoreRequest": "APPEND" | "CLEAR" | "GET" | "PREPEND" | "REMOVE" | "REMOVE_ITEMS" | "REMOVE_VC_METADATA" | "SET" | "UPDATE";
"logKey": "KEY_RECEIVED";
"notifyParent": "KEY_RECEIVED" | "READY" | "done.invoke.store.resettingStorage:invocation[0]";
"setEncryptionKey": "KEY_RECEIVED";
};
eventsCausingDelays: {

};
eventsCausingGuards: {
"isCustomSecureKeystore": "KEY_RECEIVED";
};
eventsCausingServices: {
"checkStorageInitialisedOrNot": "ERROR";
"clear": "KEY_RECEIVED";
"generateEncryptionKey": "ERROR" | "IGNORE" | "READY";
"getEncryptionKey": "TRY_AGAIN";
"hasAndroidEncryptionKey": never;
"store": "KEY_RECEIVED" | "READY" | "done.invoke.store.resettingStorage:invocation[0]";
};
matchesStates: "checkEncryptionKey" | "checkStorageInitialisation" | "failedReadingKey" | "generatingEncryptionKey" | "gettingEncryptionKey" | "ready" | "resettingStorage";
tags: never;
}

=======
export interface Typegen0 {
'@@xstate/typegen': true;
internalEvents: {
Expand Down Expand Up @@ -95,9 +46,7 @@ export interface Typegen0 {
| 'KEY_RECEIVED'
| 'READY'
| 'done.invoke.store.resettingStorage:invocation[0]';
resetIsTamperedVc: 'RESET_IS_TAMPERED';
setEncryptionKey: 'KEY_RECEIVED';
setIsTamperedVc: 'TAMPERED_VC';
};
eventsCausingDelays: {};
eventsCausingGuards: {
Expand All @@ -124,4 +73,3 @@ export interface Typegen0 {
| 'resettingStorage';
tags: never;
}
>>>>>>> 5b53b069 (refactor(INJI-205): Check Internet before OIDC AuthZ)
21 changes: 17 additions & 4 deletions screens/Home/MyVcs/AddVcModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,32 @@ import { AddVcModalProps, useAddVcModal } from './AddVcModalController';
import { OtpVerificationModal } from './OtpVerificationModal';
import { IdInputModal } from './IdInputModal';
import { useTranslation } from 'react-i18next';
import { GET_INDIVIDUAL_ID } from '../../../shared/constants';

export const AddVcModal: React.FC<AddVcModalProps> = (props) => {
const { t } = useTranslation('AddVcModal');
const controller = useAddVcModal(props);

const shouldShowAddVcModal = () => {
if (controller.isRequestingCredential) {
GET_INDIVIDUAL_ID({id: '', idType: 'UIN'});
}
return (
!controller.isAcceptingOtpInput && !controller.isRequestingCredential
);
};

const dismissIdInputModal = () => {
GET_INDIVIDUAL_ID({id: '', idType: 'UIN'});
controller.DISMISS();
};

return (
<React.Fragment>
<IdInputModal
service={props.service}
isVisible={
!controller.isAcceptingOtpInput && !controller.isRequestingCredential
}
onDismiss={controller.DISMISS}
isVisible={shouldShowAddVcModal()}
onDismiss={dismissIdInputModal}
onPress={props.onPress}
/>

Expand Down
3 changes: 3 additions & 0 deletions screens/Home/MyVcs/AddVcModalMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export const AddVcModalMachine =
INPUT_ID: {
actions: 'setId',
},
SELECT_ID_TYPE: {
actions: ['clearIdError', 'setIdType'],
},
},
states: {
acceptingIdInput: {
Expand Down
62 changes: 33 additions & 29 deletions screens/Home/MyVcs/GetVcModalMachine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextInput } from 'react-native';
import {TextInput} from 'react-native';
import {
assign,
ErrorPlatformEvent,
Expand All @@ -7,11 +7,11 @@ import {
sendParent,
StateFrom,
} from 'xstate';
import { createModel } from 'xstate/lib/model';
import { BackendResponseError, request } from '../../../shared/request';
import {createModel} from 'xstate/lib/model';
import {BackendResponseError, request} from '../../../shared/request';
import i18n from '../../../i18n';
import { AddVcModalMachine } from './AddVcModalMachine';
import { GET_INDIVIDUAL_ID } from '../../../shared/constants';
import {AddVcModalMachine} from './AddVcModalMachine';
import {GET_INDIVIDUAL_ID, IndividualId} from '../../../shared/constants';

const model = createModel(
{
Expand All @@ -26,16 +26,16 @@ const model = createModel(
},
{
events: {
INPUT_ID: (id: string) => ({ id }),
INPUT_OTP: (otp: string) => ({ otp }),
INPUT_ID: (id: string) => ({id}),
INPUT_OTP: (otp: string) => ({otp}),
VALIDATE_INPUT: () => ({}),
ACTIVATE_ICON_COLOR: () => ({}),
DEACTIVATE_ICON_COLOR: () => ({}),
READY: (idInputRef: TextInput) => ({ idInputRef }),
READY: (idInputRef: TextInput) => ({idInputRef}),
DISMISS: () => ({}),
GOT_ID: (id: string) => ({ id }),
GOT_ID: (id: string) => ({id}),
},
}
},
);

export const GetVcModalEvents = model.events;
Expand Down Expand Up @@ -222,13 +222,14 @@ export const GetVcModalMachine =
transactionId: () => String(new Date().valueOf()).substring(3, 13),
}),

setIndividualId: (_context, event) =>
GET_INDIVIDUAL_ID((event as DoneInvokeEvent<string>).data),
setIndividualId: (_context, event) => {
GET_INDIVIDUAL_ID((event as DoneInvokeEvent<IndividualId>).data);
},

setIdBackendError: assign({
idError: (context, event) => {
if ((event as ErrorPlatformEvent).data == 'IDA-MLC-001') {
return i18n.t('errors.backend.timeOut', { ns: 'GetVcModal' });
return i18n.t('errors.backend.timeOut', {ns: 'GetVcModal'});
}

const message = (event as ErrorPlatformEvent).data.message;
Expand All @@ -246,15 +247,15 @@ export const GetVcModalMachine =
},
}),

clearIdError: model.assign({ idError: '' }),
clearIdError: model.assign({idError: ''}),

setIdErrorEmpty: model.assign({
idError: () => i18n.t('errors.input.empty', { ns: 'GetVcModal' }),
idError: () => i18n.t('errors.input.empty', {ns: 'GetVcModal'}),
}),

setIdErrorWrongFormat: model.assign({
idError: () =>
i18n.t('errors.input.invalidFormat', { ns: 'GetVcModal' }),
i18n.t('errors.input.invalidFormat', {ns: 'GetVcModal'}),
}),

setOtpError: assign({
Expand Down Expand Up @@ -282,17 +283,17 @@ export const GetVcModalMachine =
},
}),

clearOtp: assign({ otp: '' }),
clearOtp: assign({otp: ''}),

setIconColorActivate: assign({ iconColor: true }),
setIconColorActivate: assign({iconColor: true}),

setIconColorDeactivate: assign({ iconColor: false }),
setIconColorDeactivate: assign({iconColor: false}),

focusInput: (context) => context.idInputRef.focus(),
focusInput: context => context.idInputRef.focus(),
},

services: {
requestOtp: async (context) => {
requestOtp: async context => {
return await request(
'POST',
'/residentmobileapp/req/individualId/otp',
Expand All @@ -304,35 +305,38 @@ export const GetVcModalMachine =
requestTime: String(new Date().toISOString()),
transactionID: context.transactionId,
version: '1.0',
}
},
);
},

requestingUinVid: async (context) => {
requestingUinVid: async context => {
const response = await request(
'POST',
'/residentmobileapp/aid/get-individual-id',
{
aid: context.id,
otp: context.otp,
transactionID: context.transactionId,
}
},
);
return response.response.individualId;
return {
id: response.response.individualId,
idType: response.response.individualIdType || 'UIN',
};
},
},

guards: {
isEmptyId: ({ id }) => !id || !id.length,
isEmptyId: ({id}) => !id || !id.length,

isWrongIdFormat: ({ id }) => !/^\d{14,29}$/.test(id),
isWrongIdFormat: ({id}) => !/^\d{14,29}$/.test(id),

isIdInvalid: (_context, event: unknown) =>
['RES-SER-449', 'IDA-MLC-001'].includes(
(event as BackendResponseError).name
(event as BackendResponseError).name,
),
},
}
},
);

type State = StateFrom<typeof GetVcModalMachine>;
Expand Down
5 changes: 3 additions & 2 deletions screens/Home/MyVcs/IdInputModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ export const IdInputModal: React.FC<IdInputModalProps> = props => {
const controller = useIdInputModal(props);

const setIndividualID = () => {
controller.INPUT_ID(individualId);
controller.INPUT_ID(individualId.id);
controller.SELECT_ID_TYPE(individualId.idType);
};

const dismissInput = () => {
props.onDismiss();
GET_INDIVIDUAL_ID('');
GET_INDIVIDUAL_ID({id: '', idType: 'UIN'});
};

const inputLabel = t('enterId', {idType: controller.idType});
Expand Down
2 changes: 1 addition & 1 deletion screens/Home/MyVcsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const MyVcsTab: React.FC<HomeScreenTabProps> = props => {
};

const clearIndividualId = () => {
GET_INDIVIDUAL_ID('');
GET_INDIVIDUAL_ID({id: '', idType: 'UIN'});
};

useEffect(() => {
Expand Down
11 changes: 8 additions & 3 deletions shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DEBUG_MODE,
} from 'react-native-dotenv';
import {Argon2iConfig} from './commonUtil';
import {VcIdType} from '../types/vc';

export let MIMOTO_BASE_URL = MIMOTO_HOST;
export let ESIGNET_BASE_URL = ESIGNET_HOST;
Expand All @@ -20,10 +21,10 @@ export const RECEIVED_VCS_STORE_KEY = 'receivedVCs';

export const MY_LOGIN_STORE_KEY = 'myLogins';

export let individualId = '';
export let individualId = {id: '', idType: 'UIN' as VcIdType};

export const GET_INDIVIDUAL_ID = (ind_Id: string) => {
individualId = ind_Id;
export const GET_INDIVIDUAL_ID = (currentIndividualId: IndividualId) => {
individualId = currentIndividualId;
};

export const ACTIVITY_LOG_STORE_KEY = 'activityLog';
Expand Down Expand Up @@ -69,5 +70,9 @@ export const argon2iConfigForUinVid: Argon2iConfig = {
export const argon2iSalt =
'1234567891011121314151617181920212223242526272829303132333435363';

export type IndividualId = {
id: string;
idType: VcIdType;
};
export const NETWORK_REQUEST_FAILED = 'Network request failed';
export const REQUEST_TIMEOUT = 'request timedout';

0 comments on commit 0537cf6

Please sign in to comment.