From 27dcfba98d32c490172e8408ae9e7689a9ca4b5c Mon Sep 17 00:00:00 2001 From: ThomasV Date: Fri, 19 Mar 2021 13:57:17 +0100 Subject: [PATCH] channels_list: improve menu for backups --- electrum/gui/kivy/uix/dialogs/lightning_channels.py | 12 ++++++++---- electrum/gui/qt/channels_list.py | 13 +++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/electrum/gui/kivy/uix/dialogs/lightning_channels.py b/electrum/gui/kivy/uix/dialogs/lightning_channels.py index bd8be068e..d5090d1e1 100644 --- a/electrum/gui/kivy/uix/dialogs/lightning_channels.py +++ b/electrum/gui/kivy/uix/dialogs/lightning_channels.py @@ -9,7 +9,7 @@ from .fee_dialog import FeeDialog from electrum.util import bh2u from electrum.logging import Logger from electrum.lnutil import LOCAL, REMOTE, format_short_channel_id -from electrum.lnchannel import AbstractChannel, Channel +from electrum.lnchannel import AbstractChannel, Channel, ChannelState from electrum.gui.kivy.i18n import _ from .question import Question from electrum.transaction import PartialTxOutput, Transaction @@ -334,8 +334,8 @@ Builder.load_string(r''' : id: popuproot data: [] - is_closed: False - is_redeemed: False + is_funded: False + is_imported: False node_id:'' short_id:'' initiator:'' @@ -401,12 +401,13 @@ Builder.load_string(r''' height: '48dp' text: _('Request force-close') on_release: root.request_force_close() - disabled: root.is_closed + disabled: not root.is_funded Button: size_hint: 0.5, None height: '48dp' text: _('Delete') on_release: root.remove_backup() + disabled: not root.is_imported ''') @@ -416,6 +417,9 @@ class ChannelBackupPopup(Popup, Logger): Popup.__init__(self, **kwargs) Logger.__init__(self) self.chan = chan + self.is_funded = chan.get_state() == ChannelState.FUNDED + self.is_imported = chan.is_imported + self.funding_txid = chan.funding_outpoint.txid self.app = app self.short_id = format_short_channel_id(chan.short_channel_id) self.capacity = self.app.format_amount_and_units(chan.get_capacity()) diff --git a/electrum/gui/qt/channels_list.py b/electrum/gui/qt/channels_list.py index 9cc2f2d0d..773b14c68 100644 --- a/electrum/gui/qt/channels_list.py +++ b/electrum/gui/qt/channels_list.py @@ -11,7 +11,7 @@ from PyQt5.QtGui import QFont, QStandardItem, QBrush from electrum.util import bh2u, NotEnoughFunds, NoDynamicFeeEstimates from electrum.i18n import _ -from electrum.lnchannel import AbstractChannel, PeerState, ChannelBackup, Channel +from electrum.lnchannel import AbstractChannel, PeerState, ChannelBackup, Channel, ChannelState from electrum.wallet import Abstract_Wallet from electrum.lnutil import LOCAL, REMOTE, format_short_channel_id, LN_MAX_FUNDING_SAT from electrum.lnworker import LNWallet @@ -207,9 +207,14 @@ class ChannelsList(MyTreeView): if not item: return channel_id = idx.sibling(idx.row(), self.Columns.NODE_ALIAS).data(ROLE_CHANNEL_ID) - if channel_id in self.lnworker.channel_backups: - menu.addAction(_("Request force-close"), lambda: self.request_force_close(channel_id)) - menu.addAction(_("Delete"), lambda: self.remove_channel_backup(channel_id)) + chan = self.lnworker.channel_backups.get(channel_id) + if chan: + funding_tx = self.parent.wallet.db.get_transaction(chan.funding_outpoint.txid) + menu.addAction(_("View funding transaction"), lambda: self.parent.show_transaction(funding_tx)) + if chan.get_state() == ChannelState.FUNDED: + menu.addAction(_("Request force-close"), lambda: self.request_force_close(channel_id)) + if chan.is_imported: + menu.addAction(_("Delete"), lambda: self.remove_channel_backup(channel_id)) menu.exec_(self.viewport().mapToGlobal(position)) return chan = self.lnworker.channels[channel_id]