diff --git a/machines/openIdBle/request.ts b/machines/openIdBle/request.ts index 52dd8706..8859eae9 100644 --- a/machines/openIdBle/request.ts +++ b/machines/openIdBle/request.ts @@ -2,17 +2,10 @@ import SmartshareReactNative from '@idpass/smartshare-react-native'; import OpenIdBle from 'react-native-openid4vp-ble'; import uuid from 'react-native-uuid'; import BluetoothStateManager from 'react-native-bluetooth-state-manager'; +import { EmitterSubscription, Linking, Platform } from 'react-native'; import { - EmitterSubscription, - Linking, - Platform, - PermissionsAndroid, -} from 'react-native'; -import { - check, checkMultiple, PERMISSIONS, - request, requestMultiple, RESULTS, } from 'react-native-permissions'; @@ -62,6 +55,7 @@ const model = createModel( ? 'ONLINE' : 'OFFLINE') as SharingProtocol, receiveLogType: '' as ActivityLogType, + readyForBluetoothStateCheck: false, }, { events: { @@ -156,6 +150,7 @@ export const requestMachine = }, on: { NEARBY_ENABLED: { + actions: 'setReadyForBluetoothStateCheck', target: '#request.checkingBluetoothService', }, NEARBY_DISABLED: { @@ -565,6 +560,10 @@ export const requestMachine = receiverInfo: (_context, event) => event.info, }), + setReadyForBluetoothStateCheck: model.assign({ + readyForBluetoothStateCheck: () => true, + }), + generateConnectionParams: assign({ connectionParams: (context) => { if (context.sharingProtocol === 'OFFLINE') { @@ -993,6 +992,10 @@ export function selectConnectionParams(state: State) { return state.context.connectionParams; } +export function selectReadyForBluetoothStateCheck(state: State) { + return state.context.readyForBluetoothStateCheck; +} + export function selectIncomingVc(state: State) { return state.context.incomingVc; } diff --git a/machines/openIdBle/scan.ts b/machines/openIdBle/scan.ts index 1fc6a0a6..1920aa67 100644 --- a/machines/openIdBle/scan.ts +++ b/machines/openIdBle/scan.ts @@ -75,7 +75,7 @@ const model = createModel( shareLogType: '' as ActivityLogType, QrLoginRef: {} as ActorRefFrom, linkCode: '', - requestCount: 0, + readyForBluetoothStateCheck: false, }, { events: { @@ -212,6 +212,7 @@ export const scanMachine = }, on: { BLUETOOTH_ALLOWED: { + actions: 'setReadyForBluetoothStateCheck', target: 'enabled', }, BLUETOOTH_DENIED: { @@ -726,6 +727,10 @@ export const scanMachine = receiverInfo: (_context, event) => event.receiverInfo, }), + setReadyForBluetoothStateCheck: model.assign({ + readyForBluetoothStateCheck: () => true, + }), + setReason: model.assign({ reason: (_context, event) => event.reason, }), @@ -1220,6 +1225,9 @@ export function selectReceiverInfo(state: State) { export function selectReason(state: State) { return state.context.reason; } +export function selectReadyForBluetoothStateCheck(state: State) { + return state.context.readyForBluetoothStateCheck; +} export function selectVcName(state: State) { return state.context.vcName; diff --git a/screens/Request/RequestScreen.tsx b/screens/Request/RequestScreen.tsx index a64710dd..6fdc1aab 100644 --- a/screens/Request/RequestScreen.tsx +++ b/screens/Request/RequestScreen.tsx @@ -41,7 +41,10 @@ export const RequestScreen: React.FC = () => { if (controller.isNearByDevicesPermissionDenied) { return ; } - if (controller.isBluetoothDenied || !isBluetoothOn) { + if ( + (controller.isBluetoothDenied || !isBluetoothOn) && + controller.isReadyForBluetoothStateCheck + ) { return ; } if ( diff --git a/screens/Request/RequestScreenController.ts b/screens/Request/RequestScreenController.ts index 71221808..7e10e541 100644 --- a/screens/Request/RequestScreenController.ts +++ b/screens/Request/RequestScreenController.ts @@ -17,7 +17,10 @@ import { selectIsCancelling, selectIsOffline, } from '../../machines/request'; -import { selectIsNearByDevicesPermissionDenied } from '../../machines/openIdBle/request'; +import { + selectIsNearByDevicesPermissionDenied, + selectReadyForBluetoothStateCheck, +} from '../../machines/openIdBle/request'; import { selectVcLabel } from '../../machines/settings'; import { GlobalContext } from '../../shared/GlobalContext'; import BluetoothStateManager from 'react-native-bluetooth-state-manager'; @@ -30,6 +33,10 @@ export function useRequestScreen() { const requestService = appService.children.get('request'); const isActive = useSelector(appService, selectIsActive); const isFocused = useSelector(appService, selectIsFocused); + const isReadyForBluetoothStateCheck = useSelector( + requestService, + selectReadyForBluetoothStateCheck + ); const isBluetoothDenied = useSelector( requestService, selectIsBluetoothDenied @@ -98,6 +105,7 @@ export function useRequestScreen() { isWaitingForVc, isBluetoothDenied, isNearByDevicesPermissionDenied, + isReadyForBluetoothStateCheck, isCheckingBluetoothService: useSelector( requestService, selectIsCheckingBluetoothService diff --git a/screens/Scan/ScanScreen.tsx b/screens/Scan/ScanScreen.tsx index f0b4b54c..d3a761e3 100644 --- a/screens/Scan/ScanScreen.tsx +++ b/screens/Scan/ScanScreen.tsx @@ -116,7 +116,10 @@ export const ScanScreen: React.FC = () => { if (controller.isNearByDevicesPermissionDenied) { return allowNearbyDevicesPermissionComponent(); } - if (controller.isBluetoothDenied || !isBluetoothOn) { + if ( + (controller.isBluetoothDenied || !isBluetoothOn) && + controller.isReadyForBluetoothStateCheck + ) { return bluetoothIsOffText(); } if (controller.isLocationDisabled || controller.isLocationDenied) { diff --git a/screens/Scan/ScanScreenController.ts b/screens/Scan/ScanScreenController.ts index cba5e104..a43a5a57 100644 --- a/screens/Scan/ScanScreenController.ts +++ b/screens/Scan/ScanScreenController.ts @@ -18,6 +18,7 @@ import { selectIsNearByDevicesPermissionDenied, selectIsBluetoothDenied, selectIsStartPermissionCheck, + selectReadyForBluetoothStateCheck, } from '../../machines/openIdBle/scan'; import { ScanEvents as ScanEvent } from '../../machines/openIdBle/scan'; @@ -31,6 +32,10 @@ export function useScanScreen() { const isLocationDisabled = useSelector(scanService, selectIsLocationDisabled); const isLocationDenied = useSelector(scanService, selectIsLocationDenied); + const isReadyForBluetoothStateCheck = useSelector( + scanService, + selectReadyForBluetoothStateCheck + ); const isStartPermissionCheck = useSelector( scanService, selectIsStartPermissionCheck @@ -73,6 +78,7 @@ export function useScanScreen() { isLocationDenied, isBluetoothDenied, isStartPermissionCheck, + isReadyForBluetoothStateCheck, isScanning: useSelector(scanService, selectIsScanning), isQrLogin: useSelector(scanService, selectIsShowQrLogin), isQrLoginstoring: useSelector(scanService, selectIsQrLoginStoring),