Skip to content

Commit

Permalink
AddNotes: Add notes after payment
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamkmr04 committed Apr 25, 2023
1 parent 6f0e456 commit 3cb9562
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import ImportAccount from './views/Accounts/ImportAccount';
import ImportAccountQRScanner from './views/Accounts/ImportAccountQRScanner';
import BumpFee from './views/BumpFee';
import QR from './views/QR';
import AddNotes from './views/AddNotes';

// POS
import Order from './views/Order';
Expand Down Expand Up @@ -258,6 +259,9 @@ const AppScenes = {
},
QR: {
screen: QR
},
AddNotes: {
screen: AddNotes
}
};

Expand Down
74 changes: 74 additions & 0 deletions views/AddNotes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import * as React from 'react';
import EncryptedStorage from 'react-native-encrypted-storage';
import { View, TextInput } from 'react-native';
import TransactionsStore from '../stores/TransactionsStore';
import { inject, observer } from 'mobx-react';

import Header from '../components/Header';
import Screen from '../components/Screen';
import Button from '../components/Button';

import { themeColor } from '../utils/ThemeUtils';

interface AddNotesProps {
navigation: any;
TransactionsStore: TransactionsStore;
}
interface AddNotesState {
notes?: string;
}

@inject('TransactionsStore')
@observer
export default class AddNotes extends React.Component<
AddNotesProps,
AddNotesState
> {
constructor(props: any) {
super(props);
this.state = {
notes: ''
};
}

render() {
const { navigation, TransactionsStore } = this.props;
const { payment_hash } = TransactionsStore;
const { notes } = this.state;
return (
<Screen>
<Header
leftComponent="Back"
centerComponent={{
text: 'Add a note',
style: {
color: themeColor('text'),
fontFamily: 'Lato-Regular',
fontSize: 20
}
}}
navigation={navigation}
/>
<View style={{ padding: 20 }}>
<TextInput
onChangeText={(text: string) => {
this.setState({ notes: text });
}}
multiline
numberOfLines={0}
style={{ fontSize: 20 }}
/>
</View>
<Button
onPress={async () => {
navigation.navigate('SendingLightning');
await EncryptedStorage.setItem(payment_hash, notes);
}}
containerStyle={{ position: 'absolute', bottom: 40 }}
buttonStyle={{ padding: 15 }}
title="add note"
/>
</Screen>
);
}
}
20 changes: 19 additions & 1 deletion views/Payment.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import EncryptedStorage from 'react-native-encrypted-storage';
import { StyleSheet, ScrollView, View } from 'react-native';
import { Icon, ListItem } from 'react-native-elements';
import { inject, observer } from 'mobx-react';
Expand All @@ -25,7 +26,8 @@ interface PaymentProps {
@observer
export default class PaymentView extends React.Component<PaymentProps> {
state = {
lnurlpaytx: null
lnurlpaytx: null,
storedNotes: ''
};

async componentDidMount() {
Expand All @@ -35,10 +37,19 @@ export default class PaymentView extends React.Component<PaymentProps> {
if (lnurlpaytx) {
this.setState({ lnurlpaytx });
}
EncryptedStorage.getItem(payment.payment_hash)
.then((storedNotes) => {
console.log('Stored notes:', storedNotes);
this.setState({ storedNotes });
})
.catch((error) => {
console.error('Error retrieving notes:', error);
});
}

render() {
const { navigation } = this.props;
const { storedNotes } = this.state;

const payment: Payment = navigation.getParam('payment', null);
const {
Expand Down Expand Up @@ -177,6 +188,13 @@ export default class PaymentView extends React.Component<PaymentProps> {
/>
</ListItem>
)}
{storedNotes && (
<KeyValue
keyValue="Notes"
value={storedNotes}
sensitive
/>
)}
</View>
</ScrollView>
</Screen>
Expand Down
9 changes: 8 additions & 1 deletion views/SendingLightning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,14 @@ export default class SendingLightning extends React.Component<
/>
</View>
)}

{!loading && !(!!error || !!payment_error) && (
<Button
title="Add a note"
onPress={() => navigation.navigate('AddNotes')}
secondary
buttonStyle={{ padding: 15 }}
/>
)}
<View style={styles.buttons}>
{payment_hash && !(!!error || !!payment_error) && (
<View
Expand Down

0 comments on commit 3cb9562

Please sign in to comment.