mirror of
https://github.com/mosip/inji-wallet.git
synced 2026-01-08 21:18:14 -05:00
* chore(INJI-195): upgrade react native version and dependencies * chore(INJI-195): upgrade expo version and dependencies * chore(INJI-195): modify associated files on version upgrade * chore(INJI-295): fixed react native flipper and patch packages * chore(INJI-195): fix for expo prebuild * chore(INJI-195): expo linked to android/ios projects * chore(INJI-195): update metro config * chore(INJI-195): fix ios build with mmkv storage patch * chore(INJI-195): gradle version modified * chore(INJI-195): fixed rn version 0.71.8 due to mmkv library issue * chore(INJI-195): removed files in android * chore(INJI-195): fix 0.71.8 for iOS project through pods with expo linking * chore(INJI-195): fix for custom fonts added through pods due to rn linkage * chore(INJI-195): fix for removing assets.car generated from pods * Modify Node version in pipeline (#806) * chore(INJI-195): fix for android splash screen not shown up * chore(INJI-195): upgraded to node 18 in pipeline * chore(INJI-195): add the pod install twice to remove duplicates via script workaround (#807) Signed-off-by: dhivya0413 <120356578+dhivya0413@users.noreply.github.com> * INJI-195 Set the signing team for iOS (#810) * chore(INJI-195): add the pod install twice to remove duplicates via script workaround * chore(INJI-195): set the signing team for ios build --------- Signed-off-by: dhivya0413 <120356578+dhivya0413@users.noreply.github.com> * Modify github runner to self hosted runner (#811) * chore(INJI-195): add the pod install twice to remove duplicates via script workaround * chore(INJI-195): set the signing team for ios build * chore(INJI-195): set the self hosted runner for ios build --------- Signed-off-by: dhivya0413 <120356578+dhivya0413@users.noreply.github.com> * Modify self hosted runner to github hosted runner (#813) * chore(INJI-195): add the pod install twice to remove duplicates via script workaround * chore(INJI-195): set the signing team for ios build * chore(INJI-195): set the self hosted runner for ios build * chore(INJI-195): modify the self hosted to github hosted runner --------- Signed-off-by: dhivya0413 <120356578+dhivya0413@users.noreply.github.com> * chore(INJI-195): modify the self hosted to github hosted runner * chore(INJI-195): set the code signing identity for ios build * chore(INJI-195): assigned app icon files to asset --------- Signed-off-by: dhivya0413 <120356578+dhivya0413@users.noreply.github.com> Signed-off-by: Swati Goel <meet2swati@gmail.com> Co-authored-by: Swati Goel <meet2swati@gmail.com>
230 lines
7.0 KiB
TypeScript
230 lines
7.0 KiB
TypeScript
import {NavigationProp, useNavigation} from '@react-navigation/native';
|
|
import {useSelector} from '@xstate/react';
|
|
import {useContext, useEffect} from 'react';
|
|
import {useTranslation} from 'react-i18next';
|
|
import {MessageOverlayProps} from '../../components/MessageOverlay';
|
|
import {MainBottomTabParamList} from '../../routes/main';
|
|
import {GlobalContext} from '../../shared/GlobalContext';
|
|
import {
|
|
selectIsConnecting,
|
|
selectIsConnectingTimeout,
|
|
selectIsInvalid,
|
|
selectIsLocationDenied,
|
|
selectIsLocationDisabled,
|
|
selectIsQrLoginDone,
|
|
selectIsScanning,
|
|
selectIsSendingVc,
|
|
selectIsSendingVcTimeout,
|
|
selectIsSent,
|
|
selectReceiverInfo,
|
|
selectIsDone,
|
|
selectStayInProgress,
|
|
} from '../../machines/bleShare/scan/selectors';
|
|
import {
|
|
selectIsAccepted,
|
|
selectIsDisconnected,
|
|
selectIsExchangingDeviceInfo,
|
|
selectIsExchangingDeviceInfoTimeout,
|
|
selectIsHandlingBleError,
|
|
selectIsOffline,
|
|
selectIsRejected,
|
|
selectIsReviewing,
|
|
selectBleError,
|
|
} from '../../machines/bleShare/commonSelectors';
|
|
import {ScanEvents} from '../../machines/bleShare/scan/scanMachine';
|
|
import {BOTTOM_TAB_ROUTES, SCAN_ROUTES} from '../../routes/routesConstants';
|
|
import {ScanStackParamList} from '../../routes/routesConstants';
|
|
|
|
type ScanLayoutNavigation = NavigationProp<
|
|
ScanStackParamList & MainBottomTabParamList
|
|
>;
|
|
|
|
// TODO: refactor
|
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
export function useScanLayout() {
|
|
const {t} = useTranslation('ScanScreen');
|
|
const {appService} = useContext(GlobalContext);
|
|
const scanService = appService.children.get('scan');
|
|
const navigation = useNavigation<ScanLayoutNavigation>();
|
|
|
|
const isLocationDisabled = useSelector(scanService, selectIsLocationDisabled);
|
|
const isLocationDenied = useSelector(scanService, selectIsLocationDenied);
|
|
const isBleError = useSelector(scanService, selectIsHandlingBleError);
|
|
const bleError = useSelector(scanService, selectBleError);
|
|
|
|
const locationError = {message: '', button: ''};
|
|
|
|
if (isLocationDisabled) {
|
|
locationError.message = t('errors.locationDisabled.message');
|
|
locationError.button = t('errors.locationDisabled.button');
|
|
} else if (isLocationDenied) {
|
|
locationError.message = t('errors.locationDenied.message');
|
|
locationError.button = t('errors.locationDenied.button');
|
|
}
|
|
|
|
const DISMISS = () => scanService.send(ScanEvents.DISMISS());
|
|
const CANCEL = () => scanService.send(ScanEvents.CANCEL());
|
|
|
|
const receiverInfo = useSelector(scanService, selectReceiverInfo);
|
|
|
|
const isInvalid = useSelector(scanService, selectIsInvalid);
|
|
const isConnecting = useSelector(scanService, selectIsConnecting);
|
|
const isConnectingTimeout = useSelector(
|
|
scanService,
|
|
selectIsConnectingTimeout,
|
|
);
|
|
const isExchangingDeviceInfo = useSelector(
|
|
scanService,
|
|
selectIsExchangingDeviceInfo,
|
|
);
|
|
const isExchangingDeviceInfoTimeout = useSelector(
|
|
scanService,
|
|
selectIsExchangingDeviceInfoTimeout,
|
|
);
|
|
const isAccepted = useSelector(scanService, selectIsAccepted);
|
|
const isRejected = useSelector(scanService, selectIsRejected);
|
|
const isSent = useSelector(scanService, selectIsSent);
|
|
const isOffline = useSelector(scanService, selectIsOffline);
|
|
const isSendingVc = useSelector(scanService, selectIsSendingVc);
|
|
const isSendingVcTimeout = useSelector(scanService, selectIsSendingVcTimeout);
|
|
|
|
const onCancel = () => scanService.send(ScanEvents.CANCEL());
|
|
const onStayInProgress = () =>
|
|
scanService.send(ScanEvents.STAY_IN_PROGRESS());
|
|
const onRetry = () => scanService.send(ScanEvents.RETRY());
|
|
let statusOverlay: Pick<
|
|
MessageOverlayProps,
|
|
| 'title'
|
|
| 'message'
|
|
| 'hint'
|
|
| 'onCancel'
|
|
| 'onStayInProgress'
|
|
| 'onRetry'
|
|
| 'progress'
|
|
| 'onBackdropPress'
|
|
| 'requester'
|
|
> = null;
|
|
if (isConnecting) {
|
|
statusOverlay = {
|
|
title: t('status.inProgress'),
|
|
message: t('status.establishingConnection'),
|
|
progress: true,
|
|
};
|
|
} else if (isConnectingTimeout) {
|
|
statusOverlay = {
|
|
title: t('status.sharingInProgress'),
|
|
hint: t('status.connectingTimeout'),
|
|
onCancel,
|
|
onStayInProgress,
|
|
onRetry,
|
|
progress: true,
|
|
};
|
|
} else if (isExchangingDeviceInfo) {
|
|
statusOverlay = {
|
|
message: t('status.exchangingDeviceInfo'),
|
|
progress: true,
|
|
};
|
|
} else if (isExchangingDeviceInfoTimeout) {
|
|
statusOverlay = {
|
|
message: t('status.exchangingDeviceInfo'),
|
|
hint: t('status.exchangingDeviceInfoTimeout'),
|
|
onCancel: CANCEL,
|
|
progress: true,
|
|
};
|
|
} else if (isSent) {
|
|
statusOverlay = {
|
|
message: t('status.sent'),
|
|
hint: t('status.sentHint'),
|
|
progress: false,
|
|
onCancel: CANCEL,
|
|
};
|
|
} else if (isSendingVc) {
|
|
statusOverlay = {
|
|
title: t('status.sharing.title'),
|
|
hint: t('status.sharing.hint'),
|
|
progress: true,
|
|
};
|
|
} else if (isSendingVcTimeout) {
|
|
statusOverlay = {
|
|
title: t('status.sharing.title'),
|
|
hint: t('status.sharing.timeoutHint'),
|
|
onCancel: CANCEL,
|
|
progress: true,
|
|
};
|
|
} else if (isAccepted) {
|
|
statusOverlay = {
|
|
title: t('status.accepted.title'),
|
|
message: t('status.accepted.message'),
|
|
onCancel: DISMISS,
|
|
};
|
|
} else if (isRejected) {
|
|
statusOverlay = {
|
|
title: t('status.rejected.title'),
|
|
message: t('status.rejected.message'),
|
|
onBackdropPress: DISMISS,
|
|
};
|
|
} else if (isInvalid) {
|
|
statusOverlay = {
|
|
message: t('status.invalid'),
|
|
onBackdropPress: DISMISS,
|
|
};
|
|
} else if (isOffline) {
|
|
statusOverlay = {
|
|
message: t('status.offline'),
|
|
onBackdropPress: DISMISS,
|
|
};
|
|
} else if (isBleError) {
|
|
statusOverlay = {
|
|
title: t('status.bleError.title'),
|
|
message: t('status.bleError.message'),
|
|
hint:
|
|
bleError.code &&
|
|
t('status.bleError.hint', {
|
|
code: bleError.code,
|
|
}),
|
|
onBackdropPress: DISMISS,
|
|
};
|
|
}
|
|
|
|
useEffect(() => {
|
|
const subscriptions = [
|
|
navigation.addListener('focus', () =>
|
|
scanService.send(ScanEvents.SCREEN_FOCUS()),
|
|
),
|
|
navigation.addListener('blur', () =>
|
|
scanService.send(ScanEvents.SCREEN_BLUR()),
|
|
),
|
|
];
|
|
|
|
return () => {
|
|
subscriptions.forEach(unsubscribe => unsubscribe());
|
|
};
|
|
}, []);
|
|
|
|
const isDone = useSelector(scanService, selectIsDone);
|
|
const isReviewing = useSelector(scanService, selectIsReviewing);
|
|
const isScanning = useSelector(scanService, selectIsScanning);
|
|
const isQrLoginDone = useSelector(scanService, selectIsQrLoginDone);
|
|
|
|
useEffect(() => {
|
|
if (isDone) {
|
|
navigation.navigate(BOTTOM_TAB_ROUTES.home);
|
|
} else if (isReviewing) {
|
|
navigation.navigate(SCAN_ROUTES.SendVcScreen);
|
|
} else if (isScanning) {
|
|
navigation.navigate(SCAN_ROUTES.ScanScreen);
|
|
} else if (isQrLoginDone) {
|
|
navigation.navigate(BOTTOM_TAB_ROUTES.history);
|
|
}
|
|
}, [isDone, isReviewing, isScanning, isQrLoginDone, isBleError]);
|
|
|
|
return {
|
|
isInvalid,
|
|
isDone,
|
|
isDisconnected: useSelector(scanService, selectIsDisconnected),
|
|
statusOverlay,
|
|
isStayInProgress: useSelector(scanService, selectStayInProgress),
|
|
DISMISS,
|
|
};
|
|
}
|