qt/kivy: lightning_tx_dialog: show LN invoice
This commit is contained in:
@@ -157,7 +157,8 @@
|
|||||||
touched: False
|
touched: False
|
||||||
padding: '10dp', '10dp'
|
padding: '10dp', '10dp'
|
||||||
background_color: .3, .3, .3, 1
|
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:
|
on_touch_down:
|
||||||
touch = args[1]
|
touch = args[1]
|
||||||
touched = bool(self.collide_point(*touch.pos))
|
touched = bool(self.collide_point(*touch.pos))
|
||||||
|
|||||||
@@ -1018,10 +1018,10 @@ class ElectrumWindow(App, Logger):
|
|||||||
self._orientation = 'landscape' if width > height else 'portrait'
|
self._orientation = 'landscape' if width > height else 'portrait'
|
||||||
self._ui_mode = 'tablet' if min(width, height) > inch(3.51) else 'phone'
|
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:
|
if not label.data:
|
||||||
return
|
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,
|
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,
|
exit=False, icon=f'atlas://{KIVY_GUI_PATH}/theming/light/error', duration=0,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from kivy.uix.dropdown import DropDown
|
|||||||
from kivy.uix.button import Button
|
from kivy.uix.button import Button
|
||||||
|
|
||||||
from electrum.gui.kivy.i18n import _
|
from electrum.gui.kivy.i18n import _
|
||||||
|
from electrum.invoices import LNInvoice
|
||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@@ -31,6 +32,7 @@ Builder.load_string('''
|
|||||||
date_str: ''
|
date_str: ''
|
||||||
payment_hash: ''
|
payment_hash: ''
|
||||||
description: ''
|
description: ''
|
||||||
|
invoice: ''
|
||||||
BoxLayout:
|
BoxLayout:
|
||||||
orientation: 'vertical'
|
orientation: 'vertical'
|
||||||
ScrollView:
|
ScrollView:
|
||||||
@@ -69,6 +71,13 @@ Builder.load_string('''
|
|||||||
TxHashLabel:
|
TxHashLabel:
|
||||||
data: root.preimage
|
data: root.preimage
|
||||||
name: _('Preimage')
|
name: _('Preimage')
|
||||||
|
TopLabel:
|
||||||
|
text: _('Lightning Invoice')
|
||||||
|
RefLabel:
|
||||||
|
data: root.invoice
|
||||||
|
text: root.invoice[:40] + "..."
|
||||||
|
name: _('Lightning Invoice')
|
||||||
|
show_text_with_qr: False
|
||||||
|
|
||||||
Widget:
|
Widget:
|
||||||
size_hint: 1, 0.1
|
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)
|
self.amount_str = format_amount(-self.amount if self.is_sent else self.amount)
|
||||||
if tx_item.get('fee_msat'):
|
if tx_item.get('fee_msat'):
|
||||||
self.fee_str = format_amount(Decimal(tx_item['fee_msat']) / 1000)
|
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 = ''
|
||||||
|
|||||||
@@ -31,7 +31,10 @@ from PyQt5.QtGui import QFont
|
|||||||
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QGridLayout
|
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QGridLayout
|
||||||
|
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
|
from electrum.invoices import LNInvoice
|
||||||
|
|
||||||
from .util import WindowModalDialog, ButtonsLineEdit, ColorScheme, Buttons, CloseButton, MONOSPACE_FONT
|
from .util import WindowModalDialog, ButtonsLineEdit, ColorScheme, Buttons, CloseButton, MONOSPACE_FONT
|
||||||
|
from .qrtextedit import ShowQRTextEdit
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .main_window import ElectrumWindow
|
from .main_window import ElectrumWindow
|
||||||
@@ -49,6 +52,14 @@ class LightningTxDialog(WindowModalDialog):
|
|||||||
self.amount = Decimal(tx_item['amount_msat']) / 1000
|
self.amount = Decimal(tx_item['amount_msat']) / 1000
|
||||||
self.payment_hash = tx_item['payment_hash']
|
self.payment_hash = tx_item['payment_hash']
|
||||||
self.preimage = tx_item['preimage']
|
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)
|
self.setMinimumWidth(700)
|
||||||
vbox = QVBoxLayout()
|
vbox = QVBoxLayout()
|
||||||
self.setLayout(vbox)
|
self.setLayout(vbox)
|
||||||
@@ -83,6 +94,12 @@ class LightningTxDialog(WindowModalDialog):
|
|||||||
self.preimage_e.setFont(QFont(MONOSPACE_FONT))
|
self.preimage_e.setFont(QFont(MONOSPACE_FONT))
|
||||||
vbox.addWidget(self.preimage_e)
|
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)))
|
vbox.addLayout(Buttons(CloseButton(self)))
|
||||||
|
|
||||||
def show_qr(self, line_edit, title=''):
|
def show_qr(self, line_edit, title=''):
|
||||||
|
|||||||
Reference in New Issue
Block a user