Skip to content

Commit

Permalink
Using 'max_payments' and 'reversed' to fetch only last 5 payments aft…
Browse files Browse the repository at this point in the history
…er a successful lightning payment
  • Loading branch information
shubhamkmr04 committed Dec 11, 2024
1 parent 0f9db4f commit 00f7bac
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 21 deletions.
6 changes: 3 additions & 3 deletions backends/LND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions backends/LightningNodeConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
14 changes: 6 additions & 8 deletions stores/PaymentsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default class PaymentsStore {
@observable error = false;
@observable error_msg: string;
@observable payments: Array<Payment | any> = [];
@observable last_index_offset: number;
settingsStore: SettingsStore;
channelsStore: ChannelsStore;

Expand All @@ -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
Expand All @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions views/SendingLightning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===
Expand Down
5 changes: 0 additions & 5 deletions views/Wallet/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ 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';
Expand All @@ -97,7 +96,6 @@ interface WalletProps {
PosStore: PosStore;
UTXOsStore: UTXOsStore;
ContactStore: ContactStore;
PaymentsStore: PaymentsStore;
ModalStore: ModalStore;
SyncStore: SyncStore;
LSPStore: LSPStore;
Expand All @@ -123,7 +121,6 @@ interface WalletState {
'PosStore',
'UTXOsStore',
'ContactStore',
'PaymentsStore',
'ModalStore',
'SyncStore',
'LSPStore',
Expand Down Expand Up @@ -305,7 +302,6 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {
ChannelsStore,
UTXOsStore,
ContactStore,
PaymentsStore,
SettingsStore,
PosStore,
FiatStore,
Expand Down Expand Up @@ -357,7 +353,6 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {
ChannelBackupStore.reset();
UTXOsStore.reset();
ContactStore.loadContacts();
PaymentsStore.getPayments();
NotesStore.loadNoteKeys();
}

Expand Down

0 comments on commit 00f7bac

Please sign in to comment.