-
-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AddNotes: Add notes after payment #1447
Changes from 7 commits
3cb9562
93ff868
1eae97c
65e89c1
f9eb5a6
6f87432
45294d4
9f5c2f5
c83530a
da0b5e3
bb18fbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import * as React from 'react'; | ||
import { View, TextInput } from 'react-native'; | ||
import EncryptedStorage from 'react-native-encrypted-storage'; | ||
|
||
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'; | ||
|
||
interface AddNotesProps { | ||
navigation: any; | ||
} | ||
interface AddNotesState { | ||
notes?: string; | ||
payment_hash?: string; | ||
txid?: string; | ||
RPreimage?: string; | ||
} | ||
const noteKeys: string[] = []; | ||
|
||
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 RPreimage: string = this.props.navigation.getParam( | ||
'getRPreimage', | ||
null | ||
); | ||
|
||
this.state = { | ||
notes: '', | ||
payment_hash, | ||
txid, | ||
RPreimage | ||
}; | ||
} | ||
async componentDidMount() { | ||
const key: any = | ||
'note-' + | ||
(this.state.txid || | ||
this.state.payment_hash || | ||
this.state.RPreimage); | ||
const storedNotes = await EncryptedStorage.getItem(key); | ||
if (storedNotes) { | ||
this.setState({ notes: storedNotes }); | ||
} | ||
} | ||
|
||
render() { | ||
const { navigation } = this.props; | ||
const { payment_hash, txid, RPreimage } = this.state; | ||
const { notes } = this.state; | ||
return ( | ||
<Screen> | ||
<Header | ||
leftComponent="Back" | ||
centerComponent={{ | ||
text: notes | ||
? localeString('views.SendingLightning.UpdateNote') | ||
: localeString('views.SendingLightning.AddANote'), | ||
style: { | ||
color: themeColor('text'), | ||
fontFamily: 'Lato-Regular', | ||
fontSize: 20 | ||
} | ||
}} | ||
navigation={navigation} | ||
/> | ||
<View style={{ padding: 20 }}> | ||
<TextInput | ||
onChangeText={(text: string) => { | ||
this.setState({ notes: text }); | ||
if (!text) { | ||
const key: any = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. type is |
||
'note-' + | ||
(payment_hash || txid || RPreimage); | ||
const index = noteKeys.indexOf(key); | ||
if (index !== -1) { | ||
noteKeys.splice(index, 1); | ||
} | ||
} | ||
}} | ||
multiline | ||
numberOfLines={0} | ||
style={{ fontSize: 20, color: themeColor('text') }} | ||
value={notes} | ||
/> | ||
</View> | ||
<Button | ||
title={ | ||
notes | ||
? localeString('views.SendingLightning.UpdateNote') | ||
: localeString('views.SendingLightning.AddANote') | ||
} | ||
onPress={async () => { | ||
navigation.goBack(); | ||
const key: any = | ||
'note-' + (payment_hash || txid || RPreimage); | ||
await EncryptedStorage.setItem(key, notes); | ||
if (!noteKeys.includes(key)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be populated when you load the note, or perhaps in a a separate note store. You also need to add logic to remove it from the index if the user deletes the note There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added the logic to remove keys from noteKeys array, in |
||
noteKeys.push(key); | ||
await EncryptedStorage.setItem( | ||
'note-Keys', | ||
JSON.stringify(noteKeys) | ||
); | ||
} | ||
}} | ||
containerStyle={{ position: 'absolute', bottom: 40 }} | ||
buttonStyle={{ padding: 15 }} | ||
/> | ||
</Screen> | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this text shouldn't be dependent on whether the note in the state is set, rather if a previous note has been saved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same with the button at the bottom of this view