Skip to content

Commit

Permalink
Merge pull request #1370 from kaloudis/get-channels-patch
Browse files Browse the repository at this point in the history
stores/ChannelsStore: only make calls to pending and closed channels if supported
  • Loading branch information
kaloudis authored Mar 14, 2023
2 parents b4e856e + 5cc8490 commit c8c1ba2
Showing 1 changed file with 54 additions and 50 deletions.
104 changes: 54 additions & 50 deletions stores/ChannelsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,57 +192,61 @@ export default class ChannelsStore {
this.getChannelsError();
});

BackendUtils.getPendingChannels()
.then((data: any) => {
const pendingOpenChannels = data.pending_open_channels.map(
(pending: any) => {
pending.channel.pendingOpen = true;
return new Channel(pending.channel);
}
);
const pendingCloseChannels = data.pending_closing_channels.map(
(pending: any) => {
pending.channel.pendingClose = true;
pending.channel.closing_txid = pending.closing_txid;
return new Channel(pending.channel);
}
);
const forceCloseChannels =
data.pending_force_closing_channels.map((pending: any) => {
pending.channel.blocks_til_maturity =
pending.blocks_til_maturity;
pending.channel.forceClose = true;
pending.channel.closing_txid = pending.closing_txid;
return new Channel(pending.channel);
});
const waitCloseChannels = data.waiting_close_channels.map(
(pending: any) => {
pending.channel.closing = true;
return new Channel(pending.channel);
}
);
this.pendingChannels = pendingOpenChannels
.concat(pendingCloseChannels)
.concat(forceCloseChannels)
.concat(waitCloseChannels);
this.error = false;
})
.catch(() => {
this.getChannelsError();
});
if (BackendUtils.supportsPendingChannels()) {
BackendUtils.getPendingChannels()
.then((data: any) => {
const pendingOpenChannels = data.pending_open_channels.map(
(pending: any) => {
pending.channel.pendingOpen = true;
return new Channel(pending.channel);
}
);
const pendingCloseChannels =
data.pending_closing_channels.map((pending: any) => {
pending.channel.pendingClose = true;
pending.channel.closing_txid = pending.closing_txid;
return new Channel(pending.channel);
});
const forceCloseChannels =
data.pending_force_closing_channels.map(
(pending: any) => {
pending.channel.blocks_til_maturity =
pending.blocks_til_maturity;
pending.channel.forceClose = true;
pending.channel.closing_txid =
pending.closing_txid;
return new Channel(pending.channel);
}
);
const waitCloseChannels = data.waiting_close_channels.map(
(pending: any) => {
pending.channel.closing = true;
return new Channel(pending.channel);
}
);
this.pendingChannels = pendingOpenChannels
.concat(pendingCloseChannels)
.concat(forceCloseChannels)
.concat(waitCloseChannels);
this.error = false;
})
.catch(() => {
this.getChannelsError();
});

BackendUtils.getClosedChannels()
.then((data: any) => {
const closedChannels = data.channels.map(
(channel: any) => new ClosedChannel(channel)
);
this.closedChannels = closedChannels;
this.error = false;
this.loading = false;
})
.catch(() => {
this.getChannelsError();
});
BackendUtils.getClosedChannels()
.then((data: any) => {
const closedChannels = data.channels.map(
(channel: any) => new ClosedChannel(channel)
);
this.closedChannels = closedChannels;
this.error = false;
this.loading = false;
})
.catch(() => {
this.getChannelsError();
});
}
};

@action
Expand Down

0 comments on commit c8c1ba2

Please sign in to comment.