kivy: improve tx dialog
This commit is contained in:
parent
bd34995d9d
commit
c2d3968ebe
|
@ -3,6 +3,7 @@ from kivy.factory import Factory
|
||||||
from kivy.properties import ObjectProperty
|
from kivy.properties import ObjectProperty
|
||||||
from kivy.lang import Builder
|
from kivy.lang import Builder
|
||||||
from kivy.clock import Clock
|
from kivy.clock import Clock
|
||||||
|
from kivy.uix.label import Label
|
||||||
|
|
||||||
from electrum_gui.kivy.i18n import _
|
from electrum_gui.kivy.i18n import _
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
@ -17,63 +18,97 @@ Builder.load_string('''
|
||||||
fee_str: ''
|
fee_str: ''
|
||||||
date_str: ''
|
date_str: ''
|
||||||
amount_str: ''
|
amount_str: ''
|
||||||
txid_str: ''
|
tx_hash: ''
|
||||||
status_str: ''
|
status_str: ''
|
||||||
description: ''
|
description: ''
|
||||||
BoxLayout:
|
outputs_str: ''
|
||||||
orientation: 'vertical'
|
ScrollView:
|
||||||
GridLayout:
|
|
||||||
cols: 2
|
|
||||||
spacing: '10dp'
|
|
||||||
TopLabel:
|
|
||||||
text: _('Status')
|
|
||||||
TopLabel:
|
|
||||||
text: root.status_str
|
|
||||||
TopLabel:
|
|
||||||
text: _('Description') if root.description else ''
|
|
||||||
TopLabel:
|
|
||||||
text: root.description
|
|
||||||
TopLabel:
|
|
||||||
text: _('Date') if root.date_str else ''
|
|
||||||
TopLabel:
|
|
||||||
text: root.date_str
|
|
||||||
TopLabel:
|
|
||||||
text: _('Amount sent') if root.is_mine else _('Amount received')
|
|
||||||
TopLabel:
|
|
||||||
text: root.amount_str
|
|
||||||
TopLabel:
|
|
||||||
text: _('Transaction fee') if root.fee_str else ''
|
|
||||||
TopLabel:
|
|
||||||
text: root.fee_str
|
|
||||||
|
|
||||||
TopLabel:
|
|
||||||
text: root.txid_str
|
|
||||||
|
|
||||||
Widget:
|
|
||||||
size_hint: 1, 0.2
|
|
||||||
|
|
||||||
BoxLayout:
|
BoxLayout:
|
||||||
size_hint: 1, None
|
orientation: 'vertical'
|
||||||
height: '48dp'
|
spacing: '10dp'
|
||||||
Button:
|
padding: '10dp'
|
||||||
size_hint: 0.5, None
|
GridLayout:
|
||||||
|
size_hint: 1, None
|
||||||
|
height: self.minimum_height
|
||||||
|
cols: 2
|
||||||
|
spacing: '10dp'
|
||||||
|
TopLabel:
|
||||||
|
text: _('Status')
|
||||||
|
TopLabel:
|
||||||
|
text: root.status_str
|
||||||
|
TopLabel:
|
||||||
|
text: _('Description') if root.description else ''
|
||||||
|
TopLabel:
|
||||||
|
text: root.description
|
||||||
|
TopLabel:
|
||||||
|
text: _('Date') if root.date_str else ''
|
||||||
|
TopLabel:
|
||||||
|
text: root.date_str
|
||||||
|
TopLabel:
|
||||||
|
text: _('Amount sent') if root.is_mine else _('Amount received')
|
||||||
|
TopLabel:
|
||||||
|
text: root.amount_str
|
||||||
|
TopLabel:
|
||||||
|
text: _('Transaction fee') if root.fee_str else ''
|
||||||
|
TopLabel:
|
||||||
|
text: root.fee_str
|
||||||
|
|
||||||
|
TopLabel:
|
||||||
|
text: _('Outputs') + ':'
|
||||||
|
|
||||||
|
GridLayout:
|
||||||
|
id: outputs
|
||||||
|
size_hint: 1, None
|
||||||
|
height: self.minimum_height
|
||||||
|
cols: 2
|
||||||
|
spacing: '10dp'
|
||||||
|
padding: '10dp'
|
||||||
|
canvas.before:
|
||||||
|
Color:
|
||||||
|
rgb: .3, .3, .3
|
||||||
|
Rectangle:
|
||||||
|
size: self.size
|
||||||
|
pos: self.pos
|
||||||
|
TopLabel:
|
||||||
|
text: _('Transaction ID') + ':' if root.tx_hash else ''
|
||||||
|
TopLabel:
|
||||||
|
font_size: '6pt'
|
||||||
|
text: '[ref=x]%s[/ref]' %' '.join(map(''.join, zip(*[iter(root.tx_hash)]*4))) if root.tx_hash else ''
|
||||||
|
padding: '10dp', '10dp'
|
||||||
|
on_ref_press:
|
||||||
|
app._clipboard.copy(self.text)
|
||||||
|
app.show_info(_('Transaction ID copied to clipboard'))
|
||||||
|
canvas.before:
|
||||||
|
Color:
|
||||||
|
rgb: .3, .3, .3
|
||||||
|
Rectangle:
|
||||||
|
size: self.size
|
||||||
|
pos: self.pos
|
||||||
|
Widget:
|
||||||
|
size_hint: 1, 0.2
|
||||||
|
|
||||||
|
BoxLayout:
|
||||||
|
size_hint: 1, None
|
||||||
height: '48dp'
|
height: '48dp'
|
||||||
text: _('Sign') if root.can_sign else _('Broadcast') if root.can_broadcast else ''
|
Button:
|
||||||
opacity: 1 if root.can_sign or root.can_broadcast else 0
|
size_hint: 0.5, None
|
||||||
disabled: not( root.can_sign or root.can_broadcast )
|
height: '48dp'
|
||||||
on_release:
|
text: _('Sign') if root.can_sign else _('Broadcast') if root.can_broadcast else ''
|
||||||
if root.can_sign: root.do_sign()
|
opacity: 1 if root.can_sign or root.can_broadcast else 0
|
||||||
if root.can_broadcast: root.do_broadcast()
|
disabled: not( root.can_sign or root.can_broadcast )
|
||||||
IconButton:
|
on_release:
|
||||||
size_hint: 0.5, None
|
if root.can_sign: root.do_sign()
|
||||||
height: '48dp'
|
if root.can_broadcast: root.do_broadcast()
|
||||||
icon: 'atlas://gui/kivy/theming/light/qrcode'
|
IconButton:
|
||||||
on_release: root.show_qr()
|
size_hint: 0.5, None
|
||||||
Button:
|
height: '48dp'
|
||||||
size_hint: 0.5, None
|
icon: 'atlas://gui/kivy/theming/light/qrcode'
|
||||||
height: '48dp'
|
on_release: root.show_qr()
|
||||||
text: _('Close')
|
Button:
|
||||||
on_release: popup.dismiss()
|
size_hint: 0.5, None
|
||||||
|
height: '48dp'
|
||||||
|
text: _('Close')
|
||||||
|
on_release: popup.dismiss()
|
||||||
''')
|
''')
|
||||||
|
|
||||||
class TxDialog(Factory.Popup):
|
class TxDialog(Factory.Popup):
|
||||||
|
@ -88,11 +123,10 @@ class TxDialog(Factory.Popup):
|
||||||
def update(self):
|
def update(self):
|
||||||
self.can_broadcast = False
|
self.can_broadcast = False
|
||||||
if self.tx.is_complete():
|
if self.tx.is_complete():
|
||||||
tx_hash = self.tx.hash()
|
self.tx_hash = self.tx.hash()
|
||||||
self.description = self.wallet.get_label(tx_hash)
|
self.description = self.wallet.get_label(self.tx_hash)
|
||||||
self.txid_str = _('Transaction ID') + ' :\n' + ' '.join(map(''.join, zip(*[iter(tx_hash)]*4)))
|
if self.tx_hash in self.wallet.transactions.keys():
|
||||||
if tx_hash in self.wallet.transactions.keys():
|
conf, timestamp = self.wallet.get_confirmations(self.tx_hash)
|
||||||
conf, timestamp = self.wallet.get_confirmations(tx_hash)
|
|
||||||
self.status_str = _("%d confirmations")%conf if conf else _('Pending')
|
self.status_str = _("%d confirmations")%conf if conf else _('Pending')
|
||||||
if timestamp:
|
if timestamp:
|
||||||
self.date_str = datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
|
self.date_str = datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
|
||||||
|
@ -121,6 +155,21 @@ class TxDialog(Factory.Popup):
|
||||||
self.fee_str = ''
|
self.fee_str = ''
|
||||||
self.can_sign = self.wallet.can_sign(self.tx)
|
self.can_sign = self.wallet.can_sign(self.tx)
|
||||||
|
|
||||||
|
for (type, address, amount) in self.tx.outputs():
|
||||||
|
t = Factory.CardLabel(text = '[ref=%s]%s[/ref]'%(address,address), font_size = '6pt')
|
||||||
|
t.shorten = True
|
||||||
|
t.size_hint_x = 0.65
|
||||||
|
t.on_ref_press = self.do_copy_address
|
||||||
|
self.ids.outputs.add_widget(t)
|
||||||
|
t = Factory.CardLabel(text = self.app.format_amount_and_units(amount), font_size='6pt')
|
||||||
|
t.size_hint_x = 0.35
|
||||||
|
t.halign = 'right'
|
||||||
|
self.ids.outputs.add_widget(t)
|
||||||
|
|
||||||
|
def do_copy_address(self, text):
|
||||||
|
self.app._clipboard.copy(text)
|
||||||
|
self.app.show_info(_('Address copied to clipboard'))
|
||||||
|
|
||||||
def do_sign(self):
|
def do_sign(self):
|
||||||
self.app.protected(_("Enter your PIN code in order to sign this transaction"), self._do_sign, ())
|
self.app.protected(_("Enter your PIN code in order to sign this transaction"), self._do_sign, ())
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ Popup:
|
||||||
orientation: 'vertical'
|
orientation: 'vertical'
|
||||||
GridLayout:
|
GridLayout:
|
||||||
spacing: '10dp'
|
spacing: '10dp'
|
||||||
|
padding: '10dp'
|
||||||
cols: 2
|
cols: 2
|
||||||
TopLabel:
|
TopLabel:
|
||||||
text: _('Requestor') if popup.is_invoice else _('Address')
|
text: _('Requestor') if popup.is_invoice else _('Address')
|
||||||
|
|
Loading…
Reference in New Issue