Skip to content

Commit

Permalink
Using getNoteKeys function and refactoring for notes on separate views
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamkmr04 committed Sep 10, 2024
1 parent 7c4b5e7 commit 468ba57
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 32 deletions.
1 change: 0 additions & 1 deletion views/Activity/Activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ export default class Activity extends React.PureComponent<
// Use the getNoteKey from the model
const noteKey = item.getNoteKey;

// for (let matchKey of noteKeys) {
if (noteKey && notes[noteKey]) {
return notes[noteKey];
}
Expand Down
17 changes: 7 additions & 10 deletions views/AddNotes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ export default class AddNotes extends React.Component<
};
}
async componentDidMount() {
const key: string =
'note-' +
(this.state.txid ||
this.state.payment_hash ||
this.state.getRPreimage);
const key: any =
this.state.txid ||
this.state.payment_hash ||
this.state.getRPreimage;
const storedNotes = await EncryptedStorage.getItem(key);
if (storedNotes) {
this.setState({ notes: storedNotes, isNoteStored: true });
Expand All @@ -71,8 +70,7 @@ export default class AddNotes extends React.Component<
const { notes } = this.state;

const saveNote = async () => {
const key: string =
'note-' + (payment_hash || txid || getRPreimage);
const key: any = payment_hash || txid || getRPreimage;
EncryptedStorage.setItem(key, notes);
await storeNoteKeys(key, notes);
navigation.goBack();
Expand Down Expand Up @@ -119,9 +117,8 @@ export default class AddNotes extends React.Component<
onChangeText={(text: string) => {
this.setState({ notes: text });
if (!text) {
const key: string =
'note-' +
(payment_hash || txid || getRPreimage);
const key: any =
payment_hash || txid || getRPreimage;
removeNoteKeys(key);
}
}}
Expand Down
18 changes: 10 additions & 8 deletions views/Invoice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export default class InvoiceView extends React.Component<InvoiceProps> {
const { navigation, route } = this.props;
const invoice = route.params?.invoice;
navigation.addListener('focus', () => {
const noteKey = invoice.getRPreimage || invoice.payment_hash;
EncryptedStorage.getItem('note-' + noteKey)
const noteKey = invoice.getNoteKey;
EncryptedStorage.getItem(noteKey)
.then((storedNotes) => {
this.setState({ storedNotes });
})
Expand Down Expand Up @@ -72,10 +72,10 @@ export default class InvoiceView extends React.Component<InvoiceProps> {
getPaymentRequest,
getKeysendMessage,
is_amp,
value
value,
getNoteKey
} = invoice;
const privateInvoice = invoice.private;
const noteKey = getRPreimage || payment_hash;

const QRButton = () => (
<TouchableOpacity
Expand All @@ -91,7 +91,9 @@ export default class InvoiceView extends React.Component<InvoiceProps> {
const EditNotesButton = () => (
<TouchableOpacity
onPress={() =>
navigation.navigate('AddNotes', { getRPreimage: noteKey })
navigation.navigate('AddNotes', {
getRPreimage: getNoteKey
})
}
style={{ marginRight: 15 }}
>
Expand Down Expand Up @@ -295,15 +297,15 @@ export default class InvoiceView extends React.Component<InvoiceProps> {
sensitive
mempoolLink={() =>
navigation.navigate('AddNotes', {
getRPreimage: noteKey
getRPreimage: getNoteKey
})
}
/>
)}
</View>
</ScrollView>
<View style={{ bottom: 15 }}>
{noteKey && (
{getNoteKey && (
<Button
title={
storedNotes
Expand All @@ -316,7 +318,7 @@ export default class InvoiceView extends React.Component<InvoiceProps> {
}
onPress={() =>
navigation.navigate('AddNotes', {
getRPreimage: noteKey
getRPreimage: getNoteKey
})
}
containerStyle={{ marginTop: 15 }}
Expand Down
16 changes: 9 additions & 7 deletions views/Payment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export default class PaymentView extends React.Component<PaymentProps> {
getNote = () => {
const { route } = this.props;
const payment = route.params?.payment;
const noteKey = payment.noteKey;
EncryptedStorage.getItem('note-' + noteKey)
const noteKey = payment.getNoteKey;
EncryptedStorage.getItem(noteKey)
.then((storedNotes) => {
this.setState({ storedNotes });
})
Expand Down Expand Up @@ -100,15 +100,17 @@ export default class PaymentView extends React.Component<PaymentProps> {
isIncomplete,
isInTransit,
isFailed,
noteKey,
getNoteKey,
getPaymentRequest
} = payment;
const date = getDisplayTime;

const EditNotesButton = () => (
<TouchableOpacity
onPress={() =>
navigation.navigate('AddNotes', { payment_hash: noteKey })
navigation.navigate('AddNotes', {
payment_hash: getNoteKey
})
}
style={{ marginRight: 15 }}
>
Expand Down Expand Up @@ -311,15 +313,15 @@ export default class PaymentView extends React.Component<PaymentProps> {
sensitive
mempoolLink={() =>
navigation.navigate('AddNotes', {
payment_hash: noteKey
payment_hash: getNoteKey
})
}
/>
)}
</View>
</ScrollView>
<View style={{ bottom: 15 }}>
{noteKey && (
{getNoteKey && (
<Button
title={
storedNotes
Expand All @@ -332,7 +334,7 @@ export default class PaymentView extends React.Component<PaymentProps> {
}
onPress={() =>
navigation.navigate('AddNotes', {
payment_hash: noteKey
payment_hash: getNoteKey
})
}
containerStyle={{ marginTop: 15 }}
Expand Down
19 changes: 13 additions & 6 deletions views/Transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class TransactionView extends React.Component<
const transaction = route.params?.transaction;
navigation.addListener('focus', () => {
this.props.TransactionsStore.resetBroadcast();
EncryptedStorage.getItem('note-' + transaction.tx)
EncryptedStorage.getItem(transaction.getNoteKey)
.then((storedNotes) => {
this.setState({ storedNotes });
})
Expand Down Expand Up @@ -87,7 +87,8 @@ export default class TransactionView extends React.Component<
getFeePercentage,
status,
getOutpoint,
raw_tx_hex
raw_tx_hex,
getNoteKey
} = transaction;
const amount = transaction.getAmount;
const date = time_stamp && new Date(Number(time_stamp) * 1000);
Expand Down Expand Up @@ -134,7 +135,9 @@ export default class TransactionView extends React.Component<
);
const EditNotesButton = () => (
<TouchableOpacity
onPress={() => navigation.navigate('AddNotes', { txid: tx })}
onPress={() =>
navigation.navigate('AddNotes', { txid: getNoteKey })
}
>
<EditNotes
style={{ alignSelf: 'center' }}
Expand Down Expand Up @@ -365,7 +368,9 @@ export default class TransactionView extends React.Component<
{storedNotes && (
<TouchableOpacity
onPress={() =>
navigation.navigate('AddNotes', { txid: tx })
navigation.navigate('AddNotes', {
txid: getNoteKey
})
}
>
<KeyValue
Expand All @@ -390,7 +395,7 @@ export default class TransactionView extends React.Component<
/>
)}

{tx && (
{getNoteKey && (
<Button
title={
storedNotes
Expand All @@ -402,7 +407,9 @@ export default class TransactionView extends React.Component<
)
}
onPress={() =>
navigation.navigate('AddNotes', { txid: tx })
navigation.navigate('AddNotes', {
txid: getNoteKey
})
}
containerStyle={{ marginTop: 20 }}
noUppercase
Expand Down

0 comments on commit 468ba57

Please sign in to comment.