Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payments: Update getPayments call to limit the number of payments #2614

Merged
merged 5 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion backends/LND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,15 @@ export default class LND {
: undefined,
route_hints: data.route_hints
});
getPayments = () => this.getRequest('/v1/payments?include_incomplete=true');
getPayments = (data?: any) =>
this.getRequest(
`/v1/payments?include_incomplete=true${
data && data?.maxPayments
? `&max_payments=${data.maxPayments}`
: ''
}${data?.reversed ? `&reversed=${data.reversed}` : ''}`
);

getNewAddress = (data: any) => this.getRequest('/v1/newaddress', data);
getNewChangeAddress = (data: any) =>
this.postRequest('/v2/wallet/address/next', data);
Expand Down
9 changes: 7 additions & 2 deletions backends/LightningNodeConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,15 @@ export default class LightningNodeConnect {
route_hints: data.route_hints
})
.then((data: lnrpc.AddInvoiceResponse) => snakeize(data));
getPayments = async () =>
getPayments = async (data: any) =>
await this.lnc.lnd.lightning
.listPayments({
include_incomplete: true
include_incomplete: true,
...(data &&
data?.maxPayments && {
max_payments: data.maxPayments
}),
...(data && data?.reversed && { reversed: data?.reversed })
})
.then((data: lnrpc.ListPaymentsResponse) => snakeize(data));
getNewAddress = async (data: any) =>
Expand Down
10 changes: 8 additions & 2 deletions stores/PaymentsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ export default class PaymentsStore {
};

@action
public getPayments = async () => {
public getPayments = async (
maxPayments: any = undefined,
shubhamkmr04 marked this conversation as resolved.
Show resolved Hide resolved
reversed: boolean = false
) => {
this.loading = true;
try {
const data = await BackendUtils.getPayments();
const data = await BackendUtils.getPayments({
maxPayments,
reversed
});
const payments = data.payments;
this.payments = payments
.slice()
Expand Down
2 changes: 1 addition & 1 deletion views/SendingLightning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default class SendingLightning extends React.Component<
fetchPayments = async () => {
const { PaymentsStore, TransactionsStore } = this.props;
try {
const payments = await PaymentsStore.getPayments();
const payments = await PaymentsStore.getPayments(5, true);
const matchingPayment = payments.find(
(payment: any) =>
payment.payment_preimage ===
Expand Down
Loading