-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3cb9562
AddNotes: Add notes after payment
shubhamkmr04 93ff868
Added notes for Onchain transaction, Payment view and Transaction view
shubhamkmr04 1eae97c
Add prefix 'note-' in the key to fetch notes
shubhamkmr04 65e89c1
Fixed all the issues raised in comments
shubhamkmr04 f9eb5a6
Added notes on invoice
shubhamkmr04 6f87432
Added 'Add/Update note' button on Transaction and Payment view as well
shubhamkmr04 45294d4
Storing keys separately that are used to fetch notes
shubhamkmr04 9f5c2f5
NotesStore: Storing and removing keys
shubhamkmr04 c83530a
Fixing Add notes btn position, Btn/header text depending on stored notes
shubhamkmr04 da0b5e3
Fixed margin and button style
shubhamkmr04 bb18fbe
NotesStore: removeNoteKeys: update local storage
kaloudis File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { action, observable } from 'mobx'; | ||
import EncryptedStorage from 'react-native-encrypted-storage'; | ||
|
||
export default class NotesStore { | ||
@observable public noteKeys: string[] = []; | ||
|
||
@action | ||
public storeNoteKeys = async (key: string, notes: string) => { | ||
if (!this.noteKeys.includes(key)) { | ||
if (notes) { | ||
this.noteKeys.push(key); | ||
} | ||
try { | ||
await EncryptedStorage.setItem( | ||
'note-Keys', | ||
JSON.stringify(this.noteKeys) | ||
); | ||
} catch (error) { | ||
console.error('Error saving to encrypted storage'); | ||
} | ||
} | ||
}; | ||
|
||
@action | ||
public removeNoteKeys = (key: string) => { | ||
const index = this.noteKeys.indexOf(key); | ||
if (index !== -1) { | ||
this.noteKeys.splice(index, 1); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import * as React from 'react'; | ||
import { View, TextInput } 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'; | ||
|
||
interface AddNotesProps { | ||
navigation: any; | ||
NotesStore: NotesStore; | ||
} | ||
interface AddNotesState { | ||
notes?: string; | ||
payment_hash?: string; | ||
txid?: string; | ||
RPreimage?: string; | ||
} | ||
|
||
@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 RPreimage: string = this.props.navigation.getParam( | ||
'getRPreimage', | ||
null | ||
); | ||
|
||
this.state = { | ||
notes: '', | ||
payment_hash, | ||
txid, | ||
RPreimage | ||
}; | ||
} | ||
async componentDidMount() { | ||
const key: string = | ||
'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, NotesStore } = this.props; | ||
const { storingNoteKeys, removeNoteKeys } = NotesStore; | ||
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: string = | ||
'note-' + | ||
(payment_hash || txid || RPreimage); | ||
removeNoteKeys(key); | ||
} | ||
}} | ||
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 () => { | ||
const key: string = | ||
'note-' + (payment_hash || txid || RPreimage); | ||
await EncryptedStorage.setItem(key, notes); | ||
await storingNoteKeys(key, notes); | ||
navigation.goBack(); | ||
}} | ||
containerStyle={{ position: 'absolute', bottom: 40 }} | ||
buttonStyle={{ padding: 15 }} | ||
/> | ||
</Screen> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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