Browse Source

kivy: show warning if request/invoice exceeds channel capacity

master
ThomasV 6 years ago
parent
commit
0c3565bd4d
  1. 7
      electrum/gui/kivy/main_window.py
  2. 26
      electrum/gui/kivy/uix/dialogs/invoice_dialog.py
  3. 27
      electrum/gui/kivy/uix/dialogs/request_dialog.py

7
electrum/gui/kivy/main_window.py

@ -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()
@ -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()
@ -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):
@ -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):

26
electrum/gui/kivy/uix/dialogs/invoice_dialog.py

@ -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
@ -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
@ -33,9 +35,14 @@ Builder.load_string('''
spacing: '10dp'
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:
@ -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]
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

27
electrum/gui/kivy/uix/dialogs/request_dialog.py

@ -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
@ -34,9 +36,14 @@ Builder.load_string('''
if self.collide_point(*touch.pos): self.shaded = not self.shaded
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:
@ -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
@ -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

Loading…
Cancel
Save