-
-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathAddNotes.tsx
170 lines (160 loc) · 5.79 KB
/
AddNotes.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
import * as React from 'react';
import { Keyboard, TouchableOpacity, View } from 'react-native';
import EncryptedStorage from 'react-native-encrypted-storage';
import { inject, observer } from 'mobx-react';
import Header from '../components/Header';
import Screen from '../components/Screen';
import Button from '../components/Button';
import { localeString } from '../utils/LocaleUtils';
import { themeColor } from '../utils/ThemeUtils';
import NotesStore from '../stores/NotesStore';
import TextInput from '../components/TextInput';
import SaveIcon from '../assets/images/SVG/Save.svg';
interface AddNotesProps {
navigation: any;
NotesStore: NotesStore;
}
interface AddNotesState {
notes?: string;
payment_hash?: string;
txid?: string;
getRPreimage?: string;
isNoteStored?: boolean;
}
@inject('NotesStore')
@observer
export default class AddNotes extends React.Component<
AddNotesProps,
AddNotesState
> {
constructor(props: any) {
super(props);
const payment_hash: string = this.props.navigation.getParam(
'payment_hash',
null
);
const txid: string = this.props.navigation.getParam('txid', null);
const getRPreimage: string = this.props.navigation.getParam(
'getRPreimage',
null
);
this.state = {
notes: '',
payment_hash,
txid,
getRPreimage,
isNoteStored: false
};
}
async componentDidMount() {
const key: string =
'note-' +
(this.state.txid ||
this.state.payment_hash ||
this.state.getRPreimage);
const storedNotes = await EncryptedStorage.getItem(key);
if (storedNotes) {
this.setState({ notes: storedNotes, isNoteStored: true });
}
}
render() {
const { navigation, NotesStore } = this.props;
const { storeNoteKeys, removeNoteKeys } = NotesStore;
const { payment_hash, txid, getRPreimage, isNoteStored } = this.state;
const { notes } = this.state;
const saveNote = async () => {
const key: string =
'note-' + (payment_hash || txid || getRPreimage);
EncryptedStorage.setItem(key, notes);
await storeNoteKeys(key, notes);
navigation.goBack();
};
const SaveButton = () => (
<TouchableOpacity onPress={() => saveNote()}>
<SaveIcon
stroke={themeColor('text')}
fill={themeColor('secondary')}
/>
</TouchableOpacity>
);
return (
<Screen>
<View
style={{
flexDirection: 'column',
height: '100%'
}}
>
<Header
leftComponent="Back"
centerComponent={{
text: isNoteStored
? localeString(
'views.SendingLightning.UpdateNote'
)
: localeString(
'views.SendingLightning.AddANote'
),
style: {
color: themeColor('text'),
fontFamily: 'Lato-Regular',
fontSize: 20
}
}}
rightComponent={SaveButton}
navigation={navigation}
/>
<TextInput
onChangeText={(text: string) => {
this.setState({ notes: text });
if (!text) {
const key: string =
'note-' +
(payment_hash || txid || getRPreimage);
removeNoteKeys(key);
}
}}
multiline
numberOfLines={0}
style={{
padding: 20,
flexGrow: 1,
flexShrink: 1
}}
textInputStyle={{
height: '100%',
textAlignVertical: 'top',
marginTop: -13
}}
value={notes}
placeholder={localeString('views.Payment.writeNote')}
onSubmitEditing={() => Keyboard.dismiss()}
/>
<View
style={{
marginHorizontal: 20,
marginBottom: 20,
marginTop: 10
}}
>
<Button
title={
isNoteStored
? localeString(
'views.SendingLightning.UpdateNote'
)
: localeString(
'views.SendingLightning.AddANote'
)
}
onPress={() => saveNote()}
buttonStyle={{
padding: 15
}}
/>
</View>
</View>
</Screen>
);
}
}