Skip to content

Commit e9fbe96

Browse files
committed
Fix issues
1 parent 2c11bda commit e9fbe96

File tree

3 files changed

+149
-93
lines changed

3 files changed

+149
-93
lines changed

src/navigation/ZKPoolEnter.tsx

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,94 @@
11
import React, { useState } from 'react';
22
import { Box, Button, Input, Heading, Text } from '@gluestack-ui/themed';
33
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 = () => {
59
const [amount, setAmount] = useState('');
610
const [loading, setLoading] = useState(false);
7-
const navigation = useNavigation();
11+
const navigation = useNavigation<NavigationProp>();
812

913
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+
}
1621

17-
setLoading(true);
22+
setLoading(true);
1823

19-
try {
2024
// Generate the ZK proof for the entered amount
2125
const zkProof = await createZKDepositProof(parsedAmount);
2226

23-
// Broadcast or submit the transaction (depending on your integration logic)
27+
// Broadcast or submit the transaction
2428
await broadcastZKPoolEntry(zkProof);
2529

26-
// Show success message and navigate (e.g., to a success screen)
30+
// Show success message and navigate
2731
alert('ZK Pool Entry Successful!');
28-
navigation.goBack(); // Replace with a success screen navigation if needed
32+
navigation.goBack();
2933
} catch (error) {
3034
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)}`);
3236
} finally {
3337
setLoading(false);
3438
}
3539
};
36-
3740
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">
4049
Enter ZK Pool
4150
</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
4453
</Text>
4554
<Input
55+
variant="outline"
56+
size="md"
57+
placeholderTextColor="$gray400"
4658
placeholder="Amount (BTC)"
4759
value={amount}
4860
onChangeText={setAmount}
4961
keyboardType="numeric"
50-
mb={5}
62+
mb="$5"
5163
w="80%"
64+
bg="$white"
65+
borderColor="$gray300"
5266
/>
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>
5578
</Button>
5679
</Box>
5780
);
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
6284
return new Promise((resolve) => {
6385
setTimeout(() => resolve(`zk-proof-for-${amount}-btc`), 2000);
6486
});
65-
}
87+
};
6688

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
6991
console.log('Broadcasting ZK Pool Entry with proof:', zkProof);
70-
}
92+
};
7193

72-
export default ZKPoolEnter;
94+
export default ZKPoolEnter;

src/navigation/ZKPoolExit.tsx

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/navigation/ZKProofExit.tsx

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

0 commit comments

Comments
 (0)