diff --git a/App.tsx b/App.tsx index 8f77788..0a5aa30 100644 --- a/App.tsx +++ b/App.tsx @@ -1,5 +1,6 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; -import { Snackbar } from 'react-native-paper'; +import { Button, Snackbar } from 'react-native-paper'; +import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import { SignClientTypes } from '@walletconnect/types'; import { useNavigation } from '@react-navigation/native'; @@ -13,6 +14,7 @@ import HomeScreen from './components/HomeScreen'; import SignRequest from './components/SignRequest'; import InvalidPath from './components/InvalidPath'; import PairingModal from './components/PairingModal'; +import AddSession from './components/AddSession'; import WalletConnect from './components/WalletConnect'; import { StackParamsList } from './types'; import useInitialization, { @@ -32,7 +34,6 @@ const App = (): React.JSX.Element => { useNavigation>(); const { accounts } = useAccounts(); - const { requestSession, setRequestSession } = useRequests(); const [modalVisible, setModalVisible] = useState(false); @@ -132,7 +133,23 @@ const App = (): React.JSX.Element => { name="WalletConnect" component={WalletConnect} options={{ - title: 'Connect Wallet', + title: 'WalletConnect Sessions', + headerRight: () => ( + + ), + }} + /> + + diff --git a/assets/WalletConnect-Icon-Blueberry.png b/assets/WalletConnect-Icon-Blueberry.png new file mode 100644 index 0000000..66625b2 Binary files /dev/null and b/assets/WalletConnect-Icon-Blueberry.png differ diff --git a/components/AddSession.tsx b/components/AddSession.tsx new file mode 100644 index 0000000..907a92b --- /dev/null +++ b/components/AddSession.tsx @@ -0,0 +1,118 @@ +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 { 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 AddSession = () => { + 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('WalletConnect'); + return pairing; + }; + // const disconnect = async () => { + // const activeSessions = await web3wallet.getActiveSessions(); + // const topic = Object.values(activeSessions)[0].topic; + // if (activeSessions) { + // await web3wallet.disconnectSession({ + // topic, + // reason: getSdkError('USER_DISCONNECTED'), + // }); + // navigation.navigate('Laconic'); + // return; + // } + // }; + 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 granted' + : 'No Camera Selected'} + + ) : ( + <> + + {isActive ? ( + + ) : ( + No Camera Selected! + )} + + + + Enter WalletConnect URI + + + + + + + + )} + + ); +}; +export default AddSession; diff --git a/components/HomeScreen.tsx b/components/HomeScreen.tsx index 9be6809..24aded1 100644 --- a/components/HomeScreen.tsx +++ b/components/HomeScreen.tsx @@ -1,7 +1,11 @@ import React, { useEffect, useState } from 'react'; -import { View, ActivityIndicator } from 'react-native'; +import { + View, + ActivityIndicator, + TouchableHighlight, + Image, +} from 'react-native'; import { Button, Text } from 'react-native-paper'; -import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import { NativeStackNavigationProp } from '@react-navigation/native-stack'; import { useNavigation } from '@react-navigation/native'; @@ -16,19 +20,28 @@ import styles from '../styles/stylesheet'; import { useAccounts } from '../context/AccountsContext'; import { StackParamsList } from '../types'; +const WCLogo = () => { + return ( + + ); +}; + const HomeScreen = () => { const { accounts, setAccounts } = useAccounts(); const navigation = useNavigation>(); - useEffect(() => { if (accounts.ethAccounts.length > 0) { navigation.setOptions({ headerRight: () => ( - + navigation.navigate('WalletConnect')}> + {} + ), }); } else { diff --git a/components/WalletConnect.tsx b/components/WalletConnect.tsx index 64a489c..1461f6d 100644 --- a/components/WalletConnect.tsx +++ b/components/WalletConnect.tsx @@ -1,107 +1,6 @@ -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 React from 'react'; +import { View, Text } from 'react-native'; -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 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 granted' - : 'No Camera Selected'} - - ) : ( - <> - - {isActive ? ( - - ) : ( - No Camera Selected! - )} - - - - Enter WalletConnect URI - - - - - - - - )} - - ); -}; -export default WalletConnect; +export default function WalletConnect() { + return ; +} diff --git a/context/RequestContext.tsx b/context/RequestContext.tsx index ee1ad57..c78233d 100644 --- a/context/RequestContext.tsx +++ b/context/RequestContext.tsx @@ -1,10 +1,11 @@ import React, { createContext, useContext, useState } from 'react'; -const RequestContext = createContext<{ - // TODO: Remove any type +interface RequestContextProps { requestSession: any; setRequestSession: (requestSession: any) => void; -}>({ +} + +const RequestContext = createContext({ requestSession: {}, setRequestSession: () => {}, }); @@ -14,7 +15,7 @@ const useRequests = () => { return requestContext; }; -const RequestProvider = ({ children }: { children: any }) => { +const RequestProvider = ({ children }: { children: React.ReactNode }) => { const [requestSession, setRequestSession] = useState({}); return (