From 6c31e7d4786eb6b7d93196c3f553d1d13f67d5b0 Mon Sep 17 00:00:00 2001 From: marcosrdz Date: Sun, 6 Sep 2020 02:35:04 -0400 Subject: [PATCH] ADD: If Camera not authorized on Desktop, show Alert. --- BlueComponents.js | 5 +++- screen/send/ScanQRCode.js | 38 ++++++++++++++++++++++----- screen/send/psbtWithHardwareWallet.js | 3 +++ screen/wallets/import.js | 3 +++ screen/wallets/list.js | 3 +++ 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/BlueComponents.js b/BlueComponents.js index 7d4f5425f..4599faa0c 100644 --- a/BlueComponents.js +++ b/BlueComponents.js @@ -46,6 +46,7 @@ import { BlueCurrentTheme } from './components/themes'; import loc, { formatBalance, formatBalanceWithoutSuffix, formatBalancePlain, removeTrailingZeros, transactionTimeToReadable } from './loc'; import AsyncStorage from '@react-native-community/async-storage'; import Lnurl from './class/lnurl'; +import ScanQRCode from './screen/send/ScanQRCode'; /** @type {AppStorage} */ const BlueApp = require('./BlueApp'); const { height, width } = Dimensions.get('window'); @@ -2095,6 +2096,8 @@ export class BlueAddressInput extends Component { alert(loc.send.qr_error_no_qrcode); } }); + } else if (response.error) { + ScanQRCode.presentCameraNotAuthorizedAlert(response.error); } }, ); @@ -2105,7 +2108,7 @@ export class BlueAddressInput extends Component { }; showActionSheet = async () => { - const isClipboardEmpty = (await Clipboard.getString()).replace(' ', '').length === 0; + const isClipboardEmpty = (await Clipboard.getString()).trim().length === 0; let copyFromClipboardIndex; if (Platform.OS === 'ios') { const options = [loc._.cancel, loc.wallets.list_long_choose, isDesktop ? loc.wallets.take_photo : loc.wallets.list_long_scan]; diff --git a/screen/send/ScanQRCode.js b/screen/send/ScanQRCode.js index 5b60b2e9f..fce418da4 100644 --- a/screen/send/ScanQRCode.js +++ b/screen/send/ScanQRCode.js @@ -1,6 +1,6 @@ /* global alert */ import React, { useState } from 'react'; -import { Image, View, TouchableOpacity, StatusBar, Platform, StyleSheet, Linking } from 'react-native'; +import { Image, View, TouchableOpacity, StatusBar, Platform, StyleSheet, Linking, Alert } from 'react-native'; import { RNCamera } from 'react-native-camera'; import { Icon } from 'react-native-elements'; import ImagePicker from 'react-native-image-picker'; @@ -9,8 +9,10 @@ import DocumentPicker from 'react-native-document-picker'; import RNFS from 'react-native-fs'; import loc from '../../loc'; import { BlueLoadingHook, BlueTextHooks, BlueButtonHook, BlueSpacing40 } from '../../BlueComponents'; +import { getSystemName } from 'react-native-device-info'; const LocalQRCode = require('@remobile/react-native-qrcode-local-image'); const createHash = require('create-hash'); +const isDesktop = getSystemName() === 'Mac OS X'; const styles = StyleSheet.create({ root: { @@ -169,10 +171,6 @@ const ScanQRCode = () => { setCameraStatus(event.cameraStatus); }; - const handleOpenSettingsTapped = () => { - Linking.openSettings(); - }; - return isLoading ? ( @@ -199,7 +197,7 @@ const ScanQRCode = () => { {loc.send.permission_camera_message} - + )} @@ -217,6 +215,34 @@ const ScanQRCode = () => { ); }; +ScanQRCode.openPrivacyDesktopSettings = () => { + if (isDesktop) { + Linking.openURL('x-apple.systempreferences:com.apple.preference.security?Privacy_Camera'); + } else { + Linking.openSettings(); + } +}; + +ScanQRCode.presentCameraNotAuthorizedAlert = error => { + Alert.alert( + loc.errors.error, + error, + [ + { + text: loc.send.open_settings, + onPress: ScanQRCode.openPrivacyDesktopSettings, + style: 'default', + }, + { + text: loc._.ok, + onPress: () => {}, + style: 'cancel', + }, + ], + { cancelable: true }, + ); +}; + ScanQRCode.navigationOptions = { headerShown: false, }; diff --git a/screen/send/psbtWithHardwareWallet.js b/screen/send/psbtWithHardwareWallet.js index 673ae0ef9..7df01768d 100644 --- a/screen/send/psbtWithHardwareWallet.js +++ b/screen/send/psbtWithHardwareWallet.js @@ -36,6 +36,7 @@ import DocumentPicker from 'react-native-document-picker'; import { decodeUR, extractSingleWorkload } from 'bc-ur/dist'; import loc from '../../loc'; import { BlueCurrentTheme } from '../../components/themes'; +import ScanQRCode from './ScanQRCode'; const EV = require('../../blue_modules/events'); const BlueElectrum = require('../../blue_modules/BlueElectrum'); /** @type {AppStorage} */ @@ -356,6 +357,8 @@ export default class PsbtWithHardwareWallet extends Component { alert(loc.send.qr_error_no_qrcode); } }); + } else if (response.error) { + ScanQRCode.presentCameraNotAuthorizedAlert(response.error); } }, ); diff --git a/screen/wallets/import.js b/screen/wallets/import.js index 537b85a43..4d8a79888 100644 --- a/screen/wallets/import.js +++ b/screen/wallets/import.js @@ -23,6 +23,7 @@ import loc from '../../loc'; import { getSystemName } from 'react-native-device-info'; import RNFS from 'react-native-fs'; import DocumentPicker from 'react-native-document-picker'; +import ScanQRCode from '../send/ScanQRCode'; const LocalQRCode = require('@remobile/react-native-qrcode-local-image'); const { width } = Dimensions.get('window'); const isDesktop = getSystemName() === 'Mac OS X'; @@ -147,6 +148,8 @@ const WalletsImport = () => { alert(loc.send.qr_error_no_qrcode); } }); + } else if (response.error) { + ScanQRCode.presentCameraNotAuthorizedAlert(response.error); } }, ); diff --git a/screen/wallets/list.js b/screen/wallets/list.js index 5b2624494..7606d4c22 100644 --- a/screen/wallets/list.js +++ b/screen/wallets/list.js @@ -25,6 +25,7 @@ import * as NavigationService from '../../NavigationService'; import loc from '../../loc'; import { BlueCurrentTheme } from '../../components/themes'; import { getSystemName } from 'react-native-device-info'; +import ScanQRCode from '../send/ScanQRCode'; const EV = require('../../blue_modules/events'); const A = require('../../blue_modules/analytics'); const BlueApp: AppStorage = require('../../BlueApp'); @@ -479,6 +480,8 @@ export default class WalletsList extends Component { alert(loc.send.qr_error_no_qrcode); } }); + } else if (response.error) { + ScanQRCode.presentCameraNotAuthorizedAlert(response.error); } }, );