diff --git a/backends/EmbeddedLND.ts b/backends/EmbeddedLND.ts index 6734ade67..7504b12b9 100644 --- a/backends/EmbeddedLND.ts +++ b/backends/EmbeddedLND.ts @@ -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) => diff --git a/backends/LND.ts b/backends/LND.ts index 762a0878a..43941a0b0 100644 --- a/backends/LND.ts +++ b/backends/LND.ts @@ -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); diff --git a/backends/LightningNodeConnect.ts b/backends/LightningNodeConnect.ts index be804b9fd..a9726bfc2 100644 --- a/backends/LightningNodeConnect.ts +++ b/backends/LightningNodeConnect.ts @@ -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) => diff --git a/lndmobile/LndMobileInjection.ts b/lndmobile/LndMobileInjection.ts index 17bbd7c4f..25b28eb1f 100644 --- a/lndmobile/LndMobileInjection.ts +++ b/lndmobile/LndMobileInjection.ts @@ -224,7 +224,10 @@ export interface ILndMobileInjections { amount?: Long, routeHints?: lnrpc.IRouteHint[] ) => Promise; - listPayments: () => Promise; + listPayments: (params?: { + maxPayments?: number; + reversed?: boolean; + }) => Promise; subscribeChannelGraph: () => Promise; sendKeysendPaymentV2: ({ amt, diff --git a/lndmobile/index.ts b/lndmobile/index.ts index 61c1d90f1..b585213ab 100644 --- a/lndmobile/index.ts +++ b/lndmobile/index.ts @@ -721,7 +721,10 @@ export const listPeers = async (): Promise => { /** * @throws */ -export const listPayments = async (): Promise => { +export const listPayments = async (params?: { + maxPayments?: number; + reversed?: boolean; +}): Promise => { const response = await sendCommand< lnrpc.IListPaymentsRequest, lnrpc.ListPaymentsRequest, @@ -731,7 +734,11 @@ export const listPayments = async (): Promise => { 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; diff --git a/stores/PaymentsStore.ts b/stores/PaymentsStore.ts index 5c13c4bfa..ba22e5440 100644 --- a/stores/PaymentsStore.ts +++ b/stores/PaymentsStore.ts @@ -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() diff --git a/views/SendingLightning.tsx b/views/SendingLightning.tsx index 8beab8ec9..5cb56e861 100644 --- a/views/SendingLightning.tsx +++ b/views/SendingLightning.tsx @@ -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 === @@ -406,7 +409,6 @@ export default class SendingLightning extends React.Component< secondary buttonStyle={{ height: 40, width: '100%' }} containerStyle={{ - backgroundColor: 'red', maxWidth: '45%', margin: 10 }}