diff --git a/App.tsx b/App.tsx index b36da6c..4ab5be3 100644 --- a/App.tsx +++ b/App.tsx @@ -1,9 +1,9 @@ import React, { useCallback, useEffect, useState } from 'react'; import { Button, Snackbar, Text } from 'react-native-paper'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; +import { TxBody, AuthInfo } from 'cosmjs-types/cosmos/tx/v1beta1/tx'; import { SignClientTypes } from '@walletconnect/types'; -import { getSdkError } from '@walletconnect/utils'; import { useNavigation } from '@react-navigation/native'; import { NativeStackNavigationProp, @@ -68,10 +68,26 @@ const App = (): React.JSX.Element => { break; case 'cosmos_signDirect': + const message = { + txbody: TxBody.toJSON( + TxBody.decode( + Uint8Array.from( + Buffer.from(request.params.signDoc.bodyBytes, 'hex'), + ), + ), + ), + authInfo: AuthInfo.toJSON( + AuthInfo.decode( + Uint8Array.from( + Buffer.from(request.params.signDoc.authInfoBytes, 'hex'), + ), + ), + ), + }; navigation.navigate('SignRequest', { network: 'cosmos', address: request.params.signerAddress, - message: request.params.signDoc.bodyBytes, + message: JSON.stringify(message, undefined, 2), requestEvent, requestSession, }); diff --git a/components/AddSession.tsx b/components/AddSession.tsx index 9efabb5..723298e 100644 --- a/components/AddSession.tsx +++ b/components/AddSession.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useState } from 'react'; -import { AppState, View } from 'react-native'; +import { AppState, TouchableOpacity, View } from 'react-native'; import { Button, Text, TextInput } from 'react-native-paper'; import { Camera, @@ -7,6 +7,7 @@ import { useCameraPermission, useCodeScanner, } from 'react-native-vision-camera'; +import { Linking } from 'react-native'; import { useNavigation } from '@react-navigation/native'; import { NativeStackNavigationProp } from '@react-navigation/native-stack'; @@ -40,6 +41,10 @@ const AddSession = () => { }, }); + const linkToSettings = async () => { + await Linking.openSettings(); + }; + const pair = async () => { const pairing = await web3WalletPair({ uri: currentWCURI }); navigation.navigate('WalletConnect'); @@ -56,16 +61,23 @@ const AddSession = () => { if (!hasPermission) { requestPermission(); } - }, [hasPermission, isActive, requestPermission]); + }, [hasPermission, requestPermission]); return ( {!hasPermission || !device ? ( - - {!hasPermission - ? 'No Camera Permission granted' - : 'No Camera Selected'} - + <> + + {!hasPermission + ? 'No Camera Permission granted' + : 'No Camera Selected'} + + + + Go to settings + + + ) : ( <> diff --git a/components/SignRequest.tsx b/components/SignRequest.tsx index fa5ebeb..6c0bcf9 100644 --- a/components/SignRequest.tsx +++ b/components/SignRequest.tsx @@ -1,5 +1,5 @@ -import React, { useEffect, useState } from 'react'; -import { Alert, Image, View } from 'react-native'; +import React, { useEffect, useMemo, useState } from 'react'; +import { Alert, Image, ScrollView, View } from 'react-native'; import { ActivityIndicator, Button, Text } from 'react-native-paper'; import { useNavigation } from '@react-navigation/native'; @@ -37,6 +37,12 @@ const SignRequest = ({ route }: SignRequestProps) => { const navigation = useNavigation>(); + const isCosmosSignDirect = useMemo(() => { + const requestParams = route.params!.requestEvent.params.request; + + return requestParams.method === 'cosmos_signDirect'; + }, [route.params]); + const retrieveData = async ( requestNetwork: string, requestAddress: string, @@ -173,9 +179,19 @@ const SignRequest = ({ route }: SignRequestProps) => { {requestURL} - - {message} - + + {isCosmosSignDirect ? ( + + + {message} + + + ) : ( + + {message} + + )} +