mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 01:40:12 +01:00
Merge pull request #6612 from BlueWallet/qr
REF: Use existing nav ref for scanQR helper #6601
This commit is contained in:
commit
555819a9b0
@ -1,7 +1,5 @@
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
import React from 'react';
|
||||
import { Image, Keyboard, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native';
|
||||
|
||||
import { scanQrHelper } from '../helpers/scan-qr';
|
||||
import loc from '../loc';
|
||||
import { useTheme } from './themes';
|
||||
@ -51,7 +49,6 @@ const AddressInput = ({
|
||||
keyboardType = 'default',
|
||||
}: AddressInputProps) => {
|
||||
const { colors } = useTheme();
|
||||
const { navigate } = useNavigation();
|
||||
const stylesHook = StyleSheet.create({
|
||||
root: {
|
||||
borderColor: colors.formBorder,
|
||||
@ -77,7 +74,7 @@ const AddressInput = ({
|
||||
case actionKeys.ScanQR:
|
||||
scanButtonTapped();
|
||||
if (launchedBy) {
|
||||
scanQrHelper(navigate, launchedBy)
|
||||
scanQrHelper(launchedBy)
|
||||
.then(value => onBarScanned({ data: value }))
|
||||
.catch(error => {
|
||||
presentAlert({ message: error.message });
|
||||
@ -145,7 +142,7 @@ const AddressInput = ({
|
||||
await scanButtonTapped();
|
||||
Keyboard.dismiss();
|
||||
// @ts-ignore: Fix later
|
||||
scanQrHelper(navigate, launchedBy).then(onBarScanned);
|
||||
scanQrHelper(launchedBy).then(onBarScanned);
|
||||
}}
|
||||
accessibilityRole="button"
|
||||
style={[styles.scan, stylesHook.scan]}
|
||||
|
@ -1,23 +1,17 @@
|
||||
import { Platform } from 'react-native';
|
||||
import { check, request, PERMISSIONS, RESULTS } from 'react-native-permissions';
|
||||
|
||||
import { navigationRef } from '../NavigationService';
|
||||
/**
|
||||
* Helper function that navigates to ScanQR screen, and returns promise that will resolve with the result of a scan,
|
||||
* and then navigates back. If QRCode scan was closed, promise resolves to null.
|
||||
*
|
||||
* @param navigateFunc {function}
|
||||
* @param currentScreenName {string}
|
||||
* @param showFileImportButton {boolean}
|
||||
*
|
||||
* @param onDismiss {function} - if camera is closed via X button it gets triggered
|
||||
* @return {Promise<string>}
|
||||
*/
|
||||
function scanQrHelper(
|
||||
navigateFunc: (scr: string | any, params?: any) => void,
|
||||
currentScreenName: string,
|
||||
showFileImportButton = true,
|
||||
onDismiss?: () => void,
|
||||
): Promise<string | null> {
|
||||
function scanQrHelper(currentScreenName: string, showFileImportButton = true, onDismiss?: () => void): Promise<string | null> {
|
||||
return requestCameraAuthorization().then(() => {
|
||||
return new Promise(resolve => {
|
||||
const params = {
|
||||
@ -28,10 +22,10 @@ function scanQrHelper(
|
||||
|
||||
params.onBarScanned = function (data: any) {
|
||||
setTimeout(() => resolve(data.data || data), 1);
|
||||
navigateFunc({ name: currentScreenName, params: {}, merge: true });
|
||||
navigationRef.navigate({ name: currentScreenName, params: {}, merge: true });
|
||||
};
|
||||
|
||||
navigateFunc('ScanQRCodeRoot', {
|
||||
navigationRef.navigate('ScanQRCodeRoot', {
|
||||
screen: 'ScanQRCode',
|
||||
params,
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useNavigation, useRoute } from '@react-navigation/native';
|
||||
import * as bitcoin from 'bitcoinjs-lib';
|
||||
import React, { useState } from 'react';
|
||||
import { useRoute } from '@react-navigation/native';
|
||||
import * as bitcoin from 'bitcoinjs-lib';
|
||||
import { ActivityIndicator, Keyboard, KeyboardAvoidingView, Linking, Platform, StyleSheet, TextInput, View } from 'react-native';
|
||||
|
||||
import * as BlueElectrum from '../../blue_modules/BlueElectrum';
|
||||
@ -37,7 +37,6 @@ interface SuccessScreenProps {
|
||||
|
||||
const Broadcast: React.FC = () => {
|
||||
const { name } = useRoute();
|
||||
const { navigate } = useNavigation();
|
||||
const [tx, setTx] = useState<string | undefined>();
|
||||
const [txHex, setTxHex] = useState<string | undefined>();
|
||||
const { colors } = useTheme();
|
||||
@ -83,7 +82,7 @@ const Broadcast: React.FC = () => {
|
||||
};
|
||||
|
||||
const handleQRScan = async () => {
|
||||
const scannedData = await scanQrHelper(navigate, name);
|
||||
const scannedData = await scanQrHelper(name);
|
||||
if (!scannedData) return;
|
||||
|
||||
if (scannedData.indexOf('+') === -1 && scannedData.indexOf('=') === -1 && scannedData.indexOf('=') === -1) {
|
||||
|
@ -857,7 +857,7 @@ const SendDetails = () => {
|
||||
setIsLoading(true);
|
||||
setOptionsVisible(false);
|
||||
await new Promise(resolve => setTimeout(resolve, 100)); // sleep for animations
|
||||
const scannedData = await scanQrHelper(navigation.navigate, name);
|
||||
const scannedData = await scanQrHelper(name);
|
||||
if (!scannedData) return setIsLoading(false);
|
||||
|
||||
let tx;
|
||||
|
@ -60,7 +60,7 @@ const PsbtMultisigQRCode = () => {
|
||||
};
|
||||
|
||||
const openScanner = async () => {
|
||||
const scanned = await scanQrHelper(navigate, name, true);
|
||||
const scanned = await scanQrHelper(name, true);
|
||||
onBarScanned({ data: scanned });
|
||||
};
|
||||
|
||||
|
@ -36,7 +36,6 @@ import ListItem from '../../components/ListItem';
|
||||
import { BlueCurrentTheme } from '../../components/themes';
|
||||
import { scanQrHelper } from '../../helpers/scan-qr';
|
||||
import loc from '../../loc';
|
||||
import { navigationRef } from '../../NavigationService';
|
||||
|
||||
export default class ElectrumSettings extends Component {
|
||||
static contextType = BlueStorageContext;
|
||||
@ -225,7 +224,7 @@ export default class ElectrumSettings extends Component {
|
||||
};
|
||||
|
||||
importScan = async () => {
|
||||
const scanned = await scanQrHelper(navigationRef.navigate, 'ElectrumSettings', true);
|
||||
const scanned = await scanQrHelper('ElectrumSettings', true);
|
||||
this.onBarScanned(scanned);
|
||||
};
|
||||
|
||||
|
@ -51,7 +51,6 @@ import { useBiometrics } from '../../hooks/useBiometrics';
|
||||
import { useExtendedNavigation } from '../../hooks/useExtendedNavigation';
|
||||
import usePrivacy from '../../hooks/usePrivacy';
|
||||
import loc from '../../loc';
|
||||
import * as NavigationService from '../../NavigationService';
|
||||
import ActionSheet from '../ActionSheet';
|
||||
|
||||
const ViewEditMultisigCosigners: React.FC = () => {
|
||||
@ -513,7 +512,7 @@ const ViewEditMultisigCosigners: React.FC = () => {
|
||||
|
||||
const scanOrOpenFile = async () => {
|
||||
setIsProvideMnemonicsModalVisible(false);
|
||||
const scanned = await scanQrHelper(NavigationService.navigate, route.name, true);
|
||||
const scanned = await scanQrHelper(route.name, true);
|
||||
setImportText(String(scanned));
|
||||
setIsProvideMnemonicsModalVisible(true);
|
||||
};
|
||||
|
@ -318,7 +318,7 @@ const WalletsList: React.FC = () => {
|
||||
};
|
||||
|
||||
const onScanButtonPressed = () => {
|
||||
scanQrHelper(navigate, routeName).then(onBarScanned);
|
||||
scanQrHelper(routeName).then(onBarScanned);
|
||||
};
|
||||
|
||||
const onBarScanned = (value: any) => {
|
||||
@ -364,7 +364,7 @@ const WalletsList: React.FC = () => {
|
||||
});
|
||||
break;
|
||||
case 2:
|
||||
scanQrHelper(navigate, routeName, true).then(data => onBarScanned(data));
|
||||
scanQrHelper(routeName, true).then(data => onBarScanned(data));
|
||||
break;
|
||||
case 3:
|
||||
if (!isClipboardEmpty) {
|
||||
|
@ -461,7 +461,7 @@ const WalletsAddMultisigStep2 = () => {
|
||||
const scanOrOpenFile = () => {
|
||||
setIsProvideMnemonicsModalVisible(false);
|
||||
InteractionManager.runAfterInteractions(async () => {
|
||||
const scanned = await scanQrHelper(navigation.navigate, name, true);
|
||||
const scanned = await scanQrHelper(name, true);
|
||||
onBarScanned({ data: scanned });
|
||||
});
|
||||
};
|
||||
|
@ -409,7 +409,7 @@ const WalletTransactions = ({ navigation }) => {
|
||||
choosePhoto();
|
||||
break;
|
||||
case 2:
|
||||
scanQrHelper(navigate, name, true).then(data => onBarCodeRead(data));
|
||||
scanQrHelper(name, true).then(data => onBarCodeRead(data));
|
||||
break;
|
||||
case 3:
|
||||
if (!isClipboardEmpty) {
|
||||
|
Loading…
Reference in New Issue
Block a user