forked from cerc-io/laconic-wallet
Remove QRScanner.tsx (#45)
* Remove QRScanner component * Remove unused variables --------- Co-authored-by: Adw8 <adwait@deepstacksoft.com>
This commit is contained in:
parent
9ab8c2ce4f
commit
d7ebdd6063
@ -1,107 +0,0 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
|
||||||
import { Alert, StyleSheet, View, AppState } from 'react-native';
|
|
||||||
import { Text, Button } from 'react-native-paper';
|
|
||||||
import {
|
|
||||||
Camera,
|
|
||||||
useCameraDevice,
|
|
||||||
useCameraPermission,
|
|
||||||
useCodeScanner,
|
|
||||||
} from 'react-native-vision-camera';
|
|
||||||
|
|
||||||
import { useNavigation } from '@react-navigation/native';
|
|
||||||
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
|
||||||
|
|
||||||
import { StackParamsList } from '../types';
|
|
||||||
|
|
||||||
const QRScanner = () => {
|
|
||||||
const navigation =
|
|
||||||
useNavigation<NativeStackNavigationProp<StackParamsList>>();
|
|
||||||
|
|
||||||
const { hasPermission, requestPermission } = useCameraPermission();
|
|
||||||
|
|
||||||
const [isActive, setIsActive] = useState(AppState.currentState === 'active');
|
|
||||||
const device = useCameraDevice('back');
|
|
||||||
const [isScanning, setScanning] = useState(true);
|
|
||||||
const codeScanner = useCodeScanner({
|
|
||||||
codeTypes: ['qr'],
|
|
||||||
onCodeScanned: codes => {
|
|
||||||
if (isScanning) {
|
|
||||||
codes.forEach(code => {
|
|
||||||
if (code.value) {
|
|
||||||
Alert.alert(`Scanned: ${code.value}`, undefined, [
|
|
||||||
{
|
|
||||||
text: 'OK',
|
|
||||||
onPress: () => {
|
|
||||||
navigation.navigate('Laconic');
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
setScanning(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const handleAppStateChange = (newState: string) => {
|
|
||||||
setIsActive(newState === 'active');
|
|
||||||
};
|
|
||||||
|
|
||||||
AppState.addEventListener('change', handleAppStateChange);
|
|
||||||
|
|
||||||
if (!hasPermission) {
|
|
||||||
requestPermission();
|
|
||||||
}
|
|
||||||
}, [hasPermission, isActive, requestPermission]);
|
|
||||||
|
|
||||||
if (!hasPermission) {
|
|
||||||
return (
|
|
||||||
<View style={styles.container}>
|
|
||||||
<Text>No Camera Permission!</Text>
|
|
||||||
<Button onPress={() => requestPermission()}>Request Permission</Button>
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!device) {
|
|
||||||
return (
|
|
||||||
<View style={styles.container}>
|
|
||||||
<Text>No Camera Selected!</Text>
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View style={styles.container}>
|
|
||||||
{isActive ? (
|
|
||||||
<Camera
|
|
||||||
style={styles.camera}
|
|
||||||
device={device}
|
|
||||||
isActive={isActive}
|
|
||||||
codeScanner={codeScanner}
|
|
||||||
video={false}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<Text>No Camera Selected!</Text>
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
container: {
|
|
||||||
flex: 1,
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
},
|
|
||||||
camera: {
|
|
||||||
width: 400,
|
|
||||||
height: 500,
|
|
||||||
borderRadius: 50,
|
|
||||||
overflow: 'hidden',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default QRScanner;
|
|
@ -7,18 +7,10 @@ import { Web3Wallet, IWeb3Wallet } from '@walletconnect/web3wallet';
|
|||||||
|
|
||||||
export let web3wallet: IWeb3Wallet;
|
export let web3wallet: IWeb3Wallet;
|
||||||
export let core: ICore;
|
export let core: ICore;
|
||||||
export let currentETHAddresses: string[];
|
|
||||||
export let currentCosmosAddresses: string[];
|
|
||||||
|
|
||||||
import { useState, useCallback, useEffect } from 'react';
|
import { useState, useCallback, useEffect } from 'react';
|
||||||
import { retrieveAccounts } from '../accounts';
|
|
||||||
|
|
||||||
export async function createWeb3Wallet() {
|
export async function createWeb3Wallet() {
|
||||||
const { ethLoadedAccounts } = await retrieveAccounts();
|
|
||||||
currentETHAddresses = ethLoadedAccounts
|
|
||||||
? ethLoadedAccounts.map(ethAccount => ethAccount.address)
|
|
||||||
: [];
|
|
||||||
|
|
||||||
// TODO: Move to dotenv
|
// TODO: Move to dotenv
|
||||||
const ENV_PROJECT_ID = 'c97365bf9f06d12a7488de36240b0ff4';
|
const ENV_PROJECT_ID = 'c97365bf9f06d12a7488de36240b0ff4';
|
||||||
const core = new Core({
|
const core = new Core({
|
||||||
|
Loading…
Reference in New Issue
Block a user