kivy: improve PIN dialog
This commit is contained in:
parent
744b74f2b5
commit
5f5e9b0a17
|
@ -682,14 +682,14 @@ class ElectrumWindow(App):
|
|||
popup = AmountDialog(show_max, amount, cb)
|
||||
popup.open()
|
||||
|
||||
def protected(self, f, args):
|
||||
def protected(self, msg, f, args):
|
||||
if self.wallet.use_encryption:
|
||||
self.password_dialog(_('Enter PIN'), f, args)
|
||||
self.password_dialog(msg, f, args)
|
||||
else:
|
||||
apply(f, args + (None,))
|
||||
|
||||
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):
|
||||
try:
|
||||
|
@ -700,7 +700,7 @@ class ElectrumWindow(App):
|
|||
label.text = _('Seed') + ':\n' + seed
|
||||
|
||||
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):
|
||||
if self.wallet.use_encryption:
|
||||
|
@ -720,10 +720,10 @@ class ElectrumWindow(App):
|
|||
else:
|
||||
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
|
||||
def callback(pw):
|
||||
Clock.schedule_once(lambda x: apply(f, args + (pw,)), 0.1)
|
||||
popup = PasswordDialog(title, callback)
|
||||
popup = PasswordDialog(msg, callback)
|
||||
popup.open()
|
||||
|
||||
|
|
|
@ -8,27 +8,31 @@ Builder.load_string('''
|
|||
|
||||
<PasswordDialog@Popup>
|
||||
id: popup
|
||||
title: _('Enter PIN Code')
|
||||
title: _('PIN Code')
|
||||
message: ''
|
||||
size_hint: 0.9, 0.9
|
||||
|
||||
BoxLayout:
|
||||
|
||||
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:
|
||||
id: a
|
||||
text: ' * '*len(kb.password) + ' o '*(6-len(kb.password))
|
||||
size_hint: 1, None
|
||||
height: '48dp'
|
||||
|
||||
Widget:
|
||||
size_hint: 1, 1
|
||||
GridLayout:
|
||||
id: kb
|
||||
update_amount: popup.update_password
|
||||
password: ''
|
||||
on_password: popup.on_password(self.password)
|
||||
size_hint: 1, None
|
||||
height: '300dp'
|
||||
height: '200dp'
|
||||
cols: 3
|
||||
KButton:
|
||||
text: '1'
|
||||
|
@ -54,18 +58,25 @@ Builder.load_string('''
|
|||
text: '0'
|
||||
KButton:
|
||||
text: '<'
|
||||
|
||||
BoxLayout:
|
||||
size_hint: 1, None
|
||||
height: '48dp'
|
||||
Widget:
|
||||
size_hint: 1, 1
|
||||
size_hint: 0.5, None
|
||||
Button:
|
||||
size_hint: 0.5, None
|
||||
height: '48dp'
|
||||
text: _('Cancel')
|
||||
on_release: popup.dismiss()
|
||||
''')
|
||||
|
||||
|
||||
class PasswordDialog(Factory.Popup):
|
||||
|
||||
def __init__(self, title, cb):
|
||||
def __init__(self, message, callback):
|
||||
Factory.Popup.__init__(self)
|
||||
self.title = title
|
||||
self.callback = cb
|
||||
self.message = message
|
||||
self.callback = callback
|
||||
|
||||
def update_password(self, c):
|
||||
kb = self.ids.kb
|
||||
|
|
|
@ -250,23 +250,32 @@ class SendScreen(CScreen):
|
|||
return
|
||||
outputs = [(bitcoin.TYPE_ADDRESS, address, amount)]
|
||||
message = unicode(self.screen.message)
|
||||
fee = None
|
||||
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):
|
||||
amount = sum(map(lambda x:x[2], outputs))
|
||||
# make unsigned transaction
|
||||
coins = self.app.wallet.get_spendable_coins()
|
||||
config = self.app.electrum_config
|
||||
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:
|
||||
traceback.print_exc(file=sys.stdout)
|
||||
self.app.show_error(str(e))
|
||||
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
|
||||
self.app.show_info("Signing...")
|
||||
try:
|
||||
self.app.wallet.sign_transaction(tx, password)
|
||||
except Exception as e:
|
||||
|
@ -277,6 +286,7 @@ class SendScreen(CScreen):
|
|||
self.app.tx_dialog(tx)
|
||||
return
|
||||
# broadcast
|
||||
self.app.show_info("Sending...")
|
||||
ok, txid = self.app.wallet.sendtx(tx)
|
||||
self.app.show_info(txid)
|
||||
|
||||
|
|
Loading…
Reference in New Issue