-
-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathPayment.tsx
270 lines (250 loc) · 10 KB
/
Payment.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import * as React from 'react';
import EncryptedStorage from 'react-native-encrypted-storage';
import { StyleSheet, ScrollView, View, TouchableOpacity } from 'react-native';
import { Icon, ListItem } from 'react-native-elements';
import { inject, observer } from 'mobx-react';
import Amount from '../components/Amount';
import Header from '../components/Header';
import KeyValue from '../components/KeyValue';
import Screen from '../components/Screen';
import Payment from '../models/Payment';
import { localeString } from '../utils/LocaleUtils';
import { themeColor } from '../utils/ThemeUtils';
import LnurlPayStore from '../stores/LnurlPayStore';
import LnurlPayHistorical from './LnurlPay/Historical';
import EditNotes from '../assets/images/SVG/Pen.svg';
import Button from '../components/Button';
interface PaymentProps {
navigation: any;
LnurlPayStore: LnurlPayStore;
}
@inject('LnurlPayStore')
@observer
export default class PaymentView extends React.Component<PaymentProps> {
state = {
lnurlpaytx: null,
storedNotes: ''
};
async componentDidMount() {
const { navigation, LnurlPayStore } = this.props;
const payment: Payment = navigation.getParam('payment', null);
const lnurlpaytx = await LnurlPayStore.load(payment.payment_hash);
if (lnurlpaytx) {
this.setState({ lnurlpaytx });
}
navigation.addListener('didFocus', () => {
const noteKey =
typeof payment.payment_hash === 'string'
? payment.payment_hash
: typeof payment.getPreimage === 'string'
? payment.getPreimage
: null;
EncryptedStorage.getItem('note-' + noteKey)
.then((storedNotes) => {
this.setState({ storedNotes });
})
.catch((error) => {
console.error('Error retrieving notes:', error);
});
});
}
render() {
const { navigation } = this.props;
const { storedNotes, lnurlpaytx } = this.state;
const payment: Payment = navigation.getParam('payment', null);
const {
getDisplayTime,
getFee,
payment_hash,
getPreimage,
enhancedPath,
getMemo
} = payment;
const date = getDisplayTime;
const noteKey =
typeof payment_hash === 'string'
? payment_hash
: typeof getPreimage === 'string'
? getPreimage
: null;
const EditNotesButton = () => (
<TouchableOpacity
onPress={() =>
navigation.navigate('AddNotes', { payment_hash: noteKey })
}
style={{ marginTop: -12 }}
>
<EditNotes height={40} width={40} />
</TouchableOpacity>
);
return (
<Screen>
<Header
leftComponent="Back"
centerComponent={{
text: localeString('views.Payment.title'),
style: {
color: themeColor('text'),
fontFamily: 'Lato-Regular'
}
}}
rightComponent={<EditNotesButton />}
navigation={navigation}
/>
<ScrollView keyboardShouldPersistTaps="handled">
<View style={styles.center}>
<Amount
sats={payment.getAmount}
debit
jumboText
sensitive
toggleable
/>
</View>
{lnurlpaytx && (
<View style={styles.historical}>
<LnurlPayHistorical
navigation={navigation}
lnurlpaytx={lnurlpaytx}
preimage={getPreimage}
/>
</View>
)}
<View style={styles.content}>
{getFee && (
<KeyValue
keyValue={localeString('views.Payment.fee')}
value={
<Amount
sats={getFee}
debit
sensitive
toggleable
/>
}
toggleable
/>
)}
{getMemo && (
<KeyValue
keyValue={localeString('views.Receive.memo')}
value={getMemo}
sensitive
/>
)}
{typeof payment_hash === 'string' && (
<KeyValue
keyValue={localeString(
'views.Payment.paymentHash'
)}
value={payment_hash}
sensitive
/>
)}
{getPreimage && (
<KeyValue
keyValue={localeString(
'views.Payment.paymentPreimage'
)}
value={getPreimage}
sensitive
/>
)}
{date && (
<KeyValue
keyValue={localeString(
'views.Payment.creationDate'
)}
value={date}
sensitive
/>
)}
{enhancedPath.length > 0 && (
<ListItem
containerStyle={{
borderBottomWidth: 0,
backgroundColor: 'transparent',
marginLeft: -16,
marginRight: -16
}}
onPress={() =>
navigation.navigate('PaymentPaths', {
enhancedPath
})
}
>
<ListItem.Content>
<ListItem.Title
style={{
color: themeColor('secondaryText'),
fontFamily: 'Lato-Regular'
}}
>
{enhancedPath.length > 1
? `${localeString(
'views.Payment.paths'
)} (${enhancedPath.length})`
: localeString(
'views.Payment.path'
)}
</ListItem.Title>
</ListItem.Content>
<Icon
name="keyboard-arrow-right"
color={themeColor('secondaryText')}
/>
</ListItem>
)}
{storedNotes && (
<KeyValue
keyValue={localeString('views.Payment.notes')}
value={storedNotes}
sensitive
mempoolLink={() =>
navigation.navigate('AddNotes', {
payment_hash: noteKey
})
}
/>
)}
{noteKey && (
<Button
title={
storedNotes
? localeString(
'views.SendingLightning.UpdateNote'
)
: localeString(
'views.SendingLightning.AddANote'
)
}
onPress={() =>
navigation.navigate('AddNotes', {
payment_hash: noteKey
})
}
containerStyle={{ marginTop: 15 }}
secondary
noUppercase
/>
)}
</View>
</ScrollView>
</Screen>
);
}
}
const styles = StyleSheet.create({
content: {
paddingLeft: 20,
paddingRight: 20
},
historical: {
padding: 20
},
center: {
alignItems: 'center',
paddingTop: 15,
paddingBottom: 15
}
});