Browse Source

kivy: show channel backup before force-close

patch-4
ThomasV 4 years ago
parent
commit
905796baeb
  1. 36
      electrum/gui/kivy/uix/dialogs/lightning_channels.py
  2. 17
      electrum/gui/kivy/uix/dialogs/qr_dialog.py

36
electrum/gui/kivy/uix/dialogs/lightning_channels.py

@ -16,6 +16,8 @@ from electrum.transaction import PartialTxOutput, Transaction
from electrum.util import NotEnoughFunds, NoDynamicFeeEstimates, format_fee_satoshis, quantize_feerate
from electrum.lnutil import ln_dummy_address
from .qr_dialog import QRDialog
if TYPE_CHECKING:
from ...main_window import ElectrumWindow
from electrum import SimpleConfig
@ -520,14 +522,38 @@ class ChannelDetailsPopup(Popup, Logger):
self.app.qr_dialog(_("Channel Backup " + self.chan.short_id_for_GUI()), text, help_text=help_text)
def force_close(self):
Question(_('Force-close channel?'), self._force_close).open()
def _force_close(self, b):
if not b:
return
if self.chan.is_closed():
self.app.show_error(_('Channel already closed'))
return
to_self_delay = self.chan.config[REMOTE].to_self_delay
help_text = ' '.join([
_('If you force-close this channel, the funds you have in it will not be available for {} blocks.').format(to_self_delay),
_('During that time, funds will not be recoverabe from your seed, and may be lost if you lose your device.'),
_('To prevent that, please save this channel backup.'),
_('It may be imported in another wallet with the same seed.')
])
title = _('Save backup and force-close')
data = self.app.wallet.lnworker.export_channel_backup(self.chan.channel_id)
popup = QRDialog(
title, data,
show_text=False,
text_for_clipboard=data,
help_text=help_text,
close_button_text=_('Next'),
on_close=self._confirm_force_close)
popup.open()
def _confirm_force_close(self):
Question(
_('Confirm force close?'),
self._do_force_close,
title=_('Force-close channel'),
no_str=_('Cancel'),
yes_str=_('Proceed')).open()
def _do_force_close(self, b):
if not b:
return
loop = self.app.wallet.network.asyncio_loop
coro = asyncio.run_coroutine_threadsafe(self.app.wallet.lnworker.force_close_channel(self.chan.channel_id), loop)
try:

17
electrum/gui/kivy/uix/dialogs/qr_dialog.py

@ -21,6 +21,7 @@ Builder.load_string('''
data: ''
shaded: False
help_text: ''
close_button_text: ''
AnchorLayout:
anchor_x: 'center'
BoxLayout:
@ -56,14 +57,22 @@ Builder.load_string('''
Button:
size_hint: 1, None
height: '48dp'
text: _('Close')
text: root.close_button_text
on_release:
popup.dismiss()
if root.on_close: root.on_close()
''')
class QRDialog(Factory.Popup):
def __init__(self, title, data, show_text, *,
failure_cb=None, text_for_clipboard=None, help_text=None):
def __init__(
self, title, data, show_text, *,
failure_cb=None,
text_for_clipboard=None,
help_text=None,
close_button_text=None,
on_close=None):
Factory.Popup.__init__(self)
self.app = App.get_running_app() # type: ElectrumWindow
self.title = title
@ -71,6 +80,8 @@ class QRDialog(Factory.Popup):
self.help_text = (data if show_text else help_text) or ''
self.failure_cb = failure_cb
self.text_for_clipboard = text_for_clipboard if text_for_clipboard else data
self.close_button_text = close_button_text or _('Close')
self.on_close = on_close
def on_open(self):
self.ids.qr.set_data(self.data, self.failure_cb)

Loading…
Cancel
Save