From 8141c48e17a4a5cefd0f2f8a31463fcb88f5ee71 Mon Sep 17 00:00:00 2001 From: shubham Date: Wed, 11 Dec 2024 21:32:07 +0530 Subject: [PATCH] Using 'max_payments' and 'reversed' to fetch only last 5 payments after a successful lightning payment --- backends/LND.ts | 6 +++--- backends/LightningNodeConnect.ts | 7 ++++--- stores/PaymentsStore.ts | 14 ++++++-------- views/SendingLightning.tsx | 3 +-- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/backends/LND.ts b/backends/LND.ts index dcc3a35fb..1c6280a98 100644 --- a/backends/LND.ts +++ b/backends/LND.ts @@ -327,10 +327,10 @@ export default class LND { getPayments = (data?: any) => this.getRequest( `/v1/payments?include_incomplete=true${ - data && data?.indexOffSet - ? `&index_offset=${data?.indexOffSet}` + data && data?.maxPayments + ? `&max_payments=${data.maxPayments}` : '' - }` + }${data?.reversed ? `&reversed=${data.reversed}` : ''}` ); getNewAddress = (data: any) => this.getRequest('/v1/newaddress', data); diff --git a/backends/LightningNodeConnect.ts b/backends/LightningNodeConnect.ts index 8d540173c..cc27c8ba3 100644 --- a/backends/LightningNodeConnect.ts +++ b/backends/LightningNodeConnect.ts @@ -175,9 +175,10 @@ export default class LightningNodeConnect { .listPayments({ include_incomplete: true, ...(data && - data?.indexOffSet && { - index_offset: data.indexOffSet - }) + data?.maxPayments && { + max_payments: data.maxPayments + }), + ...(data && data?.reversed && { reversed: data?.reversed }) }) .then((data: lnrpc.ListPaymentsResponse) => snakeize(data)); getNewAddress = async (data: any) => diff --git a/stores/PaymentsStore.ts b/stores/PaymentsStore.ts index ea5cd385f..d328fe4b7 100644 --- a/stores/PaymentsStore.ts +++ b/stores/PaymentsStore.ts @@ -10,7 +10,6 @@ export default class PaymentsStore { @observable error = false; @observable error_msg: string; @observable payments: Array = []; - @observable last_index_offset: number; settingsStore: SettingsStore; channelsStore: ChannelsStore; @@ -31,15 +30,15 @@ export default class PaymentsStore { }; @action - public getPayments = async (indexOffSet: any = undefined) => { + public getPayments = async ( + maxPayments: any = undefined, + reversed: boolean = false + ) => { this.loading = true; try { - if (!indexOffSet) { - console.log('Fetching all payments..'); - } else console.log('Fetching the last payment', indexOffSet); - const data = await BackendUtils.getPayments({ - indexOffSet + maxPayments, + reversed }); const payments = data.payments; this.payments = payments @@ -49,7 +48,6 @@ export default class PaymentsStore { (payment: any) => new Payment(payment, this.channelsStore.nodes) ); - this.last_index_offset = data.last_index_offset; this.loading = false; return this.payments; } catch (error) { diff --git a/views/SendingLightning.tsx b/views/SendingLightning.tsx index 9478d7ef2..a5189ff6b 100644 --- a/views/SendingLightning.tsx +++ b/views/SendingLightning.tsx @@ -97,9 +97,8 @@ export default class SendingLightning extends React.Component< fetchPayments = async () => { const { PaymentsStore, TransactionsStore } = this.props; - const { last_index_offset } = PaymentsStore; try { - const payments = await PaymentsStore.getPayments(last_index_offset); + const payments = await PaymentsStore.getPayments(5, true); const matchingPayment = payments.find( (payment: any) => payment.payment_preimage ===