add qr code scanner to kivy wizard
This commit is contained in:
@@ -175,6 +175,10 @@ Builder.load_string('''
|
|||||||
id: back
|
id: back
|
||||||
text: _('Back')
|
text: _('Back')
|
||||||
root: root
|
root: root
|
||||||
|
Button:
|
||||||
|
id: scan
|
||||||
|
text: _('QR')
|
||||||
|
on_release: root.scan_seed()
|
||||||
CreateAccountButton:
|
CreateAccountButton:
|
||||||
id: next
|
id: next
|
||||||
text: _('Next')
|
text: _('Next')
|
||||||
@@ -320,10 +324,16 @@ class RestoreSeedDialog(CreateAccountDialog):
|
|||||||
|
|
||||||
def get_seed_text(self):
|
def get_seed_text(self):
|
||||||
ti = self.ids.text_input_seed
|
ti = self.ids.text_input_seed
|
||||||
text = unicode(ti.text.lower()).strip()
|
text = unicode(ti.text).strip()
|
||||||
text = ' '.join(text.split())
|
text = ' '.join(text.split())
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
def scan_seed(self):
|
||||||
|
def on_complete(text):
|
||||||
|
self.ids.text_input_seed.text = text
|
||||||
|
app = App.get_running_app()
|
||||||
|
app.scan_qr(on_complete)
|
||||||
|
|
||||||
def on_parent(self, instance, value):
|
def on_parent(self, instance, value):
|
||||||
if value:
|
if value:
|
||||||
tis = self.ids.text_input_seed
|
tis = self.ids.text_input_seed
|
||||||
|
|||||||
@@ -7,14 +7,15 @@ from kivy.core.window import Window
|
|||||||
from kivy.clock import Clock
|
from kivy.clock import Clock
|
||||||
from kivy.factory import Factory
|
from kivy.factory import Factory
|
||||||
|
|
||||||
Factory.register('CreateRestoreDialog',
|
|
||||||
module='electrum_gui.kivy.uix.dialogs.create_restore')
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import weakref
|
import weakref
|
||||||
|
|
||||||
|
from create_restore import CreateRestoreDialog, ShowSeedDialog, RestoreSeedDialog
|
||||||
|
from password_dialog import PasswordDialog
|
||||||
|
|
||||||
|
|
||||||
# global Variables
|
# global Variables
|
||||||
app = App.get_running_app()
|
app = App.get_running_app()
|
||||||
|
|
||||||
@@ -59,10 +60,6 @@ class InstallWizard(Widget):
|
|||||||
t = threading.Thread(target = target)
|
t = threading.Thread(target = target)
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
def is_any(self, seed_e):
|
|
||||||
text = self.get_seed_text(seed_e)
|
|
||||||
return Wallet.is_any(text)
|
|
||||||
|
|
||||||
def run(self, action, *args):
|
def run(self, action, *args):
|
||||||
'''Entry point of our Installation wizard'''
|
'''Entry point of our Installation wizard'''
|
||||||
if not action:
|
if not action:
|
||||||
@@ -86,38 +83,37 @@ class InstallWizard(Widget):
|
|||||||
self.run('restore')
|
self.run('restore')
|
||||||
else:
|
else:
|
||||||
self.dispatch('on_wizard_complete', None)
|
self.dispatch('on_wizard_complete', None)
|
||||||
Factory.CreateRestoreDialog(on_release=on_release).open()
|
CreateRestoreDialog(on_release=on_release).open()
|
||||||
|
|
||||||
def restore(self):
|
def restore(self):
|
||||||
from create_restore import RestoreSeedDialog
|
|
||||||
self.is_restore = True
|
self.is_restore = True
|
||||||
def on_seed(_dlg, btn):
|
def on_seed(_dlg, btn):
|
||||||
|
_dlg.close()
|
||||||
if btn is _dlg.ids.back:
|
if btn is _dlg.ids.back:
|
||||||
_dlg.close()
|
|
||||||
self.run('new')
|
self.run('new')
|
||||||
return
|
return
|
||||||
text = _dlg.get_seed_text()
|
text = _dlg.get_seed_text()
|
||||||
need_password = Wallet.should_encrypt(text)
|
if Wallet.should_encrypt(text):
|
||||||
_dlg.close()
|
|
||||||
if need_password:
|
|
||||||
self.run('enter_pin', (text,))
|
self.run('enter_pin', (text,))
|
||||||
else:
|
else:
|
||||||
self.wallet = Wallet.from_text(text)
|
self.run('add_seed', (text, None))
|
||||||
# fixme: sync
|
# fixme: sync
|
||||||
msg = _('You may also enter an extended public key, to create a watching-only wallet')
|
msg = _('You may also enter an extended public key, to create a watching-only wallet')
|
||||||
RestoreSeedDialog(test=Wallet.is_any, message=msg, on_release=partial(on_seed)).open()
|
RestoreSeedDialog(test=Wallet.is_any, message=msg, on_release=on_seed).open()
|
||||||
|
|
||||||
def add_seed(self, seed, password):
|
def add_seed(self, text, password):
|
||||||
def task():
|
def task():
|
||||||
self.wallet.add_seed(seed, password)
|
if Wallet.is_seed(text):
|
||||||
self.wallet.create_master_keys(password)
|
self.wallet.add_seed(text, password)
|
||||||
|
self.wallet.create_master_keys(password)
|
||||||
|
else:
|
||||||
|
self.wallet = Wallet.from_text(text, None, self.storage)
|
||||||
self.wallet.create_main_account()
|
self.wallet.create_main_account()
|
||||||
self.wallet.synchronize()
|
self.wallet.synchronize()
|
||||||
msg= _("Electrum is generating your addresses, please wait.")
|
msg= _("Electrum is generating your addresses, please wait.")
|
||||||
self.waiting_dialog(task, msg, self.terminate)
|
self.waiting_dialog(task, msg, self.terminate)
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
from create_restore import ShowSeedDialog
|
|
||||||
self.is_restore = False
|
self.is_restore = False
|
||||||
seed = self.wallet.make_seed()
|
seed = self.wallet.make_seed()
|
||||||
msg = _("If you forget your PIN or lose your device, your seed phrase will be the "
|
msg = _("If you forget your PIN or lose your device, your seed phrase will be the "
|
||||||
@@ -131,30 +127,24 @@ class InstallWizard(Widget):
|
|||||||
ShowSeedDialog(message=msg, seed_text=seed, on_release=on_ok).open()
|
ShowSeedDialog(message=msg, seed_text=seed, on_release=on_ok).open()
|
||||||
|
|
||||||
def confirm_seed(self, seed):
|
def confirm_seed(self, seed):
|
||||||
from create_restore import RestoreSeedDialog
|
assert Wallet.is_seed(seed)
|
||||||
def on_seed(_dlg, btn):
|
def on_seed(_dlg, btn):
|
||||||
if btn is _dlg.ids.back:
|
if btn is _dlg.ids.back:
|
||||||
_dlg.close()
|
_dlg.close()
|
||||||
self.run('create')
|
self.run('create')
|
||||||
return
|
return
|
||||||
_dlg.close()
|
_dlg.close()
|
||||||
if Wallet.should_encrypt(seed):
|
self.run('enter_pin', (seed,))
|
||||||
self.run('enter_pin', (seed,))
|
|
||||||
else:
|
|
||||||
self.wallet = Wallet.from_text(seed)
|
|
||||||
# fixme: sync
|
|
||||||
msg = _('Please retype your seed phrase, to confirm that you properly saved it')
|
msg = _('Please retype your seed phrase, to confirm that you properly saved it')
|
||||||
RestoreSeedDialog(test=lambda x: x==seed, message=msg, on_release=partial(on_seed)).open()
|
RestoreSeedDialog(test=lambda x: x==seed, message=msg, on_release=on_seed).open()
|
||||||
|
|
||||||
def enter_pin(self, seed):
|
def enter_pin(self, seed):
|
||||||
from password_dialog import PasswordDialog
|
|
||||||
def callback(pin):
|
def callback(pin):
|
||||||
self.run('confirm_pin', (seed, pin))
|
self.run('confirm_pin', (seed, pin))
|
||||||
popup = PasswordDialog('Choose a PIN code', callback)
|
popup = PasswordDialog('Choose a PIN code', callback)
|
||||||
popup.open()
|
popup.open()
|
||||||
|
|
||||||
def confirm_pin(self, seed, pin):
|
def confirm_pin(self, seed, pin):
|
||||||
from password_dialog import PasswordDialog
|
|
||||||
def callback(conf):
|
def callback(conf):
|
||||||
if conf == pin:
|
if conf == pin:
|
||||||
self.run('add_seed', (seed, pin))
|
self.run('add_seed', (seed, pin))
|
||||||
|
|||||||
Reference in New Issue
Block a user