From 37393fe686141f53543a18ec78386424b1291b3a Mon Sep 17 00:00:00 2001 From: ThomasV Date: Thu, 31 May 2018 14:05:09 +0200 Subject: [PATCH] lightning: connect send button --- electrum/commands.py | 3 ++- electrum/gui/qt/main_window.py | 11 ++++++++++- electrum/gui/qt/paytoedit.py | 2 ++ lib/lnworker.py | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/electrum/commands.py b/electrum/commands.py index b97dc427f..8ab3b4221 100644 --- a/electrum/commands.py +++ b/electrum/commands.py @@ -755,7 +755,8 @@ class Commands: @command('wn') def lnpay(self, invoice): - self.wallet.lnworker.pay(invoice) + f = self.wallet.lnworker.pay(invoice) + return f.result() @command('wn') def addinvoice(self, requested_amount, message): diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index 11c2fbc20..9fb335998 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -1547,7 +1547,15 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): def do_preview(self): self.do_send(preview = True) + def pay_lightning_invoice(self, invoice): + f = self.wallet.lnworker.pay(invoice) + self.do_clear() + def do_send(self, preview = False): + if self.payto_e.is_lightning: + self.pay_lightning_invoice(self.payto_e.lightning_invoice) + return + # if run_hook('abort_send', self): return r = self.read_send_tab() @@ -1763,11 +1771,11 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): else: description = '' self.payto_e.setFrozen(True) - self.payto_e.setGreen() self.payto_e.setText(pubkey) self.message_e.setText(description) self.amount_e.setAmount(lnaddr.amount) #self.amount_e.textEdited.emit("") + self.payto_e.is_lightning = True def pay_to_URI(self, URI): if not URI: @@ -1805,6 +1813,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): self.not_enough_funds = False self.payment_request = None self.payto_e.is_pr = False + self.payto_e.is_lightning = False for e in [self.payto_e, self.message_e, self.amount_e, self.fiat_send_e, self.fee_e, self.feerate_e]: e.setText('') diff --git a/electrum/gui/qt/paytoedit.py b/electrum/gui/qt/paytoedit.py index 2b6bfce7b..0661dfa0a 100644 --- a/electrum/gui/qt/paytoedit.py +++ b/electrum/gui/qt/paytoedit.py @@ -58,6 +58,7 @@ class PayToEdit(CompletionTextEdit, ScanQRTextEdit, PrintError): self.errors = [] self.is_pr = False self.is_alias = False + self.is_lightning = False self.update_size() self.payto_address = None self.previous_payto = '' @@ -131,6 +132,7 @@ class PayToEdit(CompletionTextEdit, ScanQRTextEdit, PrintError): return if data.startswith("ln"): self.win.parse_lightning_invoice(data) + self.lightning_invoice = data return try: self.payto_address = self.parse_output(data) diff --git a/lib/lnworker.py b/lib/lnworker.py index c8fa43f09..54cefa28b 100644 --- a/lib/lnworker.py +++ b/lib/lnworker.py @@ -193,7 +193,7 @@ class LNWorker(PrintError): def pay(self, invoice): coro = self._pay_coroutine(invoice) - return asyncio.run_coroutine_threadsafe(coro, self.network.asyncio_loop).result() + return asyncio.run_coroutine_threadsafe(coro, self.network.asyncio_loop) # not aiosafe because we call .result() which will propagate an exception async def _pay_coroutine(self, invoice):