1
0

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

@@ -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: '<'
Widget:
size_hint: 1, 1
BoxLayout:
size_hint: 1, None
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):
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

View File

@@ -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)