Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(INJI-329): fix received card expand view and redirect the user to history screen after VC transfer #799

Merged
merged 6 commits into from
Sep 12, 2023
22 changes: 19 additions & 3 deletions machines/bleShare/request/requestMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export const requestMachine =
},
on: {
DISMISS: {
target: 'navigatingToHistory',
target: 'displayingIncomingVC',
},
},
},
Expand All @@ -431,11 +431,27 @@ export const requestMachine =
displayingIncomingVC: {
on: {
GO_TO_RECEIVED_VC_TAB: {
target: 'navigatingToHistory',
target: 'navigatingToReceivedCards',
},
},
},
navigatingToReceivedCards: {
on: {
DISMISS: {
target: 'navigatingToHome',
},
},
},
navigatingToHome: {
invoke: {
src: 'disconnect',
},
on: {
DISCONNECT: {
target: '#request.inactive',
},
},
},

savingFailed: {
initial: 'idle',
entry: ['setReceiveLogTypeDiscarded', 'logReceived'],
Expand Down
7 changes: 6 additions & 1 deletion machines/bleShare/request/requestMachine.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export interface Typegen0 {
checkStorageAvailability: 'done.invoke.request.checkStorage:invocation[0]';
disconnect:
| 'done.invoke.request.clearingConnection:invocation[0]'
| 'done.invoke.request.reviewing.navigatingToHistory:invocation[0]';
| 'done.invoke.request.reviewing.navigatingToHistory:invocation[0]'
| 'done.invoke.request.reviewing.navigatingToHome:invocation[0]';
monitorConnection: 'done.invoke.request:invocation[0]';
receiveVc: 'done.invoke.request.waitingForVc:invocation[0]';
requestBluetooth: 'done.invoke.request.checkingBluetoothService.requesting:invocation[0]';
Expand Down Expand Up @@ -148,6 +149,8 @@ export interface Typegen0 {
| 'reviewing.idle'
| 'reviewing.invalidIdentity'
| 'reviewing.navigatingToHistory'
| 'reviewing.navigatingToHome'
| 'reviewing.navigatingToReceivedCards'
| 'reviewing.rejected'
| 'reviewing.savingFailed'
| 'reviewing.savingFailed.idle'
Expand All @@ -169,6 +172,8 @@ export interface Typegen0 {
| 'idle'
| 'invalidIdentity'
| 'navigatingToHistory'
| 'navigatingToHome'
| 'navigatingToReceivedCards'
| 'rejected'
| 'savingFailed'
| 'verifyingIdentity'
Expand Down
8 changes: 8 additions & 0 deletions machines/bleShare/request/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,11 @@ export function selectIsSavingFailedInViewingVc(state: State) {
export function selectIsDone(state: State) {
return state.matches('reviewing.navigatingToHistory');
}

export function selectIsNavigatingToReceivedCards(state: State) {
return state.matches('reviewing.navigatingToReceivedCards');
}

export function selectIsNavigatingToHome(state: State) {
return state.matches('reviewing.navigatingToHome');
}
1 change: 1 addition & 0 deletions machines/settings.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Typegen0 {
};
'eventsCausingActions': {
injiTourGuide:
| 'ACCEPT_HARDWARE_SUPPORT_NOT_EXISTS'
| 'BACK'
| 'CANCEL'
| 'STORE_RESPONSE'
Expand Down
16 changes: 8 additions & 8 deletions routes/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { RootStackParamList } from './index';
import { ScanLayout } from '../screens/Scan/ScanLayout';
import { HistoryScreen } from '../screens/History/HistoryScreen';
import i18n from '../i18n';
import { BOTTOM_TAB_ROUTES } from './routesConstants';

const home: TabScreen = {
name: 'home',
name: BOTTOM_TAB_ROUTES.home,
component: HomeScreen,
icon: 'home',
options: {
Expand All @@ -24,16 +25,17 @@ const home: TabScreen = {
},
};
export const scan: TabScreen = {
name: 'scan',
name: BOTTOM_TAB_ROUTES.scan,
component: ScanLayout,
icon: 'qr-code-scanner',
options: {
title: i18n.t('MainLayout:scan'),
headerShown: false,
},
};

const history: TabScreen = {
name: 'history',
name: BOTTOM_TAB_ROUTES.history,
component: HistoryScreen,
icon: 'history',
options: {
Expand All @@ -48,11 +50,9 @@ mainRoutes.push(scan);
mainRoutes.push(history);

export type MainBottomTabParamList = {
home: {
activeTab: number;
};
Scan: undefined;
History: undefined;
home: undefined;
scan: undefined;
history: undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Can we have consistent naming for routes? Scan is starting with capital letter while others are not
  2. Can we reuse this value in initialised of tab screen at line number 36 also? to avoid mismatch for all routes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, extracted the bottom tab, scan and request screen names into separate file to maintain the consistency

};

export interface TabScreen {
Expand Down
29 changes: 29 additions & 0 deletions routes/routesConstants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { MainBottomTabParamList } from './main';

export const BOTTOM_TAB_ROUTES = {
home: 'home' as keyof MainBottomTabParamList,
scan: 'scan' as keyof MainBottomTabParamList,
history: 'history' as keyof MainBottomTabParamList,
};

export const SCAN_ROUTES = {
ScanScreen: 'ScanScreen' as keyof ScanStackParamList,
SendVcScreen: 'SendVcScreen' as keyof ScanStackParamList,
};

export const REQUEST_ROUTES = {
Request: 'Request' as keyof RequestStackParamList,
RequestScreen: 'RequestScreen' as keyof RequestStackParamList,
ReceiveVcScreen: 'ReceiveVcScreen' as keyof RequestStackParamList,
};

export type ScanStackParamList = {
ScanScreen: undefined;
SendVcScreen: undefined;
};

export type RequestStackParamList = {
Request: undefined;
RequestScreen: undefined;
ReceiveVcScreen: undefined;
};
4 changes: 0 additions & 4 deletions screens/Home/MyVcsTabController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
MyVcsTabEvents,
MyVcsTabMachine,
selectAddVcModal,
selectIsOnboarding,
selectIsRequestSuccessful,
selectGetVcModal,
selectIsSavingFailedInIdle,
Expand Down Expand Up @@ -46,7 +45,6 @@ export function useMyVcsTab(props: HomeScreenTabProps) {

isRefreshingVcs: useSelector(vcService, selectIsRefreshingMyVcs),
isRequestSuccessful: useSelector(service, selectIsRequestSuccessful),
isOnboarding: useSelector(service, selectIsOnboarding),
isSavingFailedInIdle: useSelector(service, selectIsSavingFailedInIdle),
walletBindingError: useSelector(service, selectWalletBindingError),
isBindingError: useSelector(service, selectShowWalletBindingError),
Expand All @@ -70,8 +68,6 @@ export function useMyVcsTab(props: HomeScreenTabProps) {
return service.send(MyVcsTabEvents.VIEW_VC(vcRef));
},

ONBOARDING_DONE: () => service.send(MyVcsTabEvents.ONBOARDING_DONE()),

IS_TAMPERED: () => service.send(MyVcsTabEvents.IS_TAMPERED()),

ACCEPT_HARDWARE_SUPPORT_NOT_EXISTS: () =>
Expand Down
49 changes: 2 additions & 47 deletions screens/Home/MyVcsTabMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import { StoreEvents, StoreResponseEvent } from '../../machines/store';
import { VcEvents } from '../../machines/vc';
import { vcItemMachine } from '../../machines/vcItem';
import { AppServices } from '../../shared/GlobalContext';
import {
MY_VCS_STORE_KEY,
ONBOARDING_STATUS_STORE_KEY,
} from '../../shared/constants';
import { MY_VCS_STORE_KEY } from '../../shared/constants';
import { AddVcModalMachine } from './MyVcs/AddVcModalMachine';
import { GetVcModalMachine } from './MyVcs/GetVcModalMachine';
import Storage from '../../shared/storage';
Expand All @@ -36,7 +33,6 @@ const model = createModel(
GET_VC: () => ({}),
STORAGE_AVAILABLE: () => ({}),
STORAGE_UNAVAILABLE: () => ({}),
ONBOARDING_DONE: () => ({}),
IS_TAMPERED: () => ({}),
},
}
Expand All @@ -57,31 +53,8 @@ export const MyVcsTabMachine = model.createMachine(
events: {} as EventFrom<typeof model>,
},
id: 'MyVcsTab',
initial: 'checkingOnboardingStatus',
initial: 'idle',
states: {
checkingOnboardingStatus: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the onboarding flow removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the old code we were using Onboarding status variable to decide whether we need to show the intro sliders in the MyVCs screen or not and when the app is installed and download the first VC we are setting that variable to true considering that onboarding is completed but there is a issue with this approach -
on the verifier side if we click on the received card we are creating new instance of MyVCS machine and it checks whether onboarding is completed or not since we didn't download the new vc that variable is not set to true and it will go into "Onboarding" state and inside this state there is no "VIEW_VC" event and the received card detailed view is failing because of this.
Now we are checking whether onboarding is done or not by checking if language preference is done or not so onboarding flow is not required

entry: ['getOnboardingStatus'],
on: {
STORE_RESPONSE: [
{ cond: 'isOnboardingDone', target: 'idle' },
{ target: 'onboarding' },
],
},
},
onboarding: {
on: {
ADD_VC: [
{
target: 'addVc',
actions: ['completeOnboarding'],
},
],
ONBOARDING_DONE: {
target: 'idle',
actions: ['completeOnboarding'],
},
},
},
addVc: {
initial: 'checkStorage',
states: {
Expand Down Expand Up @@ -202,16 +175,6 @@ export const MyVcsTabMachine = model.createMachine(
model.events.VIEW_VC(event.vcItemActor)
),

getOnboardingStatus: send(
() => StoreEvents.GET(ONBOARDING_STATUS_STORE_KEY),
{ to: (context) => context.serviceRefs.store }
),

completeOnboarding: send(
() => StoreEvents.SET(ONBOARDING_STATUS_STORE_KEY, true),
{ to: (context) => context.serviceRefs.store }
),

storeVcItem: send(
(_context, event) => {
return StoreEvents.PREPEND(
Expand All @@ -231,10 +194,6 @@ export const MyVcsTabMachine = model.createMachine(
},

guards: {
isOnboardingDone: (_context, event: StoreResponseEvent) => {
return event.response === true;
},

isMinimumStorageLimitReached: (_context, event) => Boolean(event.data),
},
}
Expand All @@ -257,10 +216,6 @@ export function selectGetVcModal(state: State) {
return state.children.GetVcModal as ActorRefFrom<typeof GetVcModalMachine>;
}

export function selectIsOnboarding(state: State) {
return state.matches('onboarding');
}

export function selectIsRequestSuccessful(state: State) {
return state.matches('addingVc.addVcSuccessful');
}
Expand Down
5 changes: 0 additions & 5 deletions screens/Home/MyVcsTabMachine.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export interface Typegen0 {
services: never;
};
'eventsCausingActions': {
completeOnboarding: 'ADD_VC' | 'ONBOARDING_DONE';
getOnboardingStatus: 'xstate.init';
refreshMyVc: 'IS_TAMPERED';
resetIsTampered: 'IS_TAMPERED';
sendVcAdded: 'STORE_RESPONSE';
Expand All @@ -41,7 +39,6 @@ export interface Typegen0 {
'eventsCausingDelays': {};
'eventsCausingGuards': {
isMinimumStorageLimitReached: 'done.invoke.MyVcsTab.addVc.checkStorage:invocation[0]';
isOnboardingDone: 'STORE_RESPONSE';
};
'eventsCausingServices': {
AddVcModal:
Expand All @@ -60,11 +57,9 @@ export interface Typegen0 {
| 'addingVc.savingFailed.idle'
| 'addingVc.storing'
| 'addingVc.waitingForvcKey'
| 'checkingOnboardingStatus'
| 'gettingVc'
| 'gettingVc.waitingForvcKey'
| 'idle'
| 'onboarding'
| 'viewingVc'
| {
addVc?: 'checkStorage' | 'storageLimitReached';
Expand Down
14 changes: 11 additions & 3 deletions screens/Request/RequestLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import { useRequestLayout } from './RequestLayoutController';
import { Message } from '../../components/Message';
import { ReceiveVcScreen } from './ReceiveVcScreen';
import { MessageOverlay } from '../../components/MessageOverlay';

import { ReceivedCardsModal } from '../Settings/ReceivedCardsModal';
import { useReceivedVcsTab } from '../Home/ReceivedVcsTabController';
import { REQUEST_ROUTES } from '../../routes/routesConstants';
const RequestStack = createNativeStackNavigator();

export const RequestLayout: React.FC = () => {
const { t } = useTranslation('RequestScreen');
const controller = useRequestLayout();
const receivedCardsController = useReceivedVcsTab();

return (
<React.Fragment>
Expand All @@ -31,7 +34,7 @@ export const RequestLayout: React.FC = () => {
}}>
{!controller.isDone && (
<RequestStack.Screen
name="ReceiveVcScreen"
name={REQUEST_ROUTES.ReceiveVcScreen}
component={ReceiveVcScreen}
options={{
title: t('incomingVc'),
Expand All @@ -46,14 +49,19 @@ export const RequestLayout: React.FC = () => {
/>
)}
<RequestStack.Screen
name="RequestScreen"
name={REQUEST_ROUTES.RequestScreen}
component={RequestScreen}
options={{
title: t('receiveCard').toUpperCase(),
}}
/>
</RequestStack.Navigator>

<ReceivedCardsModal
isVisible={controller.isNavigatingToReceivedCards}
controller={receivedCardsController}
onDismiss={controller.DISMISS}
/>
{controller.isAccepted && (
<Message
title={t('status.accepted.title')}
Expand Down
Loading