Browse Source

qt/kivy: lightning_tx_dialog: show LN invoice

patch-4
SomberNight 4 years ago
parent
commit
b3b87555dc
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 3
      electrum/gui/kivy/main.kv
  2. 4
      electrum/gui/kivy/main_window.py
  3. 16
      electrum/gui/kivy/uix/dialogs/lightning_tx_dialog.py
  4. 17
      electrum/gui/qt/lightning_tx_dialog.py

3
electrum/gui/kivy/main.kv

@ -157,7 +157,8 @@
touched: False
padding: '10dp', '10dp'
background_color: .3, .3, .3, 1
touch_callback: lambda: app.on_ref_label(self)
show_text_with_qr: True
touch_callback: lambda: app.on_ref_label(self, show_text_with_qr=self.show_text_with_qr)
on_touch_down:
touch = args[1]
touched = bool(self.collide_point(*touch.pos))

4
electrum/gui/kivy/main_window.py

@ -1018,10 +1018,10 @@ class ElectrumWindow(App, Logger):
self._orientation = 'landscape' if width > height else 'portrait'
self._ui_mode = 'tablet' if min(width, height) > inch(3.51) else 'phone'
def on_ref_label(self, label):
def on_ref_label(self, label, *, show_text_with_qr: bool = True):
if not label.data:
return
self.qr_dialog(label.name, label.data, True)
self.qr_dialog(label.name, label.data, show_text_with_qr)
def show_error(self, error, width='200dp', pos=None, arrow_pos=None,
exit=False, icon=f'atlas://{KIVY_GUI_PATH}/theming/light/error', duration=0,

16
electrum/gui/kivy/uix/dialogs/lightning_tx_dialog.py

@ -13,6 +13,7 @@ from kivy.uix.dropdown import DropDown
from kivy.uix.button import Button
from electrum.gui.kivy.i18n import _
from electrum.invoices import LNInvoice
if TYPE_CHECKING:
@ -31,6 +32,7 @@ Builder.load_string('''
date_str: ''
payment_hash: ''
description: ''
invoice: ''
BoxLayout:
orientation: 'vertical'
ScrollView:
@ -69,6 +71,13 @@ Builder.load_string('''
TxHashLabel:
data: root.preimage
name: _('Preimage')
TopLabel:
text: _('Lightning Invoice')
RefLabel:
data: root.invoice
text: root.invoice[:40] + "..."
name: _('Lightning Invoice')
show_text_with_qr: False
Widget:
size_hint: 1, 0.1
@ -109,3 +118,10 @@ class LightningTxDialog(Factory.Popup):
self.amount_str = format_amount(-self.amount if self.is_sent else self.amount)
if tx_item.get('fee_msat'):
self.fee_str = format_amount(Decimal(tx_item['fee_msat']) / 1000)
invoice = (self.app.wallet.get_invoice(self.payment_hash)
or self.app.wallet.get_request(self.payment_hash))
if invoice:
assert isinstance(invoice, LNInvoice), f"{self.invoice!r}"
self.invoice = invoice.invoice
else:
self.invoice = ''

17
electrum/gui/qt/lightning_tx_dialog.py

@ -31,7 +31,10 @@ from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QGridLayout
from electrum.i18n import _
from electrum.invoices import LNInvoice
from .util import WindowModalDialog, ButtonsLineEdit, ColorScheme, Buttons, CloseButton, MONOSPACE_FONT
from .qrtextedit import ShowQRTextEdit
if TYPE_CHECKING:
from .main_window import ElectrumWindow
@ -49,6 +52,14 @@ class LightningTxDialog(WindowModalDialog):
self.amount = Decimal(tx_item['amount_msat']) / 1000
self.payment_hash = tx_item['payment_hash']
self.preimage = tx_item['preimage']
invoice = (self.parent.wallet.get_invoice(self.payment_hash)
or self.parent.wallet.get_request(self.payment_hash))
if invoice:
assert isinstance(invoice, LNInvoice), f"{self.invoice!r}"
self.invoice = invoice.invoice
else:
self.invoice = ''
self.setMinimumWidth(700)
vbox = QVBoxLayout()
self.setLayout(vbox)
@ -83,6 +94,12 @@ class LightningTxDialog(WindowModalDialog):
self.preimage_e.setFont(QFont(MONOSPACE_FONT))
vbox.addWidget(self.preimage_e)
vbox.addWidget(QLabel(_("Lightning Invoice") + ":"))
self.invoice_e = ShowQRTextEdit(self.invoice, config=parent.config)
self.invoice_e.setMaximumHeight(150)
self.invoice_e.addCopyButton(self.parent.app)
vbox.addWidget(self.invoice_e)
vbox.addLayout(Buttons(CloseButton(self)))
def show_qr(self, line_edit, title=''):

Loading…
Cancel
Save