ThomasV
5 years ago
7 changed files with 222 additions and 1 deletions
@ -0,0 +1,111 @@ |
|||||
|
import copy |
||||
|
from datetime import datetime |
||||
|
from decimal import Decimal |
||||
|
from typing import NamedTuple, Callable, TYPE_CHECKING |
||||
|
|
||||
|
from kivy.app import App |
||||
|
from kivy.factory import Factory |
||||
|
from kivy.properties import ObjectProperty |
||||
|
from kivy.lang import Builder |
||||
|
from kivy.clock import Clock |
||||
|
from kivy.uix.label import Label |
||||
|
from kivy.uix.dropdown import DropDown |
||||
|
from kivy.uix.button import Button |
||||
|
|
||||
|
from electrum.gui.kivy.i18n import _ |
||||
|
|
||||
|
|
||||
|
if TYPE_CHECKING: |
||||
|
from ...main_window import ElectrumWindow |
||||
|
|
||||
|
|
||||
|
Builder.load_string(''' |
||||
|
|
||||
|
<LightningTxDialog> |
||||
|
id: popup |
||||
|
title: _('Lightning Payment') |
||||
|
preimage: '' |
||||
|
is_sent: False |
||||
|
amount_str: '' |
||||
|
fee_str: '' |
||||
|
date_str: '' |
||||
|
payment_hash: '' |
||||
|
description: '' |
||||
|
BoxLayout: |
||||
|
orientation: 'vertical' |
||||
|
ScrollView: |
||||
|
scroll_type: ['bars', 'content'] |
||||
|
bar_width: '25dp' |
||||
|
GridLayout: |
||||
|
height: self.minimum_height |
||||
|
size_hint_y: None |
||||
|
cols: 1 |
||||
|
spacing: '10dp' |
||||
|
padding: '10dp' |
||||
|
GridLayout: |
||||
|
height: self.minimum_height |
||||
|
size_hint_y: None |
||||
|
cols: 1 |
||||
|
spacing: '10dp' |
||||
|
BoxLabel: |
||||
|
text: _('Description') if root.description else '' |
||||
|
value: root.description |
||||
|
BoxLabel: |
||||
|
text: _('Date') |
||||
|
value: root.date_str |
||||
|
BoxLabel: |
||||
|
text: _('Amount sent') if root.is_sent else _('Amount received') |
||||
|
value: root.amount_str |
||||
|
BoxLabel: |
||||
|
text: _('Transaction fee') if root.fee_str else '' |
||||
|
value: root.fee_str |
||||
|
TopLabel: |
||||
|
text: _('Payment hash') + ':' |
||||
|
TxHashLabel: |
||||
|
data: root.payment_hash |
||||
|
name: _('Payment hash') |
||||
|
TopLabel: |
||||
|
text: _('Preimage') |
||||
|
TxHashLabel: |
||||
|
data: root.preimage |
||||
|
name: _('Preimage') |
||||
|
|
||||
|
Widget: |
||||
|
size_hint: 1, 0.1 |
||||
|
|
||||
|
BoxLayout: |
||||
|
size_hint: 1, None |
||||
|
height: '48dp' |
||||
|
Widget |
||||
|
Button: |
||||
|
size_hint: 0.5, None |
||||
|
height: '48dp' |
||||
|
text: _('Close') |
||||
|
on_release: root.dismiss() |
||||
|
''') |
||||
|
|
||||
|
|
||||
|
class ActionButtonOption(NamedTuple): |
||||
|
text: str |
||||
|
func: Callable |
||||
|
enabled: bool |
||||
|
|
||||
|
|
||||
|
class LightningTxDialog(Factory.Popup): |
||||
|
|
||||
|
def __init__(self, app, tx_item): |
||||
|
Factory.Popup.__init__(self) |
||||
|
self.app = app # type: ElectrumWindow |
||||
|
self.wallet = self.app.wallet |
||||
|
self._action_button_fn = lambda btn: None |
||||
|
self.is_sent = bool(tx_item['direction'] is 'sent') |
||||
|
self.description = tx_item['label'] |
||||
|
self.timestamp = tx_item['timestamp'] |
||||
|
self.date_str = datetime.fromtimestamp(self.timestamp).isoformat(' ')[:-3] |
||||
|
self.amount = Decimal(tx_item['amount_msat']) /1000 |
||||
|
self.payment_hash = tx_item['payment_hash'] |
||||
|
self.preimage = tx_item['preimage'] |
||||
|
format_amount = self.app.format_amount_and_units |
||||
|
self.amount_str = format_amount(self.amount) |
||||
|
if self.is_sent: |
||||
|
self.fee_str = format_amount(Decimal(tx_item['fee_msat']) / 1000) |
@ -0,0 +1,84 @@ |
|||||
|
#!/usr/bin/env python |
||||
|
# |
||||
|
# Electrum - lightweight Bitcoin client |
||||
|
# Copyright (C) 2020 The Electrum Developers |
||||
|
# |
||||
|
# Permission is hereby granted, free of charge, to any person |
||||
|
# obtaining a copy of this software and associated documentation files |
||||
|
# (the "Software"), to deal in the Software without restriction, |
||||
|
# including without limitation the rights to use, copy, modify, merge, |
||||
|
# publish, distribute, sublicense, and/or sell copies of the Software, |
||||
|
# and to permit persons to whom the Software is furnished to do so, |
||||
|
# subject to the following conditions: |
||||
|
# |
||||
|
# The above copyright notice and this permission notice shall be |
||||
|
# included in all copies or substantial portions of the Software. |
||||
|
# |
||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
||||
|
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
||||
|
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||||
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
|
# SOFTWARE. |
||||
|
|
||||
|
from typing import TYPE_CHECKING |
||||
|
from decimal import Decimal |
||||
|
import datetime |
||||
|
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QGridLayout |
||||
|
|
||||
|
from electrum.i18n import _ |
||||
|
from .util import WindowModalDialog, ButtonsLineEdit, ColorScheme, Buttons, CloseButton |
||||
|
|
||||
|
if TYPE_CHECKING: |
||||
|
from .main_window import ElectrumWindow |
||||
|
|
||||
|
|
||||
|
|
||||
|
class LightningTxDialog(WindowModalDialog): |
||||
|
|
||||
|
def __init__(self, parent: 'ElectrumWindow', tx_item: dict): |
||||
|
WindowModalDialog.__init__(self, parent, _("Lightning Payment")) |
||||
|
self.parent = parent |
||||
|
self.is_sent = bool(tx_item['direction'] is 'sent') |
||||
|
self.label = tx_item['label'] |
||||
|
self.timestamp = tx_item['timestamp'] |
||||
|
self.amount = Decimal(tx_item['amount_msat']) /1000 |
||||
|
self.payment_hash = tx_item['payment_hash'] |
||||
|
self.preimage = tx_item['preimage'] |
||||
|
self.setMinimumWidth(700) |
||||
|
vbox = QVBoxLayout() |
||||
|
self.setLayout(vbox) |
||||
|
|
||||
|
vbox.addWidget(QLabel(_("Amount:") + self.parent.format_amount_and_units(self.amount))) |
||||
|
if self.is_sent: |
||||
|
fee = Decimal(tx_item['fee_msat']) / 1000 |
||||
|
vbox.addWidget(QLabel(_("Fee:") + self.parent.format_amount_and_units(fee))) |
||||
|
time_str = datetime.datetime.fromtimestamp(self.timestamp).isoformat(' ')[:-3] |
||||
|
vbox.addWidget(QLabel(_("Date:") + time_str)) |
||||
|
|
||||
|
qr_icon = "qrcode_white.png" if ColorScheme.dark_scheme else "qrcode.png" |
||||
|
|
||||
|
vbox.addWidget(QLabel(_("Payment hash:"))) |
||||
|
self.hash_e = ButtonsLineEdit(self.payment_hash) |
||||
|
self.hash_e.addCopyButton(self.parent.app) |
||||
|
self.hash_e.addButton(qr_icon, self.show_qr, _("Show QR Code")) |
||||
|
self.hash_e.setReadOnly(True) |
||||
|
vbox.addWidget(self.hash_e) |
||||
|
|
||||
|
vbox.addWidget(QLabel(_("Preimage:"))) |
||||
|
self.preimage_e = ButtonsLineEdit(self.preimage) |
||||
|
self.preimage_e.addCopyButton(self.parent.app) |
||||
|
self.preimage_e.addButton(qr_icon, self.show_qr, _("Show QR Code")) |
||||
|
self.preimage_e.setReadOnly(True) |
||||
|
vbox.addWidget(self.preimage_e) |
||||
|
|
||||
|
vbox.addLayout(Buttons(CloseButton(self))) |
||||
|
|
||||
|
def show_qr(self): |
||||
|
text = self.address |
||||
|
try: |
||||
|
self.parent.show_qrcode(text, '', parent=self) |
||||
|
except Exception as e: |
||||
|
self.show_message(repr(e)) |
Loading…
Reference in new issue