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
4
7
8
+ // Define interfaces properly
5
9
interface ScreenOnChain {
6
10
[ SCREEN_ONX_ADDRESS ] : {
7
11
invoice : string ;
8
12
} ;
9
13
}
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 ;
16
22
}
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 < / T e x t >
57
+
58
+ < View style = { styles . addressContainer} >
59
+ < Text style = { styles . label } > Your Bitcoin Address :< / Text >
60
+ < Text style = { styles . address } selectable >
61
+ { bitcoinAddress}
62
+ < / T e x t >
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 < / T e x t >
70
+ < / T o u c h a b l e O p a c i t y >
71
+
72
+ < TouchableOpacity
73
+ style = { styles . generateButton}
74
+ onPress = { handleGenerateAddress}
75
+ >
76
+ < Text style = { styles . generateButtonText } > Generate New Address < / T e x t >
77
+ < / T o u c h a b l e O p a c i t y >
78
+
79
+ < TouchableOpacity
80
+ style = { styles . invoiceButton}
81
+ onPress = { handleGenerateInvoice}
82
+ >
83
+ < Text style = { styles . invoiceButtonText } > Generate Lightning Invoice < / T e x t >
84
+ < / T o u c h a b l e O p a c i t y >
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
+ < / T e x t >
92
+ < / V i e w >
93
+ ) }
94
+ < / View >
95
+
96
+ < TouchableOpacity
97
+ style = { styles . backButton }
98
+ onPress = { ( ) => navigation . goBack ( ) }
99
+ >
100
+ < Text style = { styles . backButtonText } > Back < / T e x t >
101
+ < / T o u c h a b l e O p a c i t y >
102
+ < / V i e w >
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