Integrate functions with UI (#14)

* Add the creatHDWallet function

* Make review changes

* Add signMessage and signEthMessage functions

* Add signCosmosMessage function

* Add resetWallet function

* Add resetWallet function

* Integrate functions with UI

* Add Alerts to react component

* Make review changes

* Add comment in utils file

* Remove lowerCase conversion in signCosmosmessage function

---------

Co-authored-by: IshaVenikar <ishavenikar7@gmail.com>
This commit is contained in:
shreerang6921
2024-02-14 19:14:21 +05:30
committed by GitHub
co-authored by IshaVenikar
parent 9ab3148aa9
commit 09a3b9fc75
9 changed files with 599 additions and 75 deletions
+5 -10
View File
@@ -1,7 +1,6 @@
import React, { useState } from 'react';
import { View } from 'react-native';
import { Text, Button, Dialog, Portal } from 'react-native-paper';
import { HDNode } from 'ethers/lib/utils';
import { useNavigation } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
@@ -11,14 +10,11 @@ import { DialogComponent } from './Dialog';
import { NetworkDropdown } from './NetworkDropdown';
import { StackParamsList, Account } from '../types';
const HomeScreen = () => {
const navigation =
useNavigation<NativeStackNavigationProp<StackParamsList>>();
const [isWalletCreated, setIsWalletCreated] = useState<boolean>(false);
const [wallet, setWallet] = useState<HDNode | null>();
const [isWalletCreating, setIsWalletCreating] = useState<boolean>(false);
const [walletDialog, setWalletDialog] = useState<boolean>(false);
const [resetWalletDialog, setResetWalletDialog] = useState<boolean>(false);
@@ -33,11 +29,11 @@ const HomeScreen = () => {
const createWalletHandler = async () => {
setIsWalletCreating(true);
await new Promise(resolve => setTimeout(resolve, 2000));
const { ethAccount, cosmosAccount } = createWallet();
const { ethWalletInfo, cosmosWalletInfo } = await createWallet();
setEthAccount(ethAccount);
setCosmosAccount(cosmosAccount);
setCurrentAccount(ethAccount);
setEthAccount(ethWalletInfo);
setCosmosAccount(cosmosWalletInfo);
setCurrentAccount(ethWalletInfo);
setWalletDialog(true);
setIsWalletCreated(true);
};
@@ -45,7 +41,6 @@ const HomeScreen = () => {
const confirmResetWallet = async () => {
await resetWallet();
setIsWalletCreated(false);
setWallet(null);
setIsWalletCreating(false);
hideResetDialog();
};
@@ -99,7 +94,7 @@ const HomeScreen = () => {
</Text>
<Text variant="bodyLarge">
<Text style={{ fontWeight: '700' }}>Public Key: </Text>
{currentAccount && currentAccount.publicKey}
{currentAccount && currentAccount.pubKey}
</Text>
</View>
+9 -5
View File
@@ -1,6 +1,7 @@
import { View } from 'react-native';
import { Button, TextInput } from 'react-native-paper';
import React, { useState } from 'react';
import { Alert } from 'react-native';
import { NativeStackScreenProps } from '@react-navigation/native-stack';
@@ -14,6 +15,13 @@ const SignMessage = ({ route }: SignProps) => {
const [message, setMessage] = useState<string>('');
const signMessageHandler = async () => {
if (network) {
const signedMessage = await signMessage(message, network, 0);
Alert.alert('Signature', signedMessage);
}
};
return (
<View style={{ marginTop: 30, paddingHorizontal: 48 }}>
<TextInput
@@ -23,11 +31,7 @@ const SignMessage = ({ route }: SignProps) => {
value={message}
/>
<View style={{ marginTop: 20, width: 150, alignSelf: 'center' }}>
<Button
mode="contained"
onPress={() => {
network && signMessage(network, 0, message);
}}>
<Button mode="contained" onPress={signMessageHandler}>
Sign
</Button>
</View>