diff --git a/stores/TransactionsStore.ts b/stores/TransactionsStore.ts index 6c2cd0da6..e5f8cbfc6 100644 --- a/stores/TransactionsStore.ts +++ b/stores/TransactionsStore.ts @@ -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; @@ -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; diff --git a/views/AddNotes.tsx b/views/AddNotes.tsx index 663152e6a..2d87e0d19 100644 --- a/views/AddNotes.tsx +++ b/views/AddNotes.tsx @@ -20,16 +20,11 @@ import SaveIcon from '../assets/images/SVG/Save.svg'; interface AddNotesProps { navigation: StackNavigationProp; 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; } @@ -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 }); } @@ -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(); }; @@ -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 diff --git a/views/Invoice.tsx b/views/Invoice.tsx index cfb7955f0..505a7411a 100644 --- a/views/Invoice.tsx +++ b/views/Invoice.tsx @@ -92,7 +92,7 @@ export default class InvoiceView extends React.Component { navigation.navigate('AddNotes', { - getRPreimage: getNoteKey + noteKey: getNoteKey }) } style={{ marginRight: 15 }} @@ -297,7 +297,7 @@ export default class InvoiceView extends React.Component { sensitive mempoolLink={() => navigation.navigate('AddNotes', { - getRPreimage: getNoteKey + noteKey: getNoteKey }) } /> @@ -318,7 +318,7 @@ export default class InvoiceView extends React.Component { } onPress={() => navigation.navigate('AddNotes', { - getRPreimage: getNoteKey + noteKey: getNoteKey }) } containerStyle={{ marginTop: 15 }} diff --git a/views/Payment.tsx b/views/Payment.tsx index 5feefc454..70d9b43ca 100644 --- a/views/Payment.tsx +++ b/views/Payment.tsx @@ -109,7 +109,7 @@ export default class PaymentView extends React.Component { navigation.navigate('AddNotes', { - payment_hash: getNoteKey + noteKey: getNoteKey }) } style={{ marginRight: 15 }} @@ -313,7 +313,7 @@ export default class PaymentView extends React.Component { sensitive mempoolLink={() => navigation.navigate('AddNotes', { - payment_hash: getNoteKey + noteKey: getNoteKey }) } /> @@ -334,7 +334,7 @@ export default class PaymentView extends React.Component { } onPress={() => navigation.navigate('AddNotes', { - payment_hash: getNoteKey + noteKey: getNoteKey }) } containerStyle={{ marginTop: 15 }} diff --git a/views/SendingLightning.tsx b/views/SendingLightning.tsx index 5c99e2661..eb63e36e4 100644 --- a/views/SendingLightning.tsx +++ b/views/SendingLightning.tsx @@ -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 }); }) @@ -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; @@ -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 ( {loading && ( @@ -435,7 +424,7 @@ export default class SendingLightning extends React.Component< } onPress={() => navigation.navigate('AddNotes', { - payment_hash: noteKey + noteKey }) } secondary diff --git a/views/SendingOnChain.tsx b/views/SendingOnChain.tsx index 8ce9ef906..00928db25 100644 --- a/views/SendingOnChain.tsx +++ b/views/SendingOnChain.tsx @@ -204,7 +204,7 @@ export default class SendingOnChain extends React.Component< } onPress={() => navigation.navigate('AddNotes', { - txid + noteKey: txid }) } secondary diff --git a/views/Transaction.tsx b/views/Transaction.tsx index 77bd82931..d4f7067d6 100644 --- a/views/Transaction.tsx +++ b/views/Transaction.tsx @@ -136,7 +136,7 @@ export default class TransactionView extends React.Component< const EditNotesButton = () => ( - navigation.navigate('AddNotes', { txid: getNoteKey }) + navigation.navigate('AddNotes', { noteKey: getNoteKey }) } > navigation.navigate('AddNotes', { - txid: getNoteKey + noteKey: getNoteKey }) } > @@ -408,7 +408,7 @@ export default class TransactionView extends React.Component< } onPress={() => navigation.navigate('AddNotes', { - txid: getNoteKey + noteKey: getNoteKey }) } containerStyle={{ marginTop: 20 }}