FIX: weird import screen scan qr code behaviour

This commit is contained in:
Overtorment 2020-03-13 14:23:12 +00:00
parent b256f2d4f8
commit bdcc40c8e0
6 changed files with 24 additions and 7 deletions

View file

@ -2088,7 +2088,7 @@ export class BlueAddressInput extends Component {
<TouchableOpacity
disabled={this.props.isLoading}
onPress={() => {
NavigationService.navigate('ScanQrAddress', { onBarScanned: this.props.onBarScanned, launchedBy: this.props.launchedBy });
NavigationService.navigate('ScanQRCode', { onBarScanned: this.props.onBarScanned, launchedBy: this.props.launchedBy });
Keyboard.dismiss();
}}
style={{

View file

@ -35,7 +35,7 @@ import rbfCancel from './screen/transactions/RBFCancel';
import receiveDetails from './screen/receive/details';
import sendDetails from './screen/send/details';
import ScanQRCode from './screen/send/scanQrAddress';
import ScanQRCode from './screen/send/ScanQRCode';
import sendCreate from './screen/send/create';
import Confirm from './screen/send/confirm';
import PsbtWithHardwareWallet from './screen/send/psbtWithHardwareWallet';
@ -251,7 +251,7 @@ const HandleOffchainAndOnChainStackNavigator = createStackNavigator(
header: null,
},
},
ScanQrAddress: {
ScanQRCode: {
screen: ScanQRCode,
},
SendDetails: {
@ -322,7 +322,7 @@ const MainBottomTabs = createStackNavigator(
header: null,
},
},
ScanQrAddress: {
ScanQRCode: {
screen: ScanQRCode,
},
LappBrowser: {

View file

@ -209,7 +209,7 @@ export default class LNDCreateInvoice extends Component {
<TouchableOpacity
disabled={this.state.isLoading}
onPress={() => {
NavigationService.navigate('ScanQrAddress', {
NavigationService.navigate('ScanQRCode', {
onBarScanned: this.processLnurl,
launchedBy: this.props.navigation.state.routeName,
});

View file

@ -9,6 +9,7 @@ import { useNavigationParam, useNavigation } from 'react-navigation-hooks';
import DocumentPicker from 'react-native-document-picker';
import RNFS from 'react-native-fs';
const LocalQRCode = require('@remobile/react-native-qrcode-local-image');
const createHash = require('create-hash');
const ScanQRCode = ({
onBarScanned = useNavigationParam('onBarScanned'),
@ -21,7 +22,23 @@ const ScanQRCode = ({
const [isLoading, setIsLoading] = useState(false);
const { navigate, goBack } = useNavigation();
const scannedCache = {};
const HashIt = function(s) {
return createHash('sha256')
.update(s)
.digest()
.toString('hex');
};
const onBarCodeRead = ret => {
const h = HashIt(ret.data);
if (scannedCache[h]) {
// this QR was already scanned by this ScanQRCode, lets prevent firing duplicate callbacks
return;
}
scannedCache[h] = +new Date();
if (!isLoading && !cameraPreviewIsPaused) {
setIsLoading(true);
try {

View file

@ -120,7 +120,7 @@ const WalletsImport = () => {
<BlueButtonLink
title={loc.wallets.import.scan_qr}
onPress={() => {
navigate('ScanQrAddress', { launchedBy: 'ImportWallet', onBarScanned, showFileImportButton: true });
navigate('ScanQRCode', { launchedBy: 'ImportWallet', onBarScanned, showFileImportButton: true });
}}
/>
</View>

View file

@ -19,7 +19,7 @@ import PropTypes from 'prop-types';
import { PlaceholderWallet } from '../../class';
import WalletImport from '../../class/walletImport';
import Swiper from 'react-native-swiper';
import ScanQRCode from '../send/scanQrAddress';
import ScanQRCode from '../send/ScanQRCode';
import DeeplinkSchemaMatch from '../../class/deeplinkSchemaMatch';
let EV = require('../../events');
let A = require('../../analytics');