Skip to content

Commit

Permalink
[FIX] Prompt camera permission (#4429)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Antunes authored Jun 8, 2022
1 parent 831cd5d commit d47bef4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 15 additions & 3 deletions app/components/Views/QRScanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import {
StyleSheet,
Alert,
} from 'react-native';
import { useSelector } from 'react-redux';
import { RNCamera } from 'react-native-camera';
import { colors as importedColors } from '../../../styles/common';
import Icon from 'react-native-vector-icons/Ionicons';
import { parse } from 'eth-url-parser';
import { colors as importedColors } from '../../../styles/common';
import { isValidAddress } from 'ethereumjs-util';
import { strings } from '../../../../locales/i18n';
import SharedDeeplinkManager from '../../../core/DeeplinkManager';
Expand All @@ -26,7 +27,6 @@ import {
isValidMnemonic,
} from '../../../util/validators';
import Engine from '../../../core/Engine';
import { useSelector } from 'react-redux';

// TODO: This file needs typings
const styles = StyleSheet.create({
Expand Down Expand Up @@ -141,7 +141,7 @@ const QRScanner = ({ navigation, route }: Props) => {
return;
}

const { KeyringController } = Engine.context;
const { KeyringController } = Engine.context as any;
const isUnlocked = KeyringController.isUnlocked();

if (!isUnlocked) {
Expand Down Expand Up @@ -210,6 +210,17 @@ const QRScanner = ({ navigation, route }: Props) => {
[end, onStartScan, onScanSuccess, navigation, currentChainId],
);

const showCameraNotAuthorizedAlert = () =>
Alert.alert(
strings('qr_scanner.not_allowed_error_title'),
strings('qr_scanner.not_allowed_error_desc'),
[
{
text: strings('qr_scanner.ok'),
},
],
);

const onError = useCallback(
(error) => {
navigation.goBack();
Expand All @@ -225,6 +236,7 @@ const QRScanner = ({ navigation, route }: Props) => {
const onStatusChange = useCallback(
(event) => {
if (event.cameraStatus === 'NOT_AUTHORIZED') {
showCameraNotAuthorizedAlert();
navigation.goBack();
}
},
Expand Down
4 changes: 3 additions & 1 deletion locales/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,9 @@
"cancel": "Cancel",
"error": "Error",
"attempting_to_scan_with_wallet_locked": "Looks like you're trying to scan a QR code, you need to unlock your wallet to be able to use it.",
"attempting_sync_from_wallet_error": "Looks like you're trying to sync with the extension. In order to do so, you will need to erase your current wallet. \n\nOnce you've erased or reinstalled a fresh version of the app, select the option to \"Sync with MetaMask Extension\". Important! Before erasing your wallet, make sure you've backed up your Secret Recovery Phrase."
"attempting_sync_from_wallet_error": "Looks like you're trying to sync with the extension. In order to do so, you will need to erase your current wallet. \n\nOnce you've erased or reinstalled a fresh version of the app, select the option to \"Sync with MetaMask Extension\". Important! Before erasing your wallet, make sure you've backed up your Secret Recovery Phrase.",
"not_allowed_error_title": "Enable camera access",
"not_allowed_error_desc": "Camera access needed to scan a QR code associated with an account address or a contract address"
},
"action_view": {
"cancel": "Cancel",
Expand Down

0 comments on commit d47bef4

Please sign in to comment.