Skip to content

Commit

Permalink
Using in sendingLightning as well + using noteKey variable in all vie…
Browse files Browse the repository at this point in the history
…ws while sending it to AddNotes
  • Loading branch information
shubhamkmr04 committed Sep 11, 2024
1 parent 468ba57 commit 481d980
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 50 deletions.
3 changes: 3 additions & 0 deletions stores/TransactionsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export default class TransactionsStore {
@observable onchain_address: string;
@observable txid: string | null;
@observable status: string | number | null;
@observable noteKey: string;

// in lieu of receiving txid on LND's publishTransaction
@observable publishSuccess = false;
@observable broadcast_txid: string;
Expand Down Expand Up @@ -487,6 +489,7 @@ export default class TransactionsStore {
this.payment_route = result.payment_route;

const payment = new Payment(result);
this.noteKey = payment.getNoteKey;
this.payment_preimage = payment.getPreimage;
this.payment_hash = payment.paymentHash;
this.isIncomplete = payment.isIncomplete;
Expand Down
34 changes: 10 additions & 24 deletions views/AddNotes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,11 @@ import SaveIcon from '../assets/images/SVG/Save.svg';
interface AddNotesProps {
navigation: StackNavigationProp<any, any>;
NotesStore: NotesStore;
route: Route<
'AddNotes',
{ payment_hash: string; txid: string; getRPreimage: string }
>;
route: Route<'AddNotes', { noteKey: string }>;
}
interface AddNotesState {
notes?: string;
payment_hash?: string;
txid?: string;
getRPreimage?: string;
noteKey?: string;
isNoteStored?: boolean;
}

Expand All @@ -41,23 +36,17 @@ export default class AddNotes extends React.Component<
> {
constructor(props: any) {
super(props);
const { payment_hash, txid, getRPreimage } =
this.props.route.params ?? {};
const { noteKey } = this.props.route.params ?? {};

this.state = {
notes: '',
payment_hash,
txid,
getRPreimage,
noteKey,
isNoteStored: false
};
}
async componentDidMount() {
const key: any =
this.state.txid ||
this.state.payment_hash ||
this.state.getRPreimage;
const storedNotes = await EncryptedStorage.getItem(key);
const { noteKey } = this.state;
const storedNotes = await EncryptedStorage.getItem(noteKey);
if (storedNotes) {
this.setState({ notes: storedNotes, isNoteStored: true });
}
Expand All @@ -66,13 +55,12 @@ export default class AddNotes extends React.Component<
render() {
const { navigation, NotesStore } = this.props;
const { storeNoteKeys, removeNoteKeys } = NotesStore;
const { payment_hash, txid, getRPreimage, isNoteStored } = this.state;
const { noteKey, isNoteStored } = this.state;
const { notes } = this.state;

const saveNote = async () => {
const key: any = payment_hash || txid || getRPreimage;
EncryptedStorage.setItem(key, notes);
await storeNoteKeys(key, notes);
EncryptedStorage.setItem(noteKey, notes);
await storeNoteKeys(noteKey, notes);
navigation.goBack();
};

Expand Down Expand Up @@ -117,9 +105,7 @@ export default class AddNotes extends React.Component<
onChangeText={(text: string) => {
this.setState({ notes: text });
if (!text) {
const key: any =
payment_hash || txid || getRPreimage;
removeNoteKeys(key);
removeNoteKeys(noteKey);
}
}}
multiline
Expand Down
6 changes: 3 additions & 3 deletions views/Invoice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class InvoiceView extends React.Component<InvoiceProps> {
<TouchableOpacity
onPress={() =>
navigation.navigate('AddNotes', {
getRPreimage: getNoteKey
noteKey: getNoteKey
})
}
style={{ marginRight: 15 }}
Expand Down Expand Up @@ -297,7 +297,7 @@ export default class InvoiceView extends React.Component<InvoiceProps> {
sensitive
mempoolLink={() =>
navigation.navigate('AddNotes', {
getRPreimage: getNoteKey
noteKey: getNoteKey
})
}
/>
Expand All @@ -318,7 +318,7 @@ export default class InvoiceView extends React.Component<InvoiceProps> {
}
onPress={() =>
navigation.navigate('AddNotes', {
getRPreimage: getNoteKey
noteKey: getNoteKey
})
}
containerStyle={{ marginTop: 15 }}
Expand Down
6 changes: 3 additions & 3 deletions views/Payment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default class PaymentView extends React.Component<PaymentProps> {
<TouchableOpacity
onPress={() =>
navigation.navigate('AddNotes', {
payment_hash: getNoteKey
noteKey: getNoteKey
})
}
style={{ marginRight: 15 }}
Expand Down Expand Up @@ -313,7 +313,7 @@ export default class PaymentView extends React.Component<PaymentProps> {
sensitive
mempoolLink={() =>
navigation.navigate('AddNotes', {
payment_hash: getNoteKey
noteKey: getNoteKey
})
}
/>
Expand All @@ -334,7 +334,7 @@ export default class PaymentView extends React.Component<PaymentProps> {
}
onPress={() =>
navigation.navigate('AddNotes', {
payment_hash: getNoteKey
noteKey: getNoteKey
})
}
containerStyle={{ marginTop: 15 }}
Expand Down
21 changes: 5 additions & 16 deletions views/SendingLightning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,8 @@ export default class SendingLightning extends React.Component<
const { TransactionsStore, navigation } = this.props;

navigation.addListener('focus', () => {
const noteKey =
typeof TransactionsStore.payment_hash === 'string'
? TransactionsStore.payment_hash
: typeof TransactionsStore.payment_preimage === 'string'
? TransactionsStore.payment_preimage
: null;
EncryptedStorage.getItem('note-' + noteKey)
const noteKey: string = TransactionsStore.noteKey;
EncryptedStorage.getItem(noteKey)
.then((storedNotes) => {
this.setState({ storedNotes });
})
Expand Down Expand Up @@ -156,7 +151,8 @@ export default class SendingLightning extends React.Component<
payment_hash,
payment_preimage,
payment_error,
isIncomplete
isIncomplete,
noteKey
} = TransactionsStore;
const { storedNotes, currentPayment } = this.state;

Expand All @@ -169,13 +165,6 @@ export default class SendingLightning extends React.Component<
const inTransit = this.inTransit(TransactionsStore);
const windowSize = Dimensions.get('window');

const noteKey =
typeof payment_hash === 'string'
? payment_hash
: typeof payment_preimage === 'string'
? payment_preimage
: null;

return (
<Screen>
{loading && (
Expand Down Expand Up @@ -435,7 +424,7 @@ export default class SendingLightning extends React.Component<
}
onPress={() =>
navigation.navigate('AddNotes', {
payment_hash: noteKey
noteKey
})
}
secondary
Expand Down
2 changes: 1 addition & 1 deletion views/SendingOnChain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export default class SendingOnChain extends React.Component<
}
onPress={() =>
navigation.navigate('AddNotes', {
txid
noteKey: txid
})
}
secondary
Expand Down
6 changes: 3 additions & 3 deletions views/Transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export default class TransactionView extends React.Component<
const EditNotesButton = () => (
<TouchableOpacity
onPress={() =>
navigation.navigate('AddNotes', { txid: getNoteKey })
navigation.navigate('AddNotes', { noteKey: getNoteKey })
}
>
<EditNotes
Expand Down Expand Up @@ -369,7 +369,7 @@ export default class TransactionView extends React.Component<
<TouchableOpacity
onPress={() =>
navigation.navigate('AddNotes', {
txid: getNoteKey
noteKey: getNoteKey
})
}
>
Expand Down Expand Up @@ -408,7 +408,7 @@ export default class TransactionView extends React.Component<
}
onPress={() =>
navigation.navigate('AddNotes', {
txid: getNoteKey
noteKey: getNoteKey
})
}
containerStyle={{ marginTop: 20 }}
Expand Down

0 comments on commit 481d980

Please sign in to comment.