1
1
import { Button , Text } from '@web3modal/ui-react-native' ;
2
2
import { View } from 'react-native' ;
3
- import { useSignMessage , useAccount , useSendTransaction } from 'wagmi' ;
4
- import { parseEther } from 'viem' ;
3
+ import { useSignMessage , useAccount , useSendTransaction , useEstimateGas } from 'wagmi' ;
4
+ import { Hex , parseEther } from 'viem' ;
5
5
6
6
export function ActionsView ( ) {
7
7
const { isConnected } = useAccount ( ) ;
8
8
const { data, isError, isPending, isSuccess, signMessage } = useSignMessage ( ) ;
9
+ const TX = {
10
+ to : '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' as Hex , // vitalik.eth
11
+ value : parseEther ( '0.001' ) ,
12
+ data : '0x' as Hex
13
+ } ;
14
+ const { data : gas , isError : isGasError } = useEstimateGas ( TX ) ;
9
15
10
16
const {
11
17
data : sendData ,
@@ -21,17 +27,9 @@ export function ActionsView() {
21
27
Sign
22
28
</ Button >
23
29
{ isSuccess && < Text > Signature: { data } </ Text > }
30
+ { isGasError && < Text > Error estimating gas</ Text > }
24
31
{ isError && < Text > Error signing message</ Text > }
25
- < Button
26
- disabled = { isSending }
27
- onPress = { ( ) =>
28
- sendTransaction ( {
29
- to : '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' , // vitalik.eth
30
- value : parseEther ( '0.001' ) ,
31
- data : '0x'
32
- } )
33
- }
34
- >
32
+ < Button disabled = { isSending } onPress = { ( ) => sendTransaction ( { ...TX , gas } ) } >
35
33
Send
36
34
</ Button >
37
35
{ isSending && < Text > Check Wallet</ Text > }
0 commit comments