electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

lightning_tx_dialog.py (4121B)


      1 import copy
      2 from datetime import datetime
      3 from decimal import Decimal
      4 from typing import NamedTuple, Callable, TYPE_CHECKING
      5 
      6 from kivy.app import App
      7 from kivy.factory import Factory
      8 from kivy.properties import ObjectProperty
      9 from kivy.lang import Builder
     10 from kivy.clock import Clock
     11 from kivy.uix.label import Label
     12 from kivy.uix.dropdown import DropDown
     13 from kivy.uix.button import Button
     14 
     15 from electrum.gui.kivy.i18n import _
     16 from electrum.invoices import LNInvoice
     17 
     18 
     19 if TYPE_CHECKING:
     20     from ...main_window import ElectrumWindow
     21 
     22 
     23 Builder.load_string('''
     24 
     25 <LightningTxDialog>
     26     id: popup
     27     title: _('Lightning Payment')
     28     preimage: ''
     29     is_sent: False
     30     amount_str: ''
     31     fee_str: ''
     32     date_str: ''
     33     payment_hash: ''
     34     description: ''
     35     invoice: ''
     36     BoxLayout:
     37         orientation: 'vertical'
     38         ScrollView:
     39             scroll_type: ['bars', 'content']
     40             bar_width: '25dp'
     41             GridLayout:
     42                 height: self.minimum_height
     43                 size_hint_y: None
     44                 cols: 1
     45                 spacing: '10dp'
     46                 padding: '10dp'
     47                 GridLayout:
     48                     height: self.minimum_height
     49                     size_hint_y: None
     50                     cols: 1
     51                     spacing: '10dp'
     52                     BoxLabel:
     53                         text: _('Description') if root.description else ''
     54                         value: root.description
     55                     BoxLabel:
     56                         text: _('Date')
     57                         value: root.date_str
     58                     BoxLabel:
     59                         text: _('Amount sent') if root.is_sent else _('Amount received')
     60                         value: root.amount_str
     61                     BoxLabel:
     62                         text: _('Transaction fee') if root.fee_str else ''
     63                         value: root.fee_str
     64                 TopLabel:
     65                     text: _('Payment hash') + ':'
     66                 TxHashLabel:
     67                     data: root.payment_hash
     68                     name: _('Payment hash')
     69                 TopLabel:
     70                     text: _('Preimage')
     71                 TxHashLabel:
     72                     data: root.preimage
     73                     name: _('Preimage')
     74                 TopLabel:
     75                     text: _('Lightning Invoice')
     76                 RefLabel:
     77                     data: root.invoice
     78                     text: root.invoice[:40] + "..."
     79                     name: _('Lightning Invoice')
     80                     show_text_with_qr: False
     81 
     82         Widget:
     83             size_hint: 1, 0.1
     84 
     85         BoxLayout:
     86             size_hint: 1, None
     87             height: '48dp'
     88             Widget
     89             Button:
     90                 size_hint: 0.5, None
     91                 height: '48dp'
     92                 text: _('Close')
     93                 on_release: root.dismiss()
     94 ''')
     95 
     96 
     97 class ActionButtonOption(NamedTuple):
     98     text: str
     99     func: Callable
    100     enabled: bool
    101 
    102 
    103 class LightningTxDialog(Factory.Popup):
    104 
    105     def __init__(self, app, tx_item):
    106         Factory.Popup.__init__(self)
    107         self.app = app  # type: ElectrumWindow
    108         self.wallet = self.app.wallet
    109         self._action_button_fn = lambda btn: None
    110         self.description = tx_item['label']
    111         self.timestamp = tx_item['timestamp']
    112         self.date_str = datetime.fromtimestamp(self.timestamp).isoformat(' ')[:-3]
    113         self.amount = Decimal(tx_item['amount_msat']) /1000
    114         self.payment_hash = tx_item['payment_hash']
    115         self.preimage = tx_item['preimage']
    116         format_amount = self.app.format_amount_and_units
    117         self.is_sent = self.amount < 0
    118         self.amount_str = format_amount(-self.amount if self.is_sent else self.amount)
    119         if tx_item.get('fee_msat'):
    120             self.fee_str = format_amount(Decimal(tx_item['fee_msat']) / 1000)
    121         invoice = (self.app.wallet.get_invoice(self.payment_hash)
    122                    or self.app.wallet.get_request(self.payment_hash))
    123         if invoice:
    124             assert isinstance(invoice, LNInvoice), f"{self.invoice!r}"
    125             self.invoice = invoice.invoice
    126         else:
    127             self.invoice = ''