laconic-wallet/components/SignMessage.tsx
Adwait Gharpure cad0b6fae5 Refactor code (#18)
* Refactored accounts and sign message component

* Change sign message to hyperlink

* Refactor network dropdown

* Add types to utils

* Import react in index.js

* Use components for create wallet and reset dialog

* Remove inline styles from accounts component

* Remove inline styles from components

* Remove incorrectly placed async

* Make app responsive using flex

* Make review changes

---------

Co-authored-by: Adw8 <adwait@deepstacksoft.com>
2024-02-19 12:12:18 +05:30

70 lines
1.9 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';
import styles from '../styles/stylesheet';
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,
accountId: account.id,
});
Alert.alert('Signature', signedMessage);
}
};
return (
<ScrollView style={styles.signPage}>
<View style={styles.accountInfo}>
<View>
<Text variant="headlineSmall">
{account && `Account ${account.id + 1}`}
</Text>
</View>
<View style={styles.accountContainer}>
<Text variant="bodyLarge">
<Text style={styles.highlight}>Address: </Text>
{account?.address}
</Text>
<Text variant="bodyLarge">
<Text style={styles.highlight}>Public Key: </Text>
{account?.pubKey}
</Text>
</View>
</View>
<TextInput
mode="outlined"
placeholder="Enter your message"
onChangeText={text => setMessage(text)}
value={message}
/>
<View style={styles.signButton}>
<Button mode="contained" onPress={signMessageHandler}>
Sign
</Button>
</View>
</ScrollView>
);
};
export default SignMessage;