Files
inji-wallet/screens/Scan/ScanScreen.tsx
dhivya0413 769ed54bcf [INJI-195] Upgrade React native version to 0.71.8 (#824)
* 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>
2023-09-13 11:53:59 +05:30

189 lines
5.2 KiB
TypeScript

import React, {useEffect, useState} from 'react';
import {useTranslation} from 'react-i18next';
import {
ErrorMessageOverlay,
MessageOverlay,
} from '../../components/MessageOverlay';
import {QrScanner} from '../../components/QrScanner';
import {Button, Centered, Column, Text} from '../../components/ui';
import {Theme} from '../../components/ui/styleUtils';
import {QrLogin} from '../QrLogin/QrLogin';
import {useScanScreen} from './ScanScreenController';
import BluetoothStateManager from 'react-native-bluetooth-state-manager';
import {Linking, Platform} from 'react-native';
import {useNavigation, NavigationProp} from '@react-navigation/native';
import {MainBottomTabParamList} from '../../routes/main';
import {BOTTOM_TAB_ROUTES} from '../../routes/routesConstants';
export const ScanScreen: React.FC = () => {
type ScanScreenNavigation = NavigationProp<MainBottomTabParamList>;
const {t} = useTranslation('ScanScreen');
const controller = useScanScreen();
const navigation = useNavigation<ScanScreenNavigation>();
const [isBluetoothOn, setIsBluetoothOn] = useState(false);
useEffect(() => {
(async () => {
await BluetoothStateManager.onStateChange(state => {
if (state === 'PoweredOff') {
setIsBluetoothOn(false);
} else {
setIsBluetoothOn(true);
}
}, true);
})();
}, [isBluetoothOn]);
// TODO(kludge): skip running this hook on every render
useEffect(() => {
if (controller.isStartPermissionCheck && !controller.isEmpty)
controller.START_PERMISSION_CHECK();
});
const openSettings = () => {
Linking.openSettings();
};
function noShareableVcText() {
return (
<Text align="center" color={Theme.Colors.errorMessage} margin="0 10">
{t('noShareableVcs')}
</Text>
);
}
function bluetoothIsOffText() {
return (
<Text align="center" color={Theme.Colors.errorMessage} margin="0 10">
{t(
Platform.OS === 'ios' ? 'bluetoothStateIos' : 'bluetoothStateAndroid',
)}
</Text>
);
}
function allowBluetoothPermissionComponent() {
return (
<Column padding="24" fill align="space-between">
<Centered fill>
<Text align="center" color={Theme.Colors.errorMessage}>
{t('enableBluetoothMessage')}
</Text>
</Centered>
<Button
title={t('enableBluetoothButtonText')}
onPress={openSettings}></Button>
</Column>
);
}
function allowNearbyDevicesPermissionComponent() {
return (
<Column padding="24" fill align="space-between">
<Centered fill>
<Text align="center" color={Theme.Colors.errorMessage}>
{t('errors.nearbyDevicesPermissionDenied.message')}
</Text>
</Centered>
<Button
title={t('errors.nearbyDevicesPermissionDenied.button')}
onPress={openSettings}></Button>
</Column>
);
}
function allowLocationComponent() {
return (
<Column padding="24" fill align="space-between">
<Centered fill>
<Text align="center" color={Theme.Colors.errorMessage}>
{controller.locationError.message}
</Text>
</Centered>
<Button
title={controller.locationError.button}
onPress={controller.LOCATION_REQUEST}
/>
</Column>
);
}
function qrScannerComponent() {
return (
<Column crossAlign="center" margin="0 0 0 -6">
<QrScanner onQrFound={controller.SCAN} title={t('scanningGuide')} />
</Column>
);
}
function loadQRScanner() {
if (controller.isEmpty) {
return noShareableVcText();
}
if (controller.isNearByDevicesPermissionDenied) {
return allowNearbyDevicesPermissionComponent();
}
if (
(controller.isBluetoothDenied || !isBluetoothOn) &&
controller.isReadyForBluetoothStateCheck
) {
return bluetoothIsOffText();
}
if (controller.isLocationDisabled || controller.isLocationDenied) {
return allowLocationComponent();
}
if (controller.isBluetoothPermissionDenied) {
return allowBluetoothPermissionComponent();
}
if (controller.isScanning) {
return qrScannerComponent();
}
}
function displayStorageLimitReachedError(): React.ReactNode {
return (
!controller.isEmpty && (
<ErrorMessageOverlay
isVisible={
controller.isMinimumStorageRequiredForAuditEntryLimitReached
}
translationPath={'ScanScreen'}
error="errors.storageLimitReached"
onDismiss={() => navigation.navigate(BOTTOM_TAB_ROUTES.home)}
/>
)
);
}
return (
<Column
fill
padding="24 0"
backgroundColor={Theme.Colors.whiteBackgroundColor}>
<Centered
fill
align="space-evenly"
backgroundColor={Theme.Colors.whiteBackgroundColor}>
{loadQRScanner()}
{controller.isQrLogin && (
<QrLogin
isVisible={controller.isQrLogin}
service={controller.isQrRef}
/>
)}
<MessageOverlay
isVisible={controller.isQrLoginstoring}
title={t('loading')}
progress
/>
</Centered>
{displayStorageLimitReachedError()}
</Column>
);
};