Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Prompt camera permission #4429

Merged
merged 9 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'),
Fatxx marked this conversation as resolved.
Show resolved Hide resolved
},
],
);

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