Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 1eaaf7e

Browse files
authored
Merge pull request #717 from lightninglabs/force-close
Force close inactive and non open channels
2 parents 956ba0e + d5e71d0 commit 1eaaf7e

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/action/channel.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,12 @@ class ChannelAction {
261261
*/
262262
async closeSelectedChannel() {
263263
try {
264-
const { selectedChannel } = this._store;
264+
const { selectedChannel: selected } = this._store;
265265
this._nav.goChannels();
266-
await this.closeChannel({ channelPoint: selectedChannel.channelPoint });
266+
await this.closeChannel({
267+
channelPoint: selected.channelPoint,
268+
force: selected.status !== 'open' || !selected.active,
269+
});
267270
} catch (err) {
268271
this._notification.display({ msg: 'Closing channel failed!', err });
269272
}

test/unit/action/channel.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ describe('Action Channels Unit Tests', () => {
262262
store.selectedChannel = {
263263
channelPoint: 'some-channel-point',
264264
status: 'open',
265+
active: true,
265266
};
266267
sandbox.stub(channel, 'closeChannel');
267268
});
@@ -271,6 +272,27 @@ describe('Action Channels Unit Tests', () => {
271272
expect(nav.goChannels, 'was called once');
272273
expect(channel.closeChannel, 'was called with', {
273274
channelPoint: 'some-channel-point',
275+
force: false,
276+
});
277+
});
278+
279+
it('should force close inactive open channel', async () => {
280+
store.selectedChannel.active = false;
281+
await channel.closeSelectedChannel();
282+
expect(nav.goChannels, 'was called once');
283+
expect(channel.closeChannel, 'was called with', {
284+
channelPoint: 'some-channel-point',
285+
force: true,
286+
});
287+
});
288+
289+
it('should force close pending-open channel', async () => {
290+
store.selectedChannel.status = 'pending-open';
291+
await channel.closeSelectedChannel();
292+
expect(nav.goChannels, 'was called once');
293+
expect(channel.closeChannel, 'was called with', {
294+
channelPoint: 'some-channel-point',
295+
force: true,
274296
});
275297
});
276298

0 commit comments

Comments
 (0)