mirror of
https://github.com/mosip/inji-wallet.git
synced 2026-01-10 05:58:01 -05:00
50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
import { useSelector } from '@xstate/react';
|
|
import { useContext } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import {
|
|
ScanEvents,
|
|
selectIsLocationDisabled,
|
|
selectIsLocationDenied,
|
|
selectIsScanning,
|
|
} from '../../machines/scan';
|
|
import { selectVcLabel } from '../../machines/settings';
|
|
import { selectShareableVcs } from '../../machines/vc';
|
|
import { GlobalContext } from '../../shared/GlobalContext';
|
|
|
|
export function useScanScreen() {
|
|
const { t } = useTranslation('ScanScreen');
|
|
const { appService } = useContext(GlobalContext);
|
|
const scanService = appService.children.get('scan');
|
|
const settingsService = appService.children.get('settings');
|
|
const vcService = appService.children.get('vc');
|
|
|
|
const shareableVcs = useSelector(vcService, selectShareableVcs);
|
|
|
|
const isLocationDisabled = useSelector(scanService, selectIsLocationDisabled);
|
|
const isLocationDenied = useSelector(scanService, selectIsLocationDenied);
|
|
|
|
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');
|
|
}
|
|
|
|
return {
|
|
locationError,
|
|
vcLabel: useSelector(settingsService, selectVcLabel),
|
|
|
|
isEmpty: !shareableVcs.length,
|
|
isLocationDisabled,
|
|
isLocationDenied,
|
|
isScanning: useSelector(scanService, selectIsScanning),
|
|
|
|
LOCATION_REQUEST: () => scanService.send(ScanEvents.LOCATION_REQUEST()),
|
|
SCAN: (qrCode: string) => scanService.send(ScanEvents.SCAN(qrCode)),
|
|
};
|
|
}
|