forked from cerc-io/laconic-wallet
* Display HD path on sign message page * Create component for displaying account details * Add retrieve accounts function * Load accounts after closing app * Fix the retrieve accounts function * Use hdpath instead of id * Check if keystore is empty while retrieving accounts * Add spinner when accounts are being fetched * Display complete hd paths after reloading the app * Remove any return type * Store public key and address * Modify sign message function to use path * Fix the add accounts functionality
64 lines
1.7 KiB
TypeScript
64 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 styles from '../styles/stylesheet';
|
|
import { signMessage } from '../utils/sign-message';
|
|
import AccountDetails from './AccountDetails';
|
|
|
|
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.counterId,
|
|
});
|
|
Alert.alert('Signature', signedMessage);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<ScrollView style={styles.signPage}>
|
|
<View style={styles.accountInfo}>
|
|
<View>
|
|
<Text variant="headlineSmall">
|
|
{account && `Account ${account.counterId + 1}`}
|
|
</Text>
|
|
</View>
|
|
<View style={styles.accountContainer}>
|
|
<AccountDetails account={account} />
|
|
</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;
|