From a29967e5c4f04ec6ca753052414175bf8137f489 Mon Sep 17 00:00:00 2001 From: shubham Date: Wed, 11 Dec 2024 19:31:05 +0530 Subject: [PATCH] Update call and paymentStore to fetch only the last payment after sending a lightning payment --- backends/LND.ts | 6 +++--- backends/LightningNodeConnect.ts | 5 ++++- stores/PaymentsStore.ts | 16 ++++++++++++++-- views/SendingLightning.tsx | 4 +++- views/Wallet/Wallet.tsx | 5 +++++ 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/backends/LND.ts b/backends/LND.ts index 7e1651217..dcc3a35fb 100644 --- a/backends/LND.ts +++ b/backends/LND.ts @@ -324,11 +324,11 @@ export default class LND { : undefined, route_hints: data.route_hints }); - getPayments = (data?: { maxPayments?: any }) => + getPayments = (data?: any) => this.getRequest( `/v1/payments?include_incomplete=true${ - data && data?.maxPayments - ? `&max_payments=${data.maxPayments}` + data && data?.indexOffSet + ? `&index_offset=${data?.indexOffSet}` : '' }` ); diff --git a/backends/LightningNodeConnect.ts b/backends/LightningNodeConnect.ts index 181a85758..55ed7f78d 100644 --- a/backends/LightningNodeConnect.ts +++ b/backends/LightningNodeConnect.ts @@ -174,7 +174,10 @@ export default class LightningNodeConnect { await this.lnc.lnd.lightning .listPayments({ include_incomplete: true, - max_payment: data && data?.maxPayments + ...(data && + data?.indexOffSet && { + indexOffSet: data.indexOffSet + }) }) .then((data: lnrpc.ListPaymentsResponse) => snakeize(data)); getNewAddress = async (data: any) => diff --git a/stores/PaymentsStore.ts b/stores/PaymentsStore.ts index 73c395db7..5293bf909 100644 --- a/stores/PaymentsStore.ts +++ b/stores/PaymentsStore.ts @@ -9,7 +9,9 @@ export default class PaymentsStore { @observable loading = false; @observable error = false; @observable error_msg: string; + @observable payments: Array = []; + @observable last_index_offset: number; settingsStore: SettingsStore; channelsStore: ChannelsStore; @@ -30,11 +32,19 @@ export default class PaymentsStore { }; @action - public getPayments = async (maxPayments: any = undefined) => { + public getPayments = async (indexOffSet: any = undefined) => { + console.log('Fetching payments...'); this.loading = true; try { - const data = await BackendUtils.getPayments({ maxPayments }); + if (!indexOffSet) { + console.log('Fetching all payments..'); + } else console.log('Fetching the last payment', indexOffSet); + + const data = await BackendUtils.getPayments({ + indexOffSet + }); const payments = data.payments; + this.payments = payments .slice() .reverse() @@ -42,7 +52,9 @@ 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) { this.resetPayments(); diff --git a/views/SendingLightning.tsx b/views/SendingLightning.tsx index 71c67f825..a28886af8 100644 --- a/views/SendingLightning.tsx +++ b/views/SendingLightning.tsx @@ -97,8 +97,10 @@ 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(5); // fetch only last 5 payments + const payments = await PaymentsStore.getPayments(last_index_offset); + const matchingPayment = payments.find( (payment: any) => payment.payment_preimage === diff --git a/views/Wallet/Wallet.tsx b/views/Wallet/Wallet.tsx index bb145ba10..0115ef90c 100644 --- a/views/Wallet/Wallet.tsx +++ b/views/Wallet/Wallet.tsx @@ -71,6 +71,7 @@ import SyncStore from '../../stores/SyncStore'; import UnitsStore from '../../stores/UnitsStore'; import UTXOsStore from '../../stores/UTXOsStore'; import ContactStore from '../../stores/ContactStore'; +import PaymentsStore from '../../stores/PaymentsStore'; import NotesStore from '../../stores/NotesStore'; import Bitcoin from '../../assets/images/SVG/Bitcoin.svg'; @@ -96,6 +97,7 @@ interface WalletProps { PosStore: PosStore; UTXOsStore: UTXOsStore; ContactStore: ContactStore; + PaymentsStore: PaymentsStore; ModalStore: ModalStore; SyncStore: SyncStore; LSPStore: LSPStore; @@ -121,6 +123,7 @@ interface WalletState { 'PosStore', 'UTXOsStore', 'ContactStore', + 'PaymentsStore', 'ModalStore', 'SyncStore', 'LSPStore', @@ -302,6 +305,7 @@ export default class Wallet extends React.Component { ChannelsStore, UTXOsStore, ContactStore, + PaymentsStore, SettingsStore, PosStore, FiatStore, @@ -353,6 +357,7 @@ export default class Wallet extends React.Component { ChannelBackupStore.reset(); UTXOsStore.reset(); ContactStore.loadContacts(); + PaymentsStore.getPayments(); NotesStore.loadNoteKeys(); }