electrum-bitcoinprivate/gui/kivy/uix/dialogs/tx_dialog.py

155 lines
5.2 KiB
Python
Raw Normal View History

2016-02-12 23:15:06 -08:00
from kivy.app import App
from kivy.factory import Factory
from kivy.properties import ObjectProperty
from kivy.lang import Builder
2016-02-13 01:33:49 -08:00
from kivy.clock import Clock
2016-02-17 01:53:14 -08:00
from kivy.uix.label import Label
2016-02-12 23:15:06 -08:00
2019-12-24 03:21:35 -08:00
from electrum_bitcoinprivate_gui.kivy.i18n import _
2016-02-12 23:15:06 -08:00
from datetime import datetime
2019-12-24 03:21:35 -08:00
from electrum_bitcoinprivate.util import InvalidPassword
2016-02-12 23:15:06 -08:00
Builder.load_string('''
<TxDialog>
2016-02-12 23:15:06 -08:00
id: popup
title: _('Transaction')
2016-02-16 01:56:58 -08:00
is_mine: True
2016-02-12 23:15:06 -08:00
can_sign: False
can_broadcast: False
fee_str: ''
2016-02-16 01:56:58 -08:00
date_str: ''
date_label:''
2016-02-12 23:15:06 -08:00
amount_str: ''
2016-02-17 01:53:14 -08:00
tx_hash: ''
2016-02-12 23:15:06 -08:00
status_str: ''
2016-02-16 01:56:58 -08:00
description: ''
2016-02-17 01:53:14 -08:00
outputs_str: ''
BoxLayout:
orientation: 'vertical'
ScrollView:
2016-02-17 01:53:14 -08:00
GridLayout:
height: self.minimum_height
2016-02-17 06:19:09 -08:00
size_hint_y: None
cols: 1
2016-02-17 01:53:14 -08:00
spacing: '10dp'
padding: '10dp'
GridLayout:
height: self.minimum_height
size_hint_y: None
cols: 1
spacing: '10dp'
BoxLabel:
text: _('Status')
value: root.status_str
BoxLabel:
text: _('Description') if root.description else ''
value: root.description
BoxLabel:
text: root.date_label
value: root.date_str
BoxLabel:
text: _('Amount sent') if root.is_mine else _('Amount received')
value: root.amount_str
BoxLabel:
text: _('Transaction fee') if root.fee_str else ''
value: root.fee_str
2016-02-17 01:53:14 -08:00
TopLabel:
text: _('Outputs') + ':'
OutputList:
height: self.minimum_height
size_hint: 1, None
id: output_list
2016-02-17 01:53:14 -08:00
TopLabel:
text: _('Transaction ID') + ':' if root.tx_hash else ''
2016-02-17 09:04:34 -08:00
TxHashLabel:
2016-02-18 04:53:23 -08:00
data: root.tx_hash
name: _('Transaction ID')
Widget:
size_hint: 1, 0.1
2016-02-16 01:56:58 -08:00
BoxLayout:
size_hint: 1, None
height: '48dp'
Button:
size_hint: 0.5, None
height: '48dp'
text: _('Sign') if root.can_sign else _('Broadcast') if root.can_broadcast else ''
disabled: not(root.can_sign or root.can_broadcast)
2016-06-08 03:55:42 -07:00
opacity: 0 if self.disabled else 1
on_release:
if root.can_sign: root.do_sign()
if root.can_broadcast: root.do_broadcast()
IconButton:
size_hint: 0.5, None
height: '48dp'
icon: 'atlas://gui/kivy/theming/light/qrcode'
on_release: root.show_qr()
Button:
size_hint: 0.5, None
2016-02-16 01:56:58 -08:00
height: '48dp'
text: _('Close')
2016-06-09 10:48:06 -07:00
on_release: root.dismiss()
2016-02-12 23:15:06 -08:00
''')
2016-02-17 02:40:05 -08:00
2016-02-12 23:15:06 -08:00
class TxDialog(Factory.Popup):
def __init__(self, app, tx):
Factory.Popup.__init__(self)
self.app = app
self.wallet = self.app.wallet
self.tx = tx
2016-02-17 06:19:09 -08:00
def on_open(self):
2016-02-12 23:15:06 -08:00
self.update()
def update(self):
format_amount = self.app.format_amount_and_units
tx_hash, self.status_str, self.description, self.can_broadcast, amount, fee, height, conf, timestamp, exp_n = self.wallet.get_tx_info(self.tx)
2016-06-09 09:09:45 -07:00
self.tx_hash = tx_hash or ''
if timestamp:
self.date_label = _('Date')
self.date_str = datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
elif exp_n:
self.date_label = _('Mempool depth')
self.date_str = _('{} from tip').format('%.2f MB'%(exp_n/1000000))
else:
self.date_label = ''
self.date_str = ''
2016-06-08 02:06:51 -07:00
if amount is None:
2016-02-12 23:15:06 -08:00
self.amount_str = _("Transaction unrelated to your wallet")
2016-06-08 02:06:51 -07:00
elif amount > 0:
self.is_mine = False
self.amount_str = format_amount(amount)
2016-06-08 02:06:51 -07:00
else:
self.is_mine = True
self.amount_str = format_amount(-amount)
self.fee_str = format_amount(fee) if fee is not None else _('unknown')
2016-02-12 23:15:06 -08:00
self.can_sign = self.wallet.can_sign(self.tx)
2016-02-17 06:19:09 -08:00
self.ids.output_list.update(self.tx.outputs())
2016-02-17 01:53:14 -08:00
2016-02-12 23:15:06 -08:00
def do_sign(self):
2016-02-13 01:33:49 -08:00
self.app.protected(_("Enter your PIN code in order to sign this transaction"), self._do_sign, ())
2016-02-12 23:15:06 -08:00
def _do_sign(self, password):
2016-02-13 02:16:45 -08:00
self.status_str = _('Signing') + '...'
2016-02-13 01:33:49 -08:00
Clock.schedule_once(lambda dt: self.__do_sign(password), 0.1)
def __do_sign(self, password):
2016-02-18 02:02:16 -08:00
try:
self.app.wallet.sign_transaction(self.tx, password)
except InvalidPassword:
self.app.show_error(_("Invalid PIN"))
2016-02-12 23:15:06 -08:00
self.update()
def do_broadcast(self):
2016-02-18 09:52:49 -08:00
self.app.broadcast(self.tx)
2016-02-12 23:15:06 -08:00
def show_qr(self):
2019-12-24 03:21:35 -08:00
from electrum_bitcoinprivate.bitcoin import base_encode, bfh
2017-10-21 22:33:03 -07:00
text = bfh(str(self.tx))
2016-02-12 23:15:06 -08:00
text = base_encode(text, base=43)
self.app.qr_dialog(_("Raw Transaction"), text)