let BlueApp = require('../../BlueApp'); import React from 'react'; import { Text, ActivityIndicator, Button, View, TouchableOpacity, } from 'react-native'; import { Camera, Permissions } from 'expo'; import { AppStorage, LegacyWallet, SegwitP2SHWallet } from '../../class'; import Ionicons from 'react-native-vector-icons/Ionicons'; let EV = require('../../events'); export default class CameraExample extends React.Component { static navigationOptions = { tabBarLabel: 'Wallets', tabBarIcon: ({ tintColor, focused }) => ( ), }; state = { isLoading: false, hasCameraPermission: null, type: Camera.Constants.Type.back, }; async onBarCodeRead(ret) { for (let w of BlueApp.wallets) { // lookig for duplicates if (w.getSecret() === ret.data) { return; // duplicate, not adding } } let newWallet = new SegwitP2SHWallet(); newWallet.setSecret(ret.data); if (newWallet.getAddress() === false) return; // bad WIF this.setState( { isLoading: true, }, async () => { newWallet.setLabel('New SegWit'); BlueApp.wallets.push(newWallet); await BlueApp.saveToDisk(); this.props.navigation.navigate('WalletsList'); EV(EV.enum.WALLETS_COUNT_CHANGED); alert( 'Imported WIF ' + ret.data + ' with address ' + newWallet.getAddress(), ); }, ); } // end async componentWillMount() { const { status } = await Permissions.askAsync(Permissions.CAMERA); this.setState({ hasCameraPermission: status === 'granted', onCameraReady: function() { alert('onCameraReady'); }, barCodeTypes: [Camera.Constants.BarCodeType.qr], }); } render() { if (this.state.isLoading) { return ( ); } const { hasCameraPermission } = this.state; if (hasCameraPermission === null) { return ; } else if (hasCameraPermission === false) { return No access to camera; } else { return ( { this.setState({ type: this.state.type === Camera.Constants.Type.back ? Camera.Constants.Type.front : Camera.Constants.Type.back, }); }} >