Skip to content

Commit

Permalink
Merge pull request #2614 from shubhamkmr04/shubham/limit-fetching-pay…
Browse files Browse the repository at this point in the history
…ment

Payments: Update `getPayments` call to limit the number of payments
  • Loading branch information
kaloudis authored Dec 19, 2024
2 parents db8bd7d + bba70b5 commit 9042771
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 11 deletions.
5 changes: 4 additions & 1 deletion backends/EmbeddedLND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ export default class EmbeddedLND extends LND {
preimage: data.preimage,
route_hints: data.route_hints
});
getPayments = async () => await listPayments();
getPayments = async (params?: {
maxPayments?: number;
reversed?: boolean;
}) => await listPayments(params);
getNewAddress = async (data: any) =>
await newAddress(data.type, data.account);
getNewChangeAddress = async (data: any) =>
Expand Down
8 changes: 7 additions & 1 deletion backends/LND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,13 @@ export default class LND {
: undefined,
route_hints: data.route_hints
});
getPayments = () => this.getRequest('/v1/payments?include_incomplete=true');
getPayments = (params?: { maxPayments?: number; reversed?: boolean }) =>
this.getRequest(
`/v1/payments?include_incomplete=true${
params?.maxPayments ? `&max_payments=${params.maxPayments}` : ''
}${params?.reversed ? `&reversed=${params.reversed}` : ''}`
);

getNewAddress = (data: any) => this.getRequest('/v1/newaddress', data);
getNewChangeAddress = (data: any) =>
this.postRequest('/v2/wallet/address/next', data);
Expand Down
11 changes: 9 additions & 2 deletions backends/LightningNodeConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,17 @@ export default class LightningNodeConnect {
route_hints: data.route_hints
})
.then((data: lnrpc.AddInvoiceResponse) => snakeize(data));
getPayments = async () =>
getPayments = async (params?: {
maxPayments?: number;
reversed?: boolean;
}) =>
await this.lnc.lnd.lightning
.listPayments({
include_incomplete: true
include_incomplete: true,
...(params?.maxPayments && {
max_payments: params.maxPayments
}),
...(params?.reversed && { reversed: params.reversed })
})
.then((data: lnrpc.ListPaymentsResponse) => snakeize(data));
getNewAddress = async (data: any) =>
Expand Down
5 changes: 4 additions & 1 deletion lndmobile/LndMobileInjection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ export interface ILndMobileInjections {
amount?: Long,
routeHints?: lnrpc.IRouteHint[]
) => Promise<lnrpc.QueryRoutesResponse>;
listPayments: () => Promise<lnrpc.ListPaymentsResponse>;
listPayments: (params?: {
maxPayments?: number;
reversed?: boolean;
}) => Promise<lnrpc.ListPaymentsResponse>;
subscribeChannelGraph: () => Promise<string>;
sendKeysendPaymentV2: ({
amt,
Expand Down
11 changes: 9 additions & 2 deletions lndmobile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,10 @@ export const listPeers = async (): Promise<lnrpc.ListPeersResponse> => {
/**
* @throws
*/
export const listPayments = async (): Promise<lnrpc.ListPaymentsResponse> => {
export const listPayments = async (params?: {
maxPayments?: number;
reversed?: boolean;
}): Promise<lnrpc.ListPaymentsResponse> => {
const response = await sendCommand<
lnrpc.IListPaymentsRequest,
lnrpc.ListPaymentsRequest,
Expand All @@ -731,7 +734,11 @@ export const listPayments = async (): Promise<lnrpc.ListPaymentsResponse> => {
response: lnrpc.ListPaymentsResponse,
method: 'ListPayments',
options: {
include_incomplete: true
include_incomplete: true,
...(params?.maxPayments && {
max_payments: Long.fromValue(params.maxPayments)
}),
...(params?.reversed && { reversed: params.reversed })
}
});
return response;
Expand Down
7 changes: 5 additions & 2 deletions stores/PaymentsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ export default class PaymentsStore {
};

@action
public getPayments = async () => {
public getPayments = async (params?: {
maxPayments?: number;
reversed?: boolean;
}) => {
this.loading = true;
try {
const data = await BackendUtils.getPayments();
const data = await BackendUtils.getPayments(params);
const payments = data.payments;
this.payments = payments
.slice()
Expand Down
6 changes: 4 additions & 2 deletions views/SendingLightning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ 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({
maxPayments: 5,
reversed: true
});
const matchingPayment = payments.find(
(payment: any) =>
payment.payment_preimage ===
Expand Down Expand Up @@ -406,7 +409,6 @@ export default class SendingLightning extends React.Component<
secondary
buttonStyle={{ height: 40, width: '100%' }}
containerStyle={{
backgroundColor: 'red',
maxWidth: '45%',
margin: 10
}}
Expand Down

0 comments on commit 9042771

Please sign in to comment.