Skip to content

Commit

Permalink
Update call and paymentStore to fetch only the last payment after sen…
Browse files Browse the repository at this point in the history
…ding a lightning payment
  • Loading branch information
shubhamkmr04 committed Dec 11, 2024
1 parent 1f7c798 commit 0f9db4f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
6 changes: 3 additions & 3 deletions backends/LND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ export default class LND {
: undefined,
route_hints: data.route_hints
});
getPayments = (data?: { maxPayments?: any }) =>
getPayments = (data?: any) =>
this.getRequest(
`/v1/payments?include_incomplete=true${
data && data?.maxPayments
? `&max_payments=${data.maxPayments}`
data && data?.indexOffSet
? `&index_offset=${data?.indexOffSet}`
: ''
}`
);
Expand Down
5 changes: 4 additions & 1 deletion backends/LightningNodeConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ export default class LightningNodeConnect {
await this.lnc.lnd.lightning
.listPayments({
include_incomplete: true,
max_payment: data && data?.maxPayments
...(data &&
data?.indexOffSet && {
index_offset: data.indexOffSet
})
})
.then((data: lnrpc.ListPaymentsResponse) => snakeize(data));
getNewAddress = async (data: any) =>
Expand Down
12 changes: 10 additions & 2 deletions stores/PaymentsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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 @@ -30,10 +31,16 @@ export default class PaymentsStore {
};

@action
public getPayments = async (maxPayments: any = undefined) => {
public getPayments = async (indexOffSet: any = undefined) => {
this.loading = true;
try {
const data = await BackendUtils.getPayments({ maxPayments });
if (!indexOffSet) {
console.log('Fetching all payments..');
} else console.log('Fetching the last payment', indexOffSet);

const data = await BackendUtils.getPayments({
indexOffSet
});
const payments = data.payments;
this.payments = payments
.slice()
Expand All @@ -42,6 +49,7 @@ 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: 2 additions & 1 deletion views/SendingLightning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ 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(5); // fetch only last 5 payments
const payments = await PaymentsStore.getPayments(last_index_offset);
const matchingPayment = payments.find(
(payment: any) =>
payment.payment_preimage ===
Expand Down
5 changes: 5 additions & 0 deletions views/Wallet/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ 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 @@ -96,6 +97,7 @@ interface WalletProps {
PosStore: PosStore;
UTXOsStore: UTXOsStore;
ContactStore: ContactStore;
PaymentsStore: PaymentsStore;
ModalStore: ModalStore;
SyncStore: SyncStore;
LSPStore: LSPStore;
Expand All @@ -121,6 +123,7 @@ interface WalletState {
'PosStore',
'UTXOsStore',
'ContactStore',
'PaymentsStore',
'ModalStore',
'SyncStore',
'LSPStore',
Expand Down Expand Up @@ -302,6 +305,7 @@ export default class Wallet extends React.Component<WalletProps, WalletState> {
ChannelsStore,
UTXOsStore,
ContactStore,
PaymentsStore,
SettingsStore,
PosStore,
FiatStore,
Expand Down Expand Up @@ -353,6 +357,7 @@ 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 0f9db4f

Please sign in to comment.