kivy: improve PIN dialog

This commit is contained in:
ThomasV 2016-02-13 10:00:20 +01:00
parent 744b74f2b5
commit 5f5e9b0a17
3 changed files with 51 additions and 30 deletions

View File

@ -682,14 +682,14 @@ class ElectrumWindow(App):
popup = AmountDialog(show_max, amount, cb) popup = AmountDialog(show_max, amount, cb)
popup.open() popup.open()
def protected(self, f, args): def protected(self, msg, f, args):
if self.wallet.use_encryption: if self.wallet.use_encryption:
self.password_dialog(_('Enter PIN'), f, args) self.password_dialog(msg, f, args)
else: else:
apply(f, args + (None,)) apply(f, args + (None,))
def show_seed(self, label): def show_seed(self, label):
self.protected(self._show_seed, (label,)) self.protected(_("Enter your PIN code in order to decrypt your seed"), self._show_seed, (label,))
def _show_seed(self, label, password): def _show_seed(self, label, password):
try: try:
@ -700,7 +700,7 @@ class ElectrumWindow(App):
label.text = _('Seed') + ':\n' + seed label.text = _('Seed') + ':\n' + seed
def change_password(self): def change_password(self):
self.protected(self._change_password, ()) self.protected(_("Changing PIN code.") + '\n' + _("Enter your current PIN:"), self._change_password, ())
def _change_password(self, old_password): def _change_password(self, old_password):
if self.wallet.use_encryption: if self.wallet.use_encryption:
@ -720,10 +720,10 @@ class ElectrumWindow(App):
else: else:
self.show_error("PIN numbers do not match") self.show_error("PIN numbers do not match")
def password_dialog(self, title, f, args): def password_dialog(self, msg, f, args):
from uix.dialogs.password_dialog import PasswordDialog from uix.dialogs.password_dialog import PasswordDialog
def callback(pw): def callback(pw):
Clock.schedule_once(lambda x: apply(f, args + (pw,)), 0.1) Clock.schedule_once(lambda x: apply(f, args + (pw,)), 0.1)
popup = PasswordDialog(title, callback) popup = PasswordDialog(msg, callback)
popup.open() popup.open()

View File

@ -8,27 +8,31 @@ Builder.load_string('''
<PasswordDialog@Popup> <PasswordDialog@Popup>
id: popup id: popup
title: _('Enter PIN Code') title: _('PIN Code')
message: ''
size_hint: 0.9, 0.9 size_hint: 0.9, 0.9
BoxLayout: BoxLayout:
orientation: 'vertical' orientation: 'vertical'
size_hint: 0.8, 1 Widget:
size_hint: 1, 1
Label:
text: root.message
text_size: self.width, None
size: self.texture_size
Widget:
size_hint: 1, 1
Label: Label:
id: a id: a
text: ' * '*len(kb.password) + ' o '*(6-len(kb.password)) text: ' * '*len(kb.password) + ' o '*(6-len(kb.password))
size_hint: 1, None Widget:
height: '48dp' size_hint: 1, 1
GridLayout: GridLayout:
id: kb id: kb
update_amount: popup.update_password update_amount: popup.update_password
password: '' password: ''
on_password: popup.on_password(self.password) on_password: popup.on_password(self.password)
size_hint: 1, None size_hint: 1, None
height: '300dp' height: '200dp'
cols: 3 cols: 3
KButton: KButton:
text: '1' text: '1'
@ -54,18 +58,25 @@ Builder.load_string('''
text: '0' text: '0'
KButton: KButton:
text: '<' text: '<'
BoxLayout:
Widget: size_hint: 1, None
size_hint: 1, 1 height: '48dp'
Widget:
size_hint: 0.5, None
Button:
size_hint: 0.5, None
height: '48dp'
text: _('Cancel')
on_release: popup.dismiss()
''') ''')
class PasswordDialog(Factory.Popup): class PasswordDialog(Factory.Popup):
def __init__(self, title, cb): def __init__(self, message, callback):
Factory.Popup.__init__(self) Factory.Popup.__init__(self)
self.title = title self.message = message
self.callback = cb self.callback = callback
def update_password(self, c): def update_password(self, c):
kb = self.ids.kb kb = self.ids.kb

View File

@ -250,23 +250,32 @@ class SendScreen(CScreen):
return return
outputs = [(bitcoin.TYPE_ADDRESS, address, amount)] outputs = [(bitcoin.TYPE_ADDRESS, address, amount)]
message = unicode(self.screen.message) message = unicode(self.screen.message)
fee = None amount = sum(map(lambda x:x[2], outputs))
self.app.protected(self.send_tx, (outputs, fee, message))
def send_tx(self, *args):
self.app.show_info("Sending...")
threading.Thread(target=self.send_tx_thread, args=args).start()
def send_tx_thread(self, outputs, fee, label, password):
# make unsigned transaction # make unsigned transaction
coins = self.app.wallet.get_spendable_coins() coins = self.app.wallet.get_spendable_coins()
config = self.app.electrum_config
try: try:
tx = self.app.wallet.make_unsigned_transaction(coins, outputs, self.app.electrum_config, fee) tx = self.app.wallet.make_unsigned_transaction(coins, outputs, config, None)
except Exception as e: except Exception as e:
traceback.print_exc(file=sys.stdout) traceback.print_exc(file=sys.stdout)
self.app.show_error(str(e)) self.app.show_error(str(e))
return return
fee = tx.get_fee()
msg = [
_("Amount to be sent") + ": " + self.app.format_amount_and_units(amount),
_("Mining fee") + ": " + self.app.format_amount_and_units(fee),
]
if fee >= config.get('confirm_fee', 100000):
msg.append(_('Warning')+ ': ' + _("The fee for this transaction seems unusually high."))
msg.append(_("Enter your PIN code to proceed"))
self.app.protected('\n'.join(msg), self.send_tx, (tx,))
def send_tx(self, *args):
threading.Thread(target=self.send_tx_thread, args=args).start()
def send_tx_thread(self, tx, password):
# sign transaction # sign transaction
self.app.show_info("Signing...")
try: try:
self.app.wallet.sign_transaction(tx, password) self.app.wallet.sign_transaction(tx, password)
except Exception as e: except Exception as e:
@ -277,6 +286,7 @@ class SendScreen(CScreen):
self.app.tx_dialog(tx) self.app.tx_dialog(tx)
return return
# broadcast # broadcast
self.app.show_info("Sending...")
ok, txid = self.app.wallet.sendtx(tx) ok, txid = self.app.wallet.sendtx(tx)
self.app.show_info(txid) self.app.show_info(txid)