tkivy: show warning if request/invoice exceeds channel capacity - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 0c3565bd4da1c03981098239723cf10b6dce2d5b DIR parent e362b4b94cb8b6fadbe5b05b2e3566fb47fc4c7e HTML Author: ThomasV <thomasv@electrum.org> Date: Thu, 5 Mar 2020 14:30:01 +0100 kivy: show warning if request/invoice exceeds channel capacity Diffstat: M electrum/gui/kivy/main_window.py | 7 ++----- M electrum/gui/kivy/uix/dialogs/invo… | 28 +++++++++++++++++++++------- M electrum/gui/kivy/uix/dialogs/requ… | 27 ++++++++++++++++++++------- 3 files changed, 43 insertions(+), 19 deletions(-) --- DIR diff --git a/electrum/gui/kivy/main_window.py b/electrum/gui/kivy/main_window.py t@@ -221,7 +221,7 @@ class ElectrumWindow(App): return self.update_tab('receive') if self.request_popup and self.request_popup.key == key: - self.request_popup.set_status(status) + self.request_popup.update_status() if status == PR_PAID: self.show_info(_('Payment Received') + '\n' + key) self._trigger_update_history() t@@ -234,7 +234,7 @@ class ElectrumWindow(App): # todo: update single item self.update_tab('send') if self.invoice_popup and self.invoice_popup.key == key: - self.invoice_popup.set_status(status) + self.invoice_popup.update_status() if status == PR_PAID: self.show_info(_('Payment was sent')) self._trigger_update_history() t@@ -445,7 +445,6 @@ class ElectrumWindow(App): request = self.wallet.get_request(key) data = request['invoice'] if is_lightning else request['URI'] self.request_popup = RequestDialog('Request', data, key, is_lightning=is_lightning) - self.request_popup.set_status(request['status']) self.request_popup.open() def show_invoice(self, is_lightning, key): t@@ -453,10 +452,8 @@ class ElectrumWindow(App): invoice = self.wallet.get_invoice(key) if not invoice: return - status = invoice['status'] data = invoice['invoice'] if is_lightning else key self.invoice_popup = InvoiceDialog('Invoice', data, key) - self.invoice_popup.set_status(status) self.invoice_popup.open() def qr_dialog(self, title, data, show_text=False, text_for_clipboard=None): DIR diff --git a/electrum/gui/kivy/uix/dialogs/invoice_dialog.py b/electrum/gui/kivy/uix/dialogs/invoice_dialog.py t@@ -7,8 +7,8 @@ from kivy.app import App from kivy.clock import Clock from electrum.gui.kivy.i18n import _ -from electrum.util import pr_tooltips, pr_color -from electrum.util import PR_UNKNOWN, PR_UNPAID, PR_FAILED +from electrum.util import pr_tooltips, pr_color, get_request_status +from electrum.util import PR_UNKNOWN, PR_UNPAID, PR_FAILED, PR_TYPE_LN if TYPE_CHECKING: from electrum.gui.kivy.main_window import ElectrumWindow t@@ -17,10 +17,12 @@ if TYPE_CHECKING: Builder.load_string(''' <InvoiceDialog@Popup> id: popup + amount: 0 title: '' data: '' status_color: 1,1,1,1 status_str:'' + warning: '' can_pay: True shaded: False show_text: False t@@ -34,8 +36,13 @@ Builder.load_string(''' TopLabel: text: root.data TopLabel: + text: _('Amount') + ': ' + app.format_amount_and_units(root.amount) + TopLabel: text: _('Status') + ': ' + root.status_str color: root.status_color + TopLabel: + warning: root.warning + color: (0.9, 0.6, 0.3, 1) Widget: size_hint: 1, 0.2 BoxLayout: t@@ -73,12 +80,19 @@ class InvoiceDialog(Factory.Popup): self.title = title self.data = data self.key = key + r = self.app.wallet.get_invoice(key) + self.amount = r.get('amount') + self.is_lightning = r.get('type') == PR_TYPE_LN + self.update_status() - def set_status(self, status): - self.status = status - self.status_str = pr_tooltips[status] - self.status_color = pr_color[status] - self.can_pay = self.status in[PR_UNPAID, PR_FAILED] + def update_status(self): + req = self.app.wallet.get_invoice(self.key) + self.status, self.status_str = get_request_status(req) + self.status_color = pr_color[self.status] + self.can_pay = self.status in [PR_UNPAID, PR_FAILED] + if self.can_pay and self.is_lightning and self.app.wallet.lnworker: + if self.amount and self.amount > self.app.wallet.lnworker.can_send(): + self.warning = _('Warning') + ': ' + _('This amount exceeds the maximum you can currently send with your channels') def on_dismiss(self): self.app.request_popup = None DIR diff --git a/electrum/gui/kivy/uix/dialogs/request_dialog.py b/electrum/gui/kivy/uix/dialogs/request_dialog.py t@@ -5,15 +5,17 @@ from kivy.app import App from kivy.clock import Clock from electrum.gui.kivy.i18n import _ -from electrum.util import pr_tooltips, pr_color -from electrum.util import PR_UNKNOWN +from electrum.util import pr_tooltips, pr_color, get_request_status +from electrum.util import PR_UNKNOWN, PR_UNPAID, PR_FAILED, PR_TYPE_LN Builder.load_string(''' <RequestDialog@Popup> id: popup + amount: 0 title: '' data: '' + warning: '' status_str: '' status_color: 1,1,1,1 shaded: False t@@ -35,8 +37,13 @@ Builder.load_string(''' TopLabel: text: root.data TopLabel: + text: _('Amount') + ': ' + app.format_amount_and_units(root.amount) + TopLabel: text: _('Status') + ': ' + root.status_str color: root.status_color + TopLabel: + text: root.warning + color: (0.9, 0.6, 0.3, 1) Widget: size_hint: 1, 0.2 BoxLayout: t@@ -73,7 +80,10 @@ class RequestDialog(Factory.Popup): self.title = title self.data = data self.key = key - self.is_lightning = is_lightning + r = self.app.wallet.get_request(key) + self.amount = r.get('amount') + self.is_lightning = r.get('type') == PR_TYPE_LN + self.update_status() def on_open(self): data = self.data t@@ -83,10 +93,13 @@ class RequestDialog(Factory.Popup): data = data.upper() self.ids.qr.set_data(data) - def set_status(self, status): - self.status = status - self.status_str = pr_tooltips[status] - self.status_color = pr_color[status] + def update_status(self): + req = self.app.wallet.get_request(self.key) + self.status, self.status_str = get_request_status(req) + self.status_color = pr_color[self.status] + if self.status == PR_UNPAID and self.is_lightning and self.app.wallet.lnworker: + if self.amount and self.amount > self.app.wallet.lnworker.can_receive(): + self.warning = _('Warning') + ': ' + _('This amount exceeds the maximum you can currently receive with your channels') def on_dismiss(self): self.app.request_popup = None