mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 08:51:32 +00:00
qt: easier import/export of channel backups
This commit is contained in:
parent
12e2beadd9
commit
182c192558
4 changed files with 42 additions and 11 deletions
|
@ -9,6 +9,7 @@ from kivy.clock import Clock
|
|||
|
||||
from electrum.util import bh2u
|
||||
from electrum.lnutil import LOCAL, REMOTE, format_short_channel_id
|
||||
from electrum.lnchannel import AbstractChannel, Channel
|
||||
from electrum.gui.kivy.i18n import _
|
||||
from .question import Question
|
||||
|
||||
|
@ -285,7 +286,7 @@ Builder.load_string(r'''
|
|||
|
||||
class ChannelBackupPopup(Popup):
|
||||
|
||||
def __init__(self, chan, app, **kwargs):
|
||||
def __init__(self, chan: AbstractChannel, app: 'ElectrumWindow', **kwargs):
|
||||
super(ChannelBackupPopup,self).__init__(**kwargs)
|
||||
self.chan = chan
|
||||
self.app = app
|
||||
|
@ -320,7 +321,7 @@ class ChannelBackupPopup(Popup):
|
|||
|
||||
class ChannelDetailsPopup(Popup):
|
||||
|
||||
def __init__(self, chan, app, **kwargs):
|
||||
def __init__(self, chan: Channel, app: 'ElectrumWindow', **kwargs):
|
||||
super(ChannelDetailsPopup,self).__init__(**kwargs)
|
||||
self.is_closed = chan.is_closed()
|
||||
self.is_redeemed = chan.is_redeemed()
|
||||
|
|
|
@ -132,7 +132,8 @@ class ChannelsList(MyTreeView):
|
|||
_("If you lose your wallet file, the only thing you can do with a backup is to request your channel to be closed, so that your funds will be sent on-chain."),
|
||||
])
|
||||
data = self.lnworker.export_channel_backup(channel_id)
|
||||
self.main_window.show_qrcode(data, 'channel backup', help_text=msg)
|
||||
self.main_window.show_qrcode(data, 'channel backup', help_text=msg,
|
||||
show_copy_text_btn=True)
|
||||
|
||||
def request_force_close(self, channel_id):
|
||||
def task():
|
||||
|
@ -147,6 +148,8 @@ class ChannelsList(MyTreeView):
|
|||
menu.setSeparatorsCollapsible(True) # consecutive separators are merged together
|
||||
selected = self.selected_in_column(self.Columns.NODE_ALIAS)
|
||||
if not selected:
|
||||
menu.addAction(_("Import channel backup"), lambda: self.parent.do_process_from_text_channel_backup())
|
||||
menu.exec_(self.viewport().mapToGlobal(position))
|
||||
return
|
||||
multi_select = len(selected) > 1
|
||||
if multi_select:
|
||||
|
|
|
@ -585,7 +585,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||
|
||||
def select_backup_dir(self, b):
|
||||
name = self.config.get('backup_dir', '')
|
||||
dirname = QFileDialog.getExistingDirectory(self, "Select your SSL certificate file", name)
|
||||
dirname = QFileDialog.getExistingDirectory(self, "Select your wallet backup directory", name)
|
||||
if dirname:
|
||||
self.config.set_key('backup_dir', dirname)
|
||||
self.backup_dir_e.setText(dirname)
|
||||
|
@ -2395,10 +2395,12 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||
d = SeedDialog(self, seed, passphrase)
|
||||
d.exec_()
|
||||
|
||||
def show_qrcode(self, data, title = _("QR code"), parent=None, help_text=None):
|
||||
def show_qrcode(self, data, title = _("QR code"), parent=None, *,
|
||||
help_text=None, show_copy_text_btn=False):
|
||||
if not data:
|
||||
return
|
||||
d = QRDialog(data, parent or self, title, help_text=help_text)
|
||||
d = QRDialog(data, parent or self, title, help_text=help_text,
|
||||
show_copy_text_btn=show_copy_text_btn)
|
||||
d.exec_()
|
||||
|
||||
@protected
|
||||
|
@ -2605,7 +2607,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||
self.show_critical(_("Electrum was unable to parse your transaction") + ":\n" + repr(e))
|
||||
return
|
||||
|
||||
def import_channel_backup(self, encrypted):
|
||||
def import_channel_backup(self, encrypted: str):
|
||||
if not self.question('Import channel backup?'):
|
||||
return
|
||||
try:
|
||||
|
@ -2658,6 +2660,13 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
|
|||
if tx:
|
||||
self.show_transaction(tx)
|
||||
|
||||
def do_process_from_text_channel_backup(self):
|
||||
text = text_dialog(self, _('Input channel backup'), _("Channel Backup:"), _("Load backup"))
|
||||
if not text:
|
||||
return
|
||||
if text.startswith('channel_backup:'):
|
||||
self.import_channel_backup(text)
|
||||
|
||||
def do_process_from_file(self):
|
||||
tx = self.read_tx_from_file()
|
||||
if tx:
|
||||
|
|
|
@ -93,7 +93,16 @@ class QRCodeWidget(QWidget):
|
|||
|
||||
class QRDialog(WindowModalDialog):
|
||||
|
||||
def __init__(self, data, parent=None, title = "", show_text=False, help_text=None):
|
||||
def __init__(
|
||||
self,
|
||||
data,
|
||||
parent=None,
|
||||
title="",
|
||||
show_text=False,
|
||||
*,
|
||||
help_text=None,
|
||||
show_copy_text_btn=False,
|
||||
):
|
||||
WindowModalDialog.__init__(self, parent, title)
|
||||
|
||||
vbox = QVBoxLayout()
|
||||
|
@ -119,14 +128,23 @@ class QRDialog(WindowModalDialog):
|
|||
p.save(filename, 'png')
|
||||
self.show_message(_("QR code saved to file") + " " + filename)
|
||||
|
||||
def copy_to_clipboard():
|
||||
def copy_image_to_clipboard():
|
||||
p = qrw.grab()
|
||||
QApplication.clipboard().setPixmap(p)
|
||||
self.show_message(_("QR code copied to clipboard"))
|
||||
|
||||
b = QPushButton(_("Copy"))
|
||||
def copy_text_to_clipboard():
|
||||
QApplication.clipboard().setText(data)
|
||||
self.show_message(_("Text copied to clipboard"))
|
||||
|
||||
b = QPushButton(_("Copy Image"))
|
||||
hbox.addWidget(b)
|
||||
b.clicked.connect(copy_to_clipboard)
|
||||
b.clicked.connect(copy_image_to_clipboard)
|
||||
|
||||
if show_copy_text_btn:
|
||||
b = QPushButton(_("Copy Text"))
|
||||
hbox.addWidget(b)
|
||||
b.clicked.connect(copy_text_to_clipboard)
|
||||
|
||||
b = QPushButton(_("Save"))
|
||||
hbox.addWidget(b)
|
||||
|
|
Loading…
Add table
Reference in a new issue