mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-26 08:55:56 +01:00
Merge pull request #5499 from BlueWallet/ref-camera-permish
REF: camera permissions
This commit is contained in:
commit
28e7613616
3 changed files with 34 additions and 8 deletions
|
@ -190,6 +190,7 @@
|
|||
"input_done": "Done",
|
||||
"input_paste": "Paste",
|
||||
"input_total": "Total:",
|
||||
"permission_camera_message": "We need your permission to use your camera.",
|
||||
"psbt_sign": "Sign a transaction",
|
||||
"open_settings": "Open Settings",
|
||||
"permission_storage_later": "Ask me later",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React, { useState } from 'react';
|
||||
import { Image, View, TouchableOpacity, StatusBar, Platform, StyleSheet, TextInput, Alert } from 'react-native';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Image, View, TouchableOpacity, StatusBar, Platform, StyleSheet, TextInput, Alert, PermissionsAndroid } from 'react-native';
|
||||
import { CameraScreen } from 'react-native-camera-kit';
|
||||
import { Icon } from 'react-native-elements';
|
||||
import { launchImageLibrary } from 'react-native-image-picker';
|
||||
|
@ -93,6 +93,7 @@ const ScanQRCode = () => {
|
|||
const [backdoorText, setBackdoorText] = useState('');
|
||||
const [backdoorVisible, setBackdoorVisible] = useState(false);
|
||||
const [animatedQRCodeData, setAnimatedQRCodeData] = useState({});
|
||||
const [cameraStatus, setCameraStatus] = useState(false);
|
||||
const stylesHook = StyleSheet.create({
|
||||
openSettingsContainer: {
|
||||
backgroundColor: colors.brandingColor,
|
||||
|
@ -105,6 +106,30 @@ const ScanQRCode = () => {
|
|||
color: colors.foregroundColor,
|
||||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA, {
|
||||
title: '',
|
||||
message: loc.send.permission_camera_message,
|
||||
buttonNeutral: loc.send.permission_storage_later,
|
||||
buttonNegative: loc._.no,
|
||||
buttonPositive: loc._.yes,
|
||||
});
|
||||
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
|
||||
console.log('You can use the camera');
|
||||
setCameraStatus(true);
|
||||
} else {
|
||||
console.log('Camera permission denied');
|
||||
setCameraStatus(false);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(err);
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
|
||||
const HashIt = function (s) {
|
||||
return createHash('sha256').update(s).digest().toString('hex');
|
||||
};
|
||||
|
@ -297,9 +322,9 @@ const ScanQRCode = () => {
|
|||
) : (
|
||||
<View style={styles.root}>
|
||||
<StatusBar hidden />
|
||||
{isFocused && (
|
||||
{isFocused && cameraStatus ? (
|
||||
<CameraScreen scanBarcode onReadCode={event => onBarCodeRead({ data: event?.nativeEvent?.codeStringValue })} showFrame={false} />
|
||||
)}
|
||||
) : null}
|
||||
<TouchableOpacity accessibilityRole="button" accessibilityLabel={loc._.close} style={styles.closeTouch} onPress={dismiss}>
|
||||
<Image style={styles.closeImage} source={require('../../img/close-white.png')} />
|
||||
</TouchableOpacity>
|
||||
|
|
|
@ -25,7 +25,7 @@ describe('BlueWallet UI Tests - import Watch-only wallet (zpub)', () => {
|
|||
'zpub6rDWXE4wbwefeCrHWehXJheXnti5F9PbpamDUeB5eFbqaY89x3jq86JADBuXpnJnSvRVwqkaTnyMaZERUg4BpxD9V4tSZfKeYh1ozPdL1xK',
|
||||
'watchOnly',
|
||||
'Imported Watch-only',
|
||||
'0 BTC', // it used to be 0.00030666 till someone stole it from git history kek
|
||||
'0.0001 BTC',
|
||||
);
|
||||
await sleep(15000);
|
||||
|
||||
|
@ -36,7 +36,7 @@ describe('BlueWallet UI Tests - import Watch-only wallet (zpub)', () => {
|
|||
await element(by.text(`No, and don’t ask me again`)).tap();
|
||||
} catch (_) {}
|
||||
await expect(element(by.id('BitcoinAddressQRCodeContainer'))).toBeVisible();
|
||||
await expect(element(by.text('bc1qtc9zquvq7lgq87kzsgltvv4etwm9uxphfkvkay'))).toBeVisible();
|
||||
await expect(element(by.text('bc1q5vzs7ea3z5e2wt53mp97mfy927eu75l7ku4w2p'))).toBeVisible();
|
||||
await element(by.id('SetCustomAmountButton')).tap();
|
||||
await element(by.id('BitcoinAmountInput')).replaceText('1');
|
||||
await element(by.id('CustomAmountDescription')).typeText('Test');
|
||||
|
@ -45,7 +45,7 @@ describe('BlueWallet UI Tests - import Watch-only wallet (zpub)', () => {
|
|||
await sup('Test');
|
||||
await expect(element(by.id('BitcoinAddressQRCodeContainer'))).toBeVisible();
|
||||
|
||||
await expect(element(by.text('bitcoin:bc1qtc9zquvq7lgq87kzsgltvv4etwm9uxphfkvkay?amount=1&label=Test'))).toBeVisible();
|
||||
await expect(element(by.text('bitcoin:bc1q5vzs7ea3z5e2wt53mp97mfy927eu75l7ku4w2p?amount=1&label=Test'))).toBeVisible();
|
||||
await device.pressBack();
|
||||
|
||||
await element(by.id('SendButton')).tap();
|
||||
|
@ -87,7 +87,7 @@ describe('BlueWallet UI Tests - import Watch-only wallet (zpub)', () => {
|
|||
await device.pressBack();
|
||||
await device.pressBack();
|
||||
await device.pressBack();
|
||||
await helperDeleteWallet('Imported Watch-only');
|
||||
await helperDeleteWallet('Imported Watch-only', '10000');
|
||||
|
||||
process.env.TRAVIS && require('fs').writeFileSync(lockFile, '1');
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue