Skip to content

Commit b7cda03

Browse files
committed
Fix
1 parent f57e6c1 commit b7cda03

File tree

2 files changed

+300
-9
lines changed

2 files changed

+300
-9
lines changed

src/navigation/Receive.tsx

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import React, { useState } from "react";
2+
import { View, Text, StyleSheet, TouchableOpacity } from "react-native";
3+
import { useNavigation } from "@react-navigation/native";
4+
5+
export const Receive = () => {
6+
const navigation = useNavigation();
7+
8+
// Using state to manage the address with a default message
9+
const [bitcoinAddress, setBitcoinAddress] = useState("Generate an address to receive Bitcoin");
10+
11+
// Function to handle copying address to clipboard
12+
const handleCopyAddress = () => {
13+
if (bitcoinAddress !== "Generate an address to receive Bitcoin") {
14+
console.log("Address copied to clipboard:", bitcoinAddress);
15+
// In a real app, you'd use Clipboard here
16+
} else {
17+
console.log("No address to copy");
18+
// You could add a toast notification here
19+
}
20+
};
21+
22+
// Function to simulate generating a new address
23+
const handleGenerateAddress = () => {
24+
// In a real app, this would call a wallet API
25+
const newAddress = "bc1q" + Math.random().toString(36).substring(2, 15);
26+
setBitcoinAddress(newAddress);
27+
};
28+
29+
return (
30+
<View style={styles.container}>
31+
<Text style={styles.title}>Receive Bitcoin</Text>
32+
33+
<View style={styles.addressContainer}>
34+
<Text style={styles.label}>Your Bitcoin Address:</Text>
35+
<Text style={styles.address} selectable>
36+
{bitcoinAddress}
37+
</Text>
38+
39+
<TouchableOpacity
40+
style={styles.copyButton}
41+
onPress={handleCopyAddress}
42+
disabled={bitcoinAddress === "Generate an address to receive Bitcoin"}
43+
>
44+
<Text style={styles.copyButtonText}>Copy Address</Text>
45+
</TouchableOpacity>
46+
47+
<TouchableOpacity
48+
style={styles.generateButton}
49+
onPress={handleGenerateAddress}
50+
>
51+
<Text style={styles.generateButtonText}>Generate New Address</Text>
52+
</TouchableOpacity>
53+
</View>
54+
55+
<TouchableOpacity
56+
style={styles.backButton}
57+
onPress={() => navigation.goBack()}
58+
>
59+
<Text style={styles.backButtonText}>Back</Text>
60+
</TouchableOpacity>
61+
</View>
62+
);
63+
};
64+
65+
const styles = StyleSheet.create({
66+
container: {
67+
flex: 1,
68+
padding: 20,
69+
backgroundColor: '#fff',
70+
},
71+
title: {
72+
fontSize: 24,
73+
fontWeight: 'bold',
74+
marginBottom: 20,
75+
textAlign: 'center',
76+
},
77+
addressContainer: {
78+
backgroundColor: '#f5f5f5',
79+
padding: 15,
80+
borderRadius: 8,
81+
marginBottom: 20,
82+
},
83+
label: {
84+
fontSize: 16,
85+
marginBottom: 10,
86+
},
87+
address: {
88+
fontSize: 14,
89+
color: '#333',
90+
marginBottom: 15,
91+
},
92+
copyButton: {
93+
backgroundColor: '#007AFF',
94+
padding: 10,
95+
borderRadius: 5,
96+
alignItems: 'center',
97+
marginBottom: 10,
98+
},
99+
copyButtonText: {
100+
color: '#fff',
101+
fontSize: 16,
102+
},
103+
generateButton: {
104+
backgroundColor: '#4CAF50',
105+
padding: 10,
106+
borderRadius: 5,
107+
alignItems: 'center',
108+
},
109+
generateButtonText: {
110+
color: '#fff',
111+
fontSize: 16,
112+
},
113+
backButton: {
114+
backgroundColor: '#666',
115+
padding: 10,
116+
borderRadius: 5,
117+
alignItems: 'center',
118+
},
119+
backButtonText: {
120+
color: '#fff',
121+
fontSize: 16,
122+
},
123+
});
124+
125+
export default Receive;

src/navigation/screenOnChain.ts

Lines changed: 175 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,182 @@
1-
import { generateInvoice } from "../app/lightning";
2-
import { SCREEN_ONX_ADDRESS } from "../app/constants";
3-
import { interface } from "../utils/nostr/encryption";
1+
import React, { useState } from "react";
2+
import { View, Text, StyleSheet, TouchableOpacity } from "react-native";
3+
import { useNavigation } from "@react-navigation/native";
4+
import { generateInvoice } from "../app/lightning"; // Fixed import path
5+
import { SCREEN_ONX_ADDRESS } from "../app/constants"; // Fixed import path
6+
import { interface as nostrInterface } from "../utils/nostr/encryption"; // Renamed to avoid keyword conflict
47

