1
1
import React , { useState } from 'react' ;
2
2
import { Box , Button , Input , Heading , Text } from '@gluestack-ui/themed' ;
3
3
import { useNavigation } from '@react-navigation/native' ;
4
- function ZKPoolEnter ( ) {
4
+
5
+ // Type definition for navigation prop
6
+ type NavigationProp = ReturnType < typeof useNavigation > ;
7
+
8
+ const ZKPoolEnter = ( ) => {
5
9
const [ amount , setAmount ] = useState ( '' ) ;
6
10
const [ loading , setLoading ] = useState ( false ) ;
7
- const navigation = useNavigation ( ) ;
11
+ const navigation = useNavigation < NavigationProp > ( ) ;
8
12
9
13
const onEnterPool = async ( ) => {
10
- // Validate the input amount
11
- const parsedAmount = parseFloat ( amount ) ;
12
- if ( isNaN ( parsedAmount ) || parsedAmount <= 0 ) {
13
- alert ( 'Please enter a valid positive Bitcoin amount.' ) ;
14
- return ;
15
- }
14
+ try {
15
+ // Validate the input amount
16
+ const parsedAmount = parseFloat ( amount ) ;
17
+ if ( isNaN ( parsedAmount ) || parsedAmount <= 0 ) {
18
+ alert ( 'Please enter a valid positive Bitcoin amount.' ) ;
19
+ return ;
20
+ }
16
21
17
- setLoading ( true ) ;
22
+ setLoading ( true ) ;
18
23
19
- try {
20
24
// Generate the ZK proof for the entered amount
21
25
const zkProof = await createZKDepositProof ( parsedAmount ) ;
22
26
23
- // Broadcast or submit the transaction (depending on your integration logic)
27
+ // Broadcast or submit the transaction
24
28
await broadcastZKPoolEntry ( zkProof ) ;
25
29
26
- // Show success message and navigate (e.g., to a success screen)
30
+ // Show success message and navigate
27
31
alert ( 'ZK Pool Entry Successful!' ) ;
28
- navigation . goBack ( ) ; // Replace with a success screen navigation if needed
32
+ navigation . goBack ( ) ;
29
33
} catch ( error ) {
30
34
console . error ( 'Error entering ZK pool:' , error ) ;
31
- alert ( ' Failed to enter the ZK Pool.' ) ;
35
+ alert ( ` Failed to enter the ZK Pool: ${ error instanceof Error ? error . message : String ( error ) } ` ) ;
32
36
} finally {
33
37
setLoading ( false ) ;
34
38
}
35
39
} ;
36
-
37
40
return (
38
- < Box flex = { 1 } justifyContent = "center" alignItems = "center" bg = "$primary400" p = { 4 } >
39
- < Heading size = "xl" color = "white" mb = { 5 } >
41
+ < Box
42
+ flex = { 1 }
43
+ justifyContent = "center"
44
+ alignItems = "center"
45
+ bg = "$primary400"
46
+ p = "$4"
47
+ >
48
+ < Heading size = "xl" color = "$white" mb = "$5" >
40
49
Enter ZK Pool
41
50
</ Heading >
42
- < Text size = "lg" color = "white" mb = { 2 } >
43
- Enter the amount of Bitcoin to deposit into the ZK Pool
51
+ < Text size = "lg" color = "$ white" mb = "$2" >
52
+ Enter the amount of Bitcoin to deposit
44
53
</ Text >
45
54
< Input
55
+ variant = "outline"
56
+ size = "md"
57
+ placeholderTextColor = "$gray400"
46
58
placeholder = "Amount (BTC)"
47
59
value = { amount }
48
60
onChangeText = { setAmount }
49
61
keyboardType = "numeric"
50
- mb = { 5 }
62
+ mb = "$5"
51
63
w = "80%"
64
+ bg = "$white"
65
+ borderColor = "$gray300"
52
66
/>
53
- < Button onPress = { onEnterPool } isDisabled = { loading } isLoading = { loading } variant = "solid" >
54
- { loading ? 'Processing...' : 'Enter Pool' }
67
+ < Button
68
+ size = "md"
69
+ variant = "solid"
70
+ bg = "$primary500"
71
+ onPress = { onEnterPool }
72
+ isDisabled = { loading }
73
+ $loading = { loading }
74
+ >
75
+ < Text color = "$white" >
76
+ { loading ? 'Processing...' : 'Enter Pool' }
77
+ </ Text >
55
78
</ Button >
56
79
</ Box >
57
80
) ;
58
- }
59
-
60
- async function createZKDepositProof ( amount : number ) {
61
- // Replace this mock function with your ZK proof generation logic
81
+ } ;
82
+ const createZKDepositProof = async ( amount : number ) : Promise < string > => {
83
+ // Replace with actual ZK proof generation logic
62
84
return new Promise ( ( resolve ) => {
63
85
setTimeout ( ( ) => resolve ( `zk-proof-for-${ amount } -btc` ) , 2000 ) ;
64
86
} ) ;
65
- }
87
+ } ;
66
88
67
- async function broadcastZKPoolEntry ( zkProof : string ) {
68
- // Replace this mock function with your actual broadcasting logic
89
+ const broadcastZKPoolEntry = async ( zkProof : string ) : Promise < void > => {
90
+ // Replace with actual broadcasting logic
69
91
console . log ( 'Broadcasting ZK Pool Entry with proof:' , zkProof ) ;
70
- }
92
+ } ;
71
93
72
- export default ZKPoolEnter ;
94
+ export default ZKPoolEnter ;
0 commit comments