-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathActionsView.tsx
39 lines (36 loc) · 1.34 KB
/
ActionsView.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Button, Text } from '@web3modal/ui-react-native';
import { View } from 'react-native';
import { useSignMessage, useAccount, useSendTransaction, useEstimateGas } from 'wagmi';
import { Hex, parseEther } from 'viem';
export function ActionsView() {
const { isConnected } = useAccount();
const { data, isError, isPending, isSuccess, signMessage } = useSignMessage();
const TX = {
to: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' as Hex, // vitalik.eth
value: parseEther('0.001'),
data: '0x' as Hex
};
const { data: gas, isError: isGasError } = useEstimateGas(TX);
const {
data: sendData,
isPending: isSending,
isSuccess: isSendSuccess,
sendTransaction
} = useSendTransaction();
return isConnected ? (
<View>
<Text variant="large-600">Wagmi Actions</Text>
<Button disabled={isPending} onPress={() => signMessage({ message: 'Hello Web3Modal!' })}>
Sign
</Button>
{isSuccess && <Text>Signature: {data}</Text>}
{isGasError && <Text>Error estimating gas</Text>}
{isError && <Text>Error signing message</Text>}
<Button disabled={isSending} onPress={() => sendTransaction({ ...TX, gas })}>
Send
</Button>
{isSending && <Text>Check Wallet</Text>}
{isSendSuccess && <Text>Transaction: {JSON.stringify(sendData)}</Text>}
</View>
) : null;
}