From 6efe5db0d05286b3cd96c62bcb2a8bbf5bb7a628 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Thu, 11 Oct 2018 18:10:31 +0200 Subject: [PATCH] run open_channel in a WaitingDialog --- electrum/gui/qt/channels_list.py | 9 +-------- electrum/gui/qt/main_window.py | 9 +++++++++ electrum/lnworker.py | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/electrum/gui/qt/channels_list.py b/electrum/gui/qt/channels_list.py index 59763c319..761ada824 100644 --- a/electrum/gui/qt/channels_list.py +++ b/electrum/gui/qt/channels_list.py @@ -111,11 +111,4 @@ class ChannelsList(MyTreeWidget): local_amt = local_amt_inp.get_amount() push_amt = push_amt_inp.get_amount() connect_contents = str(remote_nodeid.text()).strip() - self.main_window.protect(self.open_channel, (connect_contents, local_amt, push_amt)) - - def open_channel(self, *args, **kwargs): - try: - self.parent.wallet.lnworker.open_channel(*args, **kwargs) - except Exception as e: - # don't use str(e) because str(asyncio.TimeoutError()) (and many others) is '' - self.parent.show_error('Cannot open channel: %s' % repr(e)) + self.parent.open_channel(connect_contents, local_amt, push_amt) diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index 0d7507fac..7322ffe7a 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -1850,6 +1850,15 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): WaitingDialog(self, _('Broadcasting transaction...'), broadcast_thread, broadcast_done, self.on_error) + @protected + def open_channel(self, *args, **kwargs): + def task(): + return self.wallet.lnworker.open_channel(*args, **kwargs) + def on_success(result): + print(result) + self.show_message(_('Channel open')) + WaitingDialog(self, _('Opening channel...'), task, on_success, self.on_error) + def query_choice(self, msg, choices): # Needed by QtHandler for hardware wallets dialog = WindowModalDialog(self.top_level_window()) diff --git a/electrum/lnworker.py b/electrum/lnworker.py index 7597339b1..4ac8e69f1 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -214,7 +214,7 @@ class LNWorker(PrintError): # TODO maybe filter out onion if not on tor? return random.choice(addr_list) - def open_channel(self, connect_contents, local_amt_sat, push_amt_sat, pw, timeout=5): + def open_channel(self, connect_contents, local_amt_sat, push_amt_sat, password=None, timeout=5): node_id, rest = extract_nodeid(connect_contents) peer = self.peers.get(node_id) if not peer: @@ -231,7 +231,7 @@ class LNWorker(PrintError): except socket.gaierror: raise ConnStringFormatError(_('Hostname does not resolve (getaddrinfo failed)')) peer = self.add_peer(host, port, node_id) - coro = self._open_channel_coroutine(peer, local_amt_sat, push_amt_sat, None if pw == "" else pw) + coro = self._open_channel_coroutine(peer, local_amt_sat, push_amt_sat, password) f = asyncio.run_coroutine_threadsafe(coro, self.network.asyncio_loop) return f.result(timeout)