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 all 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
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 @@ -324,7 +324,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 @@ -170,10 +170,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
Loading