1
1
import React , { useState } from "react" ;
2
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
3
+ import { NavigationProp , useNavigation } from "@react-navigation/native" ;
4
+ import { generateInvoice } from "../app/lightning" ;
5
+ import { SCREEN_ONX_ADDRESS } from "../app/constants" ;
6
+ import * as nostrInterface from "../utils/nostr/encryption" ; // Evita conflito de palavras-chave
7
7
8
- // Define interfaces properly
9
- interface ScreenOnChain {
10
- [ SCREEN_ONX_ADDRESS ] : {
11
- invoice : string ;
12
- } ;
13
- }
14
-
15
- // Define navigation param list
8
+ // Tipagem correta dos parâmetros de navegação
16
9
interface NavigationParams {
17
10
OnboardingHome : undefined ;
18
11
Send : undefined ;
@@ -21,162 +14,161 @@ interface NavigationParams {
21
14
generateAddress : undefined ;
22
15
}
23
16
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 ) ;
17
+ // Tipagem para armazenamento de invoice na blockchain
18
+ interface ScreenOnChain {
19
+ [ key in typeof SCREEN_ONX_ADDRESS ] : {
20
+ invoice : string ;
21
+ } ;
22
+ }
23
+
24
+ export const Receive : React . FC = ( ) => {
25
+ const navigation = useNavigation < NavigationProp < NavigationParams > > ( ) ;
26
+ const [ bitcoinAddress , setBitcoinAddress ] = useState (
27
+ "Generate an address to receive Bitcoin"
28
+ ) ;
29
+ const [ invoice , setInvoice ] = useState < string | null > ( null ) ;
28
30
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
- } ;
31
+ // Copiar endereço para área de transferência
32
+ const handleCopyAddress = ( ) => {
33
+ if ( bitcoinAddress !== "Generate an address to receive Bitcoin" ) {
34
+ console . log ( "Address copied to clipboard:" , bitcoinAddress ) ;
35
+ } else {
36
+ console . log ( "No address to copy" ) ;
37
+ }
38
+ } ;
37
39
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
- } ;
40
+ // Gerar novo endereço Bitcoin
41
+ const handleGenerateAddress = ( ) => {
42
+ const newAddress = "bc1q" + Math . random ( ) . toString ( 36 ) . substring ( 2 , 15 ) ;
43
+ setBitcoinAddress ( newAddress ) ;
44
+ } ;
45
+
46
+ // Gerar fatura Lightning
47
+ const handleGenerateInvoice = async ( ) => {
48
+ try {
49
+ const newInvoice = await generateInvoice ( ) ;
50
+ setInvoice ( newInvoice ) ;
51
+ } catch ( error ) {
52
+ console . error ( "Failed to generate invoice:" , error ) ;
53
+ }
54
+ } ;
43
55
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
- } ;
56
+ return (
57
+ < View style = { styles . container } >
58
+ < Text style = { styles . title } > Receive Bitcoin < / T e x t >
53
59
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 >
60
+ < View style = { styles . addressContainer} >
61
+ < Text style = { styles . label } > Your Bitcoin Address :< / Text >
62
+ < Text style = { styles . address } selectable >
63
+ { bitcoinAddress}
64
+ < / T e x t >
63
65
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 >
66
+ < TouchableOpacity
67
+ style = { styles . copyButton}
68
+ onPress = { handleCopyAddress}
69
+ disabled = { bitcoinAddress = = = "Generate an address to receive Bitcoin" }
70
+ >
71
+ < Text style = { styles . copyButtonText} > Copy Address < / T e x t >
72
+ < / T o u c h a b l e O p a c i t y >
71
73
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 >
74
+ < TouchableOpacity style = { styles . generateButton} onPress = { handleGenerateAddress} >
75
+ < Text style = { styles . generateButtonText } > Generate New Address < / T e x t >
76
+ < / T o u c h a b l e O p a c i t y >
78
77
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 >
78
+ < TouchableOpacity style = { styles . invoiceButton} onPress = { handleGenerateInvoice} >
79
+ < Text style = { styles . invoiceButtonText } > Generate Lightning Invoice < / T e x t >
80
+ < / T o u c h a b l e O p a c i t y >
85
81
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 >
82
+ { invoice && (
83
+ < View style = { styles . invoiceContainer } >
84
+ < Text style = { styles . label } > Lightning Invoice :< / Text >
85
+ < Text style = { styles . address } selectable >
86
+ { invoice}
87
+ < / T e x t >
88
+ < / V i e w >
89
+ ) }
90
+ < / View >
95
91
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
- ) ;
92
+ < TouchableOpacity style = { styles . backButton} onPress = { ( ) => navigation . goBack ( ) } >
93
+ < Text style = { styles . backButtonText } > Back < / T e x t >
94
+ < / T o u c h a b l e O p a c i t y >
95
+ < / V i e w >
96
+ ) ;
104
97
} ;
105
98
106
99
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
- } ,
100
+ container : {
101
+ flex : 1 ,
102
+ padding : 20 ,
103
+ backgroundColor : "#fff" ,
104
+ } ,
105
+ title : {
106
+ fontSize : 24 ,
107
+ fontWeight : "bold" ,
108
+ marginBottom : 20 ,
109
+ textAlign : "center" ,
110
+ } ,
111
+ addressContainer : {
112
+ backgroundColor : "#f5f5f5" ,
113
+ padding : 15 ,
114
+ borderRadius : 8 ,
115
+ marginBottom : 20 ,
116
+ } ,
117
+ invoiceContainer : {
118
+ marginTop : 15 ,
119
+ } ,
120
+ label : {
121
+ fontSize : 16 ,
122
+ marginBottom : 10 ,
123
+ } ,
124
+ address : {
125
+ fontSize : 14 ,
126
+ color : "#333" ,
127
+ marginBottom : 15 ,
128
+ } ,
129
+ copyButton : {
130
+ backgroundColor : "#007AFF" ,
131
+ padding : 10 ,
132
+ borderRadius : 5 ,
133
+ alignItems : "center" ,
134
+ marginBottom : 10 ,
135
+ } ,
136
+ copyButtonText : {
137
+ color : "#fff" ,
138
+ fontSize : 16 ,
139
+ } ,
140
+ generateButton : {
141
+ backgroundColor : "#4CAF50" ,
142
+ padding : 10 ,
143
+ borderRadius : 5 ,
144
+ alignItems : "center" ,
145
+ marginBottom : 10 ,
146
+ } ,
147
+ generateButtonText : {
148
+ color : "#fff" ,
149
+ fontSize : 16 ,
150
+ } ,
151
+ invoiceButton : {
152
+ backgroundColor : "#FFA500" ,
153
+ padding : 10 ,
154
+ borderRadius : 5 ,
155
+ alignItems : "center" ,
156
+ marginBottom : 10 ,
157
+ } ,
158
+ invoiceButtonText : {
159
+ color : "#fff" ,
160
+ fontSize : 16 ,
161
+ } ,
162
+ backButton : {
163
+ backgroundColor : "#666" ,
164
+ padding : 10 ,
165
+ borderRadius : 5 ,
166
+ alignItems : "center" ,
167
+ } ,
168
+ backButtonText : {
169
+ color : "#fff" ,
170
+ fontSize : 16 ,
171
+ } ,
180
172
} ) ;
181
173
182
- export default Receive ;
174
+ export default Receive ;
0 commit comments