8+
// Define interfaces properly
59
interface ScreenOnChain {
610
[SCREEN_ONX_ADDRESS]: {
711
invoice: string;
812
};
913
}
10-
interface {
11-
OnboardingHome: 'OnboardingHome';
12-
Send: 'Send';
13-
Receive: 'Receive';
14-
generateInvoice: 'generateInvoice';
15-
generateAddress: 'generateAddress';
14+
15+
// Define navigation param list
16+
interface NavigationParams {
17+
OnboardingHome: undefined;
18+
Send: undefined;
19+
Receive: undefined;
20+
generateInvoice: undefined;
21+
generateAddress: undefined;
1622
}
23+
24+
export const Receive = () => {
25+
const navigation = useNavigation();
26+
const [bitcoinAddress, setBitcoinAddress] = useState("Generate an address to receive Bitcoin");
27+
const [invoice, setInvoice] = useState<string | null>(null);
28+
29+
// Function to handle copying address to clipboard
30+
const handleCopyAddress = () => {
31+
if (bitcoinAddress !== "Generate an address to receive Bitcoin") {
32+
console.log("Address copied to clipboard:", bitcoinAddress);
33+
} else {
34+
console.log("No address to copy");
35+
}
36+
};
37+
38+
// Function to generate a new Bitcoin address
39+
const handleGenerateAddress = () => {
40+
const newAddress = "bc1q" + Math.random().toString(36).substring(2, 15);
41+
setBitcoinAddress(newAddress);
42+
};
43+
44+
// Function to generate lightning invoice
45+
const handleGenerateInvoice = async () => {
46+
try {
47+
const newInvoice = await generateInvoice();
48+
setInvoice(newInvoice);
49+
} catch (error) {
50+
console.error("Failed to generate invoice:", error);
51+
}
52+
};
53+
54+
return (
55+
<View style={styles.container}>
56+
<Text style={styles.title}>Receive Bitcoin</Text>
57+
58+
<View style={styles.addressContainer}>
59+
<Text style={styles.label}>Your Bitcoin Address:</Text>
60+
<Text style={styles.address} selectable>
61+
{bitcoinAddress}
62+
</Text>
63+
64+
<TouchableOpacity
65+
style={styles.copyButton}
66+
onPress={handleCopyAddress}
67+
disabled={bitcoinAddress === "Generate an address to receive Bitcoin"}
68+
>
69+
<Text style={styles.copyButtonText}>Copy Address</Text>
70+
</TouchableOpacity>
71+
72+
<TouchableOpacity
73+
style={styles.generateButton}
74+
onPress={handleGenerateAddress}
75+
>
76+
<Text style={styles.generateButtonText}>Generate New Address</Text>
77+
</TouchableOpacity>
78+
79+
<TouchableOpacity
80+
style={styles.invoiceButton}
81+
onPress={handleGenerateInvoice}
82+
>
83+
<Text style={styles.invoiceButtonText}>Generate Lightning Invoice</Text>
84+
</TouchableOpacity>
85+
86+
{invoice && (
87+
<View style={styles.invoiceContainer}>
88+
<Text style={styles.label}>Lightning Invoice:</Text>
89+
<Text style={styles.address} selectable>
90+
{invoice}
91+
</Text>
92+
</View>
93+
)}
94+
</View>
95+
96+
<TouchableOpacity
97+
style={styles.backButton}
98+
onPress={() => navigation.goBack()}
99+
>
100+
<Text style={styles.backButtonText}>Back</Text>
101+
</TouchableOpacity>
102+
</View>
103+
);
104+
};
105+
106+
const styles = StyleSheet.create({
107+
container: {
108+
flex: 1,
109+
padding: 20,
110+
backgroundColor: '#fff',
111+
},
112+
title: {
113+
fontSize: 24,
114+
fontWeight: 'bold',
115+
marginBottom: 20,
116+
textAlign: 'center',
117+
},
118+
addressContainer: {
119+
backgroundColor: '#f5f5f5',
120+
padding: 15,
121+
borderRadius: 8,
122+
marginBottom: 20,
123+
},
124+
invoiceContainer: {
125+
marginTop: 15,
126+
},
127+
label: {
128+
fontSize: 16,
129+
marginBottom: 10,
130+
},
131+
address: {
132+
fontSize: 14,
133+
color: '#333',
134+
marginBottom: 15,
135+
wordBreak: 'break-all',
136+
},
137+
copyButton: {
138+
backgroundColor: '#007AFF',
139+
padding: 10,
140+
borderRadius: 5,
141+
alignItems: 'center',
142+
marginBottom: 10,
143+
},
144+
copyButtonText: {
145+
color: '#fff',
146+
fontSize: 16,
147+
},
148+
generateButton: {
149+
backgroundColor: '#4CAF50',
150+
padding: 10,
151+
borderRadius: 5,
152+
alignItems: 'center',
153+
marginBottom: 10,
154+
},
155+
generateButtonText: {
156+
color: '#fff',
157+
fontSize: 16,
158+
},
159+
invoiceButton: {
160+
backgroundColor: '#FFA500',
161+
padding: 10,
162+
borderRadius: 5,
163+
alignItems: 'center',
164+
marginBottom: 10,
165+
},
166+
invoiceButtonText: {
167+
color: '#fff',
168+
fontSize: 16,
169+
},
170+
backButton: {
171+
backgroundColor: '#666',
172+
padding: 10,
173+
borderRadius: 5,
174+
alignItems: 'center',
175+
},
176+
backButtonText: {
177+
color: '#fff',
178+
fontSize: 16,
179+
},
180+
});
181+
182+
export default Receive;

0 commit comments

Comments
 (0)