1
0

Change warning shown on first channel creation

Qt: if created channel is not recoverable, show channel backup after creation
This commit is contained in:
ThomasV
2021-03-23 17:25:27 +01:00
parent f2aa52e5aa
commit 18d7db12da
8 changed files with 63 additions and 48 deletions

View File

@@ -24,6 +24,8 @@ from electrum import blockchain
from electrum.network import Network, TxBroadcastError, BestEffortRequestFailed
from electrum.interface import PREFERRED_NETWORK_PROTOCOL, ServerAddr
from electrum.logging import Logger
from electrum.gui import messages
from .i18n import _
from . import KIVY_GUI_PATH
@@ -727,14 +729,10 @@ class ElectrumWindow(App, Logger):
if not self.wallet.has_lightning():
self.show_error(_('Lightning is not enabled for this wallet'))
return
if not self.wallet.lnworker.channels:
warning1 = _("Lightning support in Electrum is experimental. "
"Do not put large amounts in lightning channels.")
warning2 = _("Funds stored in lightning channels are not recoverable "
"from your seed. You must backup your wallet file everytime "
"you create a new channel.")
if not self.wallet.lnworker.channels and not self.wallet.lnworker.channel_backups:
warning = _(messages.MSG_LIGHTNING_WARNING)
d = Question(_('Do you want to create your first channel?') +
'\n\n' + warning1 + '\n\n' + warning2, self.open_channel_dialog_with_warning)
'\n\n' + warning, self.open_channel_dialog_with_warning)
d.open()
else:
d = LightningOpenChannelDialog(self)
@@ -1295,7 +1293,7 @@ class ElectrumWindow(App, Logger):
def save_backup(self):
if platform != 'android':
backup_dir = util.get_backup_dir(self.electrum_config)
backup_dir = self.electrum_config.get_backup_dir()
if backup_dir:
self._save_backup(backup_dir)
else:

View File

@@ -3,6 +3,7 @@ from typing import TYPE_CHECKING
from kivy.lang import Builder
from kivy.factory import Factory
from electrum.gui import messages
from electrum.gui.kivy.i18n import _
from electrum.lnaddr import lndecode
from electrum.util import bh2u
@@ -214,11 +215,7 @@ class LightningOpenChannelDialog(Factory.Popup, Logger):
self.maybe_show_funding_tx(chan, funding_tx)
else:
title = _('Save backup')
help_text = ' '.join([
_('Your wallet does not have recoverable channels.'),
_('Please save this channel backup on another device.'),
_('It may be imported in another Electrum wallet with the same seed.')
])
help_text = _(messages.MSG_CREATED_NON_RECOVERABLE_CHANNEL)
data = lnworker.export_channel_backup(chan.channel_id)
popup = QRDialog(
title, data,

View File

@@ -9,3 +9,13 @@ If this is enabled, other nodes cannot open a channel to you. Channel recovery d
"""
MSG_REQUEST_FORCE_CLOSE = """If you choose to request force-close, your node will pretend that it has lost its data and ask the remote node to broadcast their latest state. Doing so from time to time helps make sure that nodes are honest, because your node can punish them if they broadcast a revoked state."""
MSG_CREATED_NON_RECOVERABLE_CHANNEL = """
The channel you created is not recoverable from seed.
To prevent fund losses, please save this backup on another device.
It may be imported in another Electrum wallet with the same seed.
"""
MSG_LIGHTNING_WARNING = """
Electrum uses static channel backups. If you lose your wallet file, you will need to request your channel to be force-closed by the remote peer in order to recover your funds. This assumes that the remote peer is reachable, and has not lost its own data.
"""

View File

@@ -356,15 +356,11 @@ class ChannelsList(MyTreeView):
return h
def new_channel_with_warning(self):
if not self.parent.wallet.lnworker.channels:
warning = _("Lightning support in Electrum is experimental. "
"Do not put large amounts in lightning channels.")
if not self.parent.wallet.lnworker.has_recoverable_channels():
warning += _("Funds stored in lightning channels are not recoverable from your seed. "
"You must backup your wallet file everytime you create a new channel.")
lnworker = self.parent.wallet.lnworker
if not lnworker.channels and not lnworker.channel_backups:
warning = _(messages.MSG_LIGHTNING_WARNING)
answer = self.parent.question(
_('Do you want to create your first channel?') + '\n\n' +
_('WARNING') + ': ' + '\n\n' + warning)
_('Do you want to create your first channel?') + '\n\n' + warning)
if answer:
self.new_channel_dialog()
else:

View File

@@ -50,12 +50,13 @@ from PyQt5.QtWidgets import (QMessageBox, QComboBox, QSystemTrayIcon, QTabWidget
QMenu, QAction, QStackedWidget, QToolButton)
import electrum
from electrum.gui import messages
from electrum import (keystore, ecc, constants, util, bitcoin, commands,
paymentrequest, lnutil)
from electrum.bitcoin import COIN, is_address
from electrum.plugin import run_hook, BasePlugin
from electrum.i18n import _
from electrum.util import (format_time, get_backup_dir,
from electrum.util import (format_time,
UserCancelled, profiler,
bh2u, bfh, InvalidPassword,
UserFacingException,
@@ -627,7 +628,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
vbox.addLayout(Buttons(CancelButton(d), OkButton(d)))
if not d.exec_():
return False
backup_dir = get_backup_dir(self.config)
backup_dir = self.config.get_backup_dir()
if backup_dir is None:
self.show_message(_("You need to configure a backup directory in your preferences"), title=_("Backup not configured"))
return
@@ -1831,24 +1832,37 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
funding_sat=funding_sat,
push_amt_sat=push_amt,
password=password)
def on_success(args):
chan, funding_tx = args
n = chan.constraints.funding_txn_minimum_depth
message = '\n'.join([
_('Channel established.'),
_('Remote peer ID') + ':' + chan.node_id.hex(),
_('This channel will be usable after {} confirmations').format(n)
])
if not funding_tx.is_complete():
message += '\n\n' + _('Please sign and broadcast the funding transaction')
self.show_message(message)
if not funding_tx.is_complete():
self.show_transaction(funding_tx)
def on_failure(exc_info):
type_, e, traceback = exc_info
self.show_error(_('Could not open channel: {}').format(repr(e)))
WaitingDialog(self, _('Opening channel...'), task, on_success, on_failure)
WaitingDialog(self, _('Opening channel...'), task, self.on_open_channel_success, on_failure)
def on_open_channel_success(self, args):
chan, funding_tx = args
lnworker = self.wallet.lnworker
if not lnworker.has_recoverable_channels():
backup_dir = self.config.get_backup_dir()
if backup_dir is not None:
self.show_message(_(f'Your wallet backup has been updated in {backup_dir}'))
else:
data = lnworker.export_channel_backup(chan.channel_id)
help_text = _(messages.MSG_CREATED_NON_RECOVERABLE_CHANNEL)
self.show_qrcode(
data, _('Save channel backup'),
help_text=help_text,
show_copy_text_btn=True)
n = chan.constraints.funding_txn_minimum_depth
message = '\n'.join([
_('Channel established.'),
_('Remote peer ID') + ':' + chan.node_id.hex(),
_('This channel will be usable after {} confirmations').format(n)
])
if not funding_tx.is_complete():
message += '\n\n' + _('Please sign and broadcast the funding transaction')
self.show_message(message)
self.show_transaction(funding_tx)
else:
self.show_message(message)
def query_choice(self, msg, choices):
# Needed by QtHandler for hardware wallets