zenith-wallet-web/src/screens/SignMessage.tsx
Isha Venikar f554c82149
Integrate wallet connect (#2)
* Configure stack navigation to display header

* Use wallet connect to connect with dApps

* Replace react-native alerts with js alerts

* Add example env file

* Remove unnecessary code

* Make UI changes

* Uncomment required code

* Remove unnecessary dependencies

* Remove any type

* Fix indentation

---------

Co-authored-by: Shreerang Kale <shreerangkale@gmail.com>
Co-authored-by: Nabarun <nabarun@deepstacksoft.com>
2024-07-26 10:28:57 +05:30

61 lines
1.6 KiB
TypeScript

import React, { useState } from 'react';
import { View } 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 '../components/AccountDetails';
type SignProps = NativeStackScreenProps<StackParamsList, 'SignMessage'>;
const SignMessage = ({ route }: SignProps) => {
const namespace = route.params.selectedNamespace;
const chainId = route.params.selectedChainId;
const account = route.params.accountInfo;
const [message, setMessage] = useState<string>('');
const signMessageHandler = async () => {
const signedMessage = await signMessage({
message,
namespace,
chainId,
accountId: account.index,
});
alert(`Signature ${signedMessage}`);
};
return (
<View style={styles.signPage}>
<View style={styles.accountInfo}>
<View>
<Text variant="titleMedium">
{account && `Account ${account.index + 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>
</View>
);
};
export default SignMessage;