diff --git a/App.tsx b/App.tsx index 4e2147c..3927687 100644 --- a/App.tsx +++ b/App.tsx @@ -8,7 +8,6 @@ import SignMessage from './components/SignMessage'; import HomeScreen from './components/HomeScreen'; import SignRequest from './components/SignRequest'; import InvalidPath from './components/InvalidPath'; -import QRScanner from './components/QRScanner'; import PairingModal from './components/PairingModal'; import SignModal from './components/SignModal'; import WalletConnect from './components/WalletConnect'; @@ -132,31 +131,22 @@ const App = (): React.JSX.Element => { title: 'Connect Wallet', }} /> - + - <> - - - + ); }; diff --git a/components/PairingModal.tsx b/components/PairingModal.tsx index 5d575a7..63bf114 100644 --- a/components/PairingModal.tsx +++ b/components/PairingModal.tsx @@ -2,17 +2,17 @@ import React from 'react'; import { Image, View, Modal } from 'react-native'; import { Button, Text } from 'react-native-paper'; +import { SessionTypes } from '@walletconnect/types'; +import { getSdkError } from '@walletconnect/utils'; + import { PairingModalProps } from '../types'; import styles from '../styles/stylesheet'; import { web3wallet } from '../utils/wallet-connect/WalletConnectUtils'; -import { SessionTypes } from '@walletconnect/types'; -import { getSdkError } from '@walletconnect/utils'; - const PairingModal = ({ visible, - currentEthAddresses, currentProposal, + currentEthAddresses, setCurrentProposal, setModalVisible, }: PairingModalProps) => { diff --git a/components/WalletConnect.tsx b/components/WalletConnect.tsx index 69fe4ae..67e6786 100644 --- a/components/WalletConnect.tsx +++ b/components/WalletConnect.tsx @@ -1,42 +1,102 @@ -import React, { useState } from 'react'; -import { View } from 'react-native'; -import { Button, TextInput } from 'react-native-paper'; +import React, { useEffect, useState } from 'react'; +import { AppState, View } from 'react-native'; +import { Button, Text, TextInput } from 'react-native-paper'; +import { + Camera, + useCameraDevice, + useCameraPermission, + useCodeScanner, +} from 'react-native-vision-camera'; -import { NativeStackNavigationProp } from '@react-navigation/native-stack'; import { useNavigation } from '@react-navigation/native'; +import { NativeStackNavigationProp } from '@react-navigation/native-stack'; import { web3WalletPair } from '../utils/wallet-connect/WalletConnectUtils'; import styles from '../styles/stylesheet'; import { StackParamsList } from '../types'; const WalletConnect = () => { - const [currentWCURI, setCurrentWCURI] = useState(''); - const navigation = useNavigation>(); + const { hasPermission, requestPermission } = useCameraPermission(); + const device = useCameraDevice('back'); + + const [currentWCURI, setCurrentWCURI] = useState(''); + const [isActive, setIsActive] = useState(AppState.currentState === 'active'); + const [isScanning, setScanning] = useState(true); + + const codeScanner = useCodeScanner({ + codeTypes: ['qr'], + onCodeScanned: codes => { + if (isScanning) { + codes.forEach(code => { + if (code.value) { + setCurrentWCURI(code.value); + setScanning(false); + } + }); + } + }, + }); + const pair = async () => { const pairing = await web3WalletPair({ uri: currentWCURI }); navigation.navigate('Laconic'); return pairing; }; + useEffect(() => { + const handleAppStateChange = (newState: string) => { + setIsActive(newState === 'active'); + }; + + AppState.addEventListener('change', handleAppStateChange); + + if (!hasPermission) { + requestPermission(); + } + }, [hasPermission, isActive, requestPermission]); + return ( - + {!hasPermission || !device ? ( + + {!hasPermission ? 'No Camera Permission!' : 'No Camera Selected!'} + + ) : ( + <> + + {isActive ? ( + + ) : ( + No Camera Selected! + )} + - - - + + + + + + + + + )} ); }; - export default WalletConnect; diff --git a/styles/stylesheet.js b/styles/stylesheet.js index 86313e1..fdf7338 100644 --- a/styles/stylesheet.js +++ b/styles/stylesheet.js @@ -191,6 +191,17 @@ const styles = StyleSheet.create({ paddingHorizontal: 10, marginVertical: 20, }, + cameraContainer: { + justifyContent: 'center', + alignItems: 'center', + }, + inputContainer: { + marginTop: 20, + }, + camera: { + width: 400, + height: 400, + }, }); export default styles; diff --git a/types.ts b/types.ts index 38dcc0c..36aed1b 100644 --- a/types.ts +++ b/types.ts @@ -7,7 +7,6 @@ export type StackParamsList = { | { network: string; address: string; message: string } | undefined; InvalidPath: undefined; - QRScanner: undefined; WalletConnect: undefined; };