laconic-wallet/components/SignMessage.tsx
IshaVenikar 8685c94151 Integrate functionality to add new accounts with UI (#17)
* Create addAccount function

* Make review changes

* Create addAccount function

* Add id for each account

* Modify resetWallet function

* Make review changes

* Integrate functions
2024-02-19 12:12:18 +05:30

56 lines
1.7 KiB
TypeScript

import React, { useState } from 'react';
import { ScrollView, View, Alert } from 'react-native';
import { Button, Text, TextInput } from 'react-native-paper';
import { NativeStackScreenProps } from '@react-navigation/native-stack';
import { StackParamsList } from '../types';
import { signMessage } from '../utils';
type SignProps = NativeStackScreenProps<StackParamsList, 'SignMessage'>;
const SignMessage = ({ route }: SignProps) => {
const network = route.params?.selectedNetwork;
const account = route.params?.accountInfo;
const [message, setMessage] = useState<string>('');
const signMessageHandler = async () => {
if (network) {
if (!account) {
throw new Error('Account is not valid');
}
const signedMessage = await signMessage(message, network, account.id);
Alert.alert('Signature', signedMessage);
}
};
return (
<ScrollView style={{ marginTop: 24, paddingHorizontal: 24 }}>
<View style={{ marginTop: 24, marginBottom: 30 }}>
<Text variant="bodyLarge">
<Text style={{ fontWeight: '700' }}>Address: </Text>
{account && account.address}
</Text>
<Text variant="bodyLarge">
<Text style={{ fontWeight: '700' }}>Public Key: </Text>
{account && account.pubKey}
</Text>
</View>
<TextInput
mode="outlined"
placeholder="Enter your message"
onChangeText={text => setMessage(text)}
value={message}
/>
<View style={{ marginTop: 20, width: 150, alignSelf: 'center' }}>
<Button mode="contained" onPress={signMessageHandler}>
Sign
</Button>
</View>
</ScrollView>
);
};
export default SignMessage;