kivy: simplify install wizard
This commit is contained in:
parent
bd3f3c3554
commit
f6661fdd2c
|
@ -35,30 +35,20 @@ class InstallWizard(Widget):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.network = network
|
self.network = network
|
||||||
self.storage = storage
|
self.storage = storage
|
||||||
|
self.wallet = Wallet(self.storage)
|
||||||
|
|
||||||
def waiting_dialog(self, task,
|
def waiting_dialog(self, task, msg):
|
||||||
msg= _("Electrum is generating your addresses,"
|
|
||||||
" please wait."),
|
|
||||||
on_complete=None):
|
|
||||||
'''Perform a blocking task in the background by running the passed
|
'''Perform a blocking task in the background by running the passed
|
||||||
method in a thread.
|
method in a thread.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def target():
|
def target():
|
||||||
|
|
||||||
# run your threaded function
|
# run your threaded function
|
||||||
try:
|
try:
|
||||||
task()
|
task()
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
Clock.schedule_once(lambda dt: app.show_error(str(err)))
|
Clock.schedule_once(lambda dt: app.show_error(str(err)))
|
||||||
|
|
||||||
# on completion hide message
|
# on completion hide message
|
||||||
Clock.schedule_once(lambda dt: app.info_bubble.hide(now=True), -1)
|
Clock.schedule_once(lambda dt: app.info_bubble.hide(now=True), -1)
|
||||||
|
|
||||||
# call completion routine
|
|
||||||
if on_complete:
|
|
||||||
Clock.schedule_once(lambda dt: on_complete())
|
|
||||||
|
|
||||||
app.show_info_bubble(
|
app.show_info_bubble(
|
||||||
text=msg, icon='atlas://gui/kivy/theming/light/important',
|
text=msg, icon='atlas://gui/kivy/theming/light/important',
|
||||||
pos=Window.center, width='200sp', arrow_pos=None, modal=True)
|
pos=Window.center, width='200sp', arrow_pos=None, modal=True)
|
||||||
|
@ -72,91 +62,77 @@ class InstallWizard(Widget):
|
||||||
|
|
||||||
def is_any(self, seed_e):
|
def is_any(self, seed_e):
|
||||||
text = self.get_seed_text(seed_e)
|
text = self.get_seed_text(seed_e)
|
||||||
return (Wallet.is_seed(text) or
|
return Wallet.is_any(text)
|
||||||
Wallet.is_old_mpk(text) or
|
|
||||||
Wallet.is_xpub(text) or
|
|
||||||
Wallet.is_xprv(text) or
|
|
||||||
Wallet.is_address(text) or
|
|
||||||
Wallet.is_private_key(text))
|
|
||||||
|
|
||||||
def run(self, action):
|
def run(self, action, *args):
|
||||||
'''Entry point of our Installation wizard
|
'''Entry point of our Installation wizard'''
|
||||||
'''
|
|
||||||
if not action:
|
if not action:
|
||||||
return
|
return
|
||||||
|
if action == 'new':
|
||||||
Factory.CreateRestoreDialog(
|
self.new()
|
||||||
on_release=self.on_creatrestore_complete,
|
elif action == 'create':
|
||||||
action=action).open()
|
self.create()
|
||||||
|
elif action == 'restore':
|
||||||
def on_creatrestore_complete(self, dialog, button):
|
self.restore()
|
||||||
if not button:
|
elif action == 'enter_pin':
|
||||||
# soft back or escape button pressed
|
self.enter_pin(*args)
|
||||||
return self.dispatch('on_wizard_complete', None)
|
elif action == 'confirm_pin':
|
||||||
dialog.close()
|
self.confirm_pin(*args)
|
||||||
|
elif action == 'add_seed':
|
||||||
action = dialog.action
|
self.add_seed(*args)
|
||||||
if button == dialog.ids.create:
|
elif action == 'terminate':
|
||||||
wallet = Wallet(self.storage)
|
self.terminate()
|
||||||
self.password_dialog(wallet=wallet, mode='create')
|
|
||||||
|
|
||||||
elif button == dialog.ids.restore:
|
|
||||||
wallet = None
|
|
||||||
self.restore_seed_dialog(wallet)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.dispatch('on_wizard_complete', None)
|
raise BaseException("unknown action", action)
|
||||||
|
|
||||||
def restore_seed_dialog(self, wallet):
|
def new(self):
|
||||||
from electrum_gui.kivy.uix.dialogs.create_restore import\
|
def on_release(dialog, button):
|
||||||
RestoreSeedDialog
|
if not button:
|
||||||
|
# soft back or escape button pressed
|
||||||
|
return self.dispatch('on_wizard_complete', None)
|
||||||
|
dialog.close()
|
||||||
|
action = dialog.action
|
||||||
|
if button == dialog.ids.create:
|
||||||
|
self.run('create')
|
||||||
|
elif button == dialog.ids.restore:
|
||||||
|
self.run('restore')
|
||||||
|
else:
|
||||||
|
self.dispatch('on_wizard_complete', None)
|
||||||
|
Factory.CreateRestoreDialog(on_release=on_release).open()
|
||||||
|
|
||||||
|
def restore(self):
|
||||||
|
from create_restore import RestoreSeedDialog
|
||||||
|
def on_seed(_dlg, btn):
|
||||||
|
if btn is _dlg.ids.back:
|
||||||
|
_dlg.close()
|
||||||
|
self.run('new')
|
||||||
|
return
|
||||||
|
text = self.get_seed_text(_dlg.ids.text_input_seed)
|
||||||
|
need_password = Wallet.should_encrypt(text)
|
||||||
|
_dlg.close()
|
||||||
|
if need_password:
|
||||||
|
self.run('enter_pin', text)
|
||||||
|
else:
|
||||||
|
self.wallet = Wallet.from_text(text)
|
||||||
|
# fixme: sync
|
||||||
RestoreSeedDialog(
|
RestoreSeedDialog(
|
||||||
on_release=partial(self.on_verify_restore_ok, wallet),
|
on_release=partial(on_seed),
|
||||||
wizard=weakref.proxy(self)).open()
|
wizard=weakref.proxy(self)).open()
|
||||||
|
|
||||||
|
def add_seed(self, seed, password):
|
||||||
|
def task():
|
||||||
|
self.wallet.add_seed(seed, password)
|
||||||
|
self.wallet.create_master_keys(password)
|
||||||
|
self.wallet.create_main_account()
|
||||||
|
self.wallet.synchronize()
|
||||||
|
self.run('terminate')
|
||||||
|
msg= _("Electrum is generating your addresses, please wait.")
|
||||||
|
self.waiting_dialog(task, msg)
|
||||||
|
|
||||||
def on_verify_restore_ok(self, wallet, _dlg, btn, restore=False):
|
def create(self):
|
||||||
if btn in (_dlg.ids.back, _dlg.ids.but_close) :
|
from create_restore import InitSeedDialog
|
||||||
_dlg.close()
|
seed = self.wallet.make_seed()
|
||||||
Factory.CreateRestoreDialog(
|
msg = _("[color=#414141]"+\
|
||||||
on_release=self.on_creatrestore_complete).open()
|
|
||||||
return
|
|
||||||
|
|
||||||
seed = self.get_seed_text(_dlg.ids.text_input_seed)
|
|
||||||
if not seed:
|
|
||||||
return app.show_error(_("No seed!"), duration=.5)
|
|
||||||
|
|
||||||
_dlg.close()
|
|
||||||
|
|
||||||
if Wallet.is_seed(seed):
|
|
||||||
return self.password_dialog(wallet=wallet, mode='restore',
|
|
||||||
seed=seed)
|
|
||||||
elif Wallet.is_xpub(seed):
|
|
||||||
wallet = Wallet.from_xpub(seed, self.storage)
|
|
||||||
elif Wallet.is_address(seed):
|
|
||||||
wallet = Wallet.from_address(seed, self.storage)
|
|
||||||
elif Wallet.is_private_key(seed):
|
|
||||||
wallet = Wallet.from_private_key(seed, self.storage)
|
|
||||||
else:
|
|
||||||
return app.show_error(_('Not a valid seed. App will now exit'),
|
|
||||||
exit=True, modal=True, duration=.5)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def show_seed(self, wallet=None, instance=None, password=None,
|
|
||||||
wallet_name=None, mode='create', seed=''):
|
|
||||||
if instance and (not wallet or not wallet.seed):
|
|
||||||
return app.show_error(_('No seed'))
|
|
||||||
|
|
||||||
if not seed:
|
|
||||||
try:
|
|
||||||
seed = self.wallet.get_seed(password)
|
|
||||||
except Exception:
|
|
||||||
return app.show_error(_('Incorrect Password'))
|
|
||||||
|
|
||||||
brainwallet = seed
|
|
||||||
|
|
||||||
msg2 = _("[color=#414141]"+\
|
|
||||||
"[b]PLEASE WRITE DOWN YOUR SEED PASS[/b][/color]"+\
|
"[b]PLEASE WRITE DOWN YOUR SEED PASS[/b][/color]"+\
|
||||||
"[size=9]\n\n[/size]" +\
|
"[size=9]\n\n[/size]" +\
|
||||||
"[color=#929292]If you ever forget your pincode, your seed" +\
|
"[color=#929292]If you ever forget your pincode, your seed" +\
|
||||||
|
@ -164,195 +140,40 @@ class InstallWizard(Widget):
|
||||||
"[b]only way to recover[/b][/color] your wallet. Your " +\
|
"[b]only way to recover[/b][/color] your wallet. Your " +\
|
||||||
" [color=#EB984E][b]Bitcoins[/b][/color] will otherwise be" +\
|
" [color=#EB984E][b]Bitcoins[/b][/color] will otherwise be" +\
|
||||||
" [color=#EB984E][b]lost forever![/b][/color]")
|
" [color=#EB984E][b]lost forever![/b][/color]")
|
||||||
|
def on_ok(_dlg, _btn):
|
||||||
if wallet.imported_keys:
|
|
||||||
msg2 += "[b][color=#ff0000ff]" + _("WARNING") + "[/color]:[/b] " +\
|
|
||||||
_("Your wallet contains imported keys. These keys cannot" +\
|
|
||||||
" be recovered from seed.")
|
|
||||||
|
|
||||||
def on_ok_press(_dlg, _btn):
|
|
||||||
_dlg.close()
|
_dlg.close()
|
||||||
mode = _dlg.mode
|
if _btn == _dlg.ids.confirm:
|
||||||
if _btn != _dlg.ids.confirm:
|
self.run('enter_pin', seed)
|
||||||
if not instance:
|
|
||||||
self.password_dialog(wallet, mode=mode)
|
|
||||||
return
|
|
||||||
# confirm
|
|
||||||
if instance is None:
|
|
||||||
# in initial phase create mode
|
|
||||||
# save seed with password
|
|
||||||
|
|
||||||
def create(password):
|
|
||||||
wallet.add_seed(seed, password)
|
|
||||||
wallet.create_master_keys(password)
|
|
||||||
wallet.create_main_account()
|
|
||||||
wallet.synchronize() # generate first addresses offline
|
|
||||||
|
|
||||||
self.waiting_dialog(partial(create, password),
|
|
||||||
on_complete=partial(self.load_network,
|
|
||||||
wallet, mode=mode))
|
|
||||||
|
|
||||||
|
|
||||||
from electrum_gui.kivy.uix.dialogs.create_restore import InitSeedDialog
|
|
||||||
InitSeedDialog(message=msg2,
|
|
||||||
seed_msg=brainwallet, on_release=on_ok_press, mode=mode).open()
|
|
||||||
|
|
||||||
def password_dialog(self, wallet=None, instance=None, mode='create',
|
|
||||||
seed=''):
|
|
||||||
"""Can be called directly (instance is None)
|
|
||||||
or from a callback (instance is not None)"""
|
|
||||||
app = App.get_running_app()
|
|
||||||
|
|
||||||
if mode != 'create' and wallet and wallet.is_watching_only():
|
|
||||||
return app.show_error('This is a watching only wallet')
|
|
||||||
|
|
||||||
if instance and not wallet.seed:
|
|
||||||
return app.show_error('No seed !!', exit=True, modal=True)
|
|
||||||
|
|
||||||
if instance is not None:
|
|
||||||
if wallet.use_encryption:
|
|
||||||
msg = (
|
|
||||||
_('Your wallet is encrypted. Use this dialog to change" + \
|
|
||||||
" your password.') + '\n' + _('To disable wallet" + \
|
|
||||||
" encryption, enter an empty new password.'))
|
|
||||||
mode = 'confirm'
|
|
||||||
else:
|
else:
|
||||||
msg = _('Your wallet keys are not encrypted')
|
self.run('new')
|
||||||
mode = 'new'
|
InitSeedDialog(message=msg, seed_msg=seed, on_release=on_ok, mode='create').open()
|
||||||
else:
|
|
||||||
msg = _("Please choose a password to encrypt your wallet keys.") +\
|
|
||||||
'\n' + _("Leave these fields empty if you want to disable" + \
|
|
||||||
" encryption.")
|
|
||||||
|
|
||||||
def on_release(wallet, seed, _dlg, _btn):
|
def enter_pin(self, seed):
|
||||||
ti_password = _dlg.ids.ti_password
|
from password_dialog import PasswordDialog
|
||||||
ti_new_password = _dlg.ids.ti_new_password
|
def callback(pin):
|
||||||
ti_confirm_password = _dlg.ids.ti_confirm_password
|
self.run('confirm_pin', seed, pin)
|
||||||
if _btn != _dlg.ids.next:
|
popup = PasswordDialog('Enter PIN', callback)
|
||||||
if mode == 'restore':
|
popup.open()
|
||||||
# back is disabled cause seed is already set
|
|
||||||
return
|
|
||||||
_dlg.close()
|
|
||||||
if not instance:
|
|
||||||
# back on create
|
|
||||||
Factory.CreateRestoreDialog(
|
|
||||||
on_release=self.on_creatrestore_complete).open()
|
|
||||||
return
|
|
||||||
|
|
||||||
# Confirm
|
def confirm_pin(self, seed, pin):
|
||||||
wallet_name = _dlg.ids.ti_wallet_name.text
|
from password_dialog import PasswordDialog
|
||||||
new_password = unicode(ti_new_password.text)
|
def callback(conf):
|
||||||
new_password2 = unicode(ti_confirm_password.text)
|
if conf == pin:
|
||||||
|
self.run('add_seed', seed, pin)
|
||||||
if new_password != new_password2:
|
|
||||||
# passwords don't match
|
|
||||||
ti_password.text = ""
|
|
||||||
ti_new_password.text = ""
|
|
||||||
ti_confirm_password.text = ""
|
|
||||||
if ti_password.disabled:
|
|
||||||
ti_new_password.focus = True
|
|
||||||
else:
|
|
||||||
ti_password.focus = True
|
|
||||||
return app.show_error(_('Passwords do not match'), duration=.5)
|
|
||||||
|
|
||||||
if not new_password:
|
|
||||||
new_password = None
|
|
||||||
|
|
||||||
if mode == 'restore':
|
|
||||||
password = unicode(ti_password.text)
|
|
||||||
# if wallet and wallet.use_encryption else
|
|
||||||
# None)
|
|
||||||
if not password:
|
|
||||||
password = None
|
|
||||||
wallet = Wallet.from_text(seed, password, self.storage)
|
|
||||||
|
|
||||||
def on_complete(*l):
|
|
||||||
self.load_network(wallet, mode='restore')
|
|
||||||
_dlg.close()
|
|
||||||
|
|
||||||
self.waiting_dialog(wallet.synchronize,
|
|
||||||
msg=_("generating addresses"),
|
|
||||||
on_complete=on_complete)
|
|
||||||
return
|
|
||||||
|
|
||||||
if not instance:
|
|
||||||
# create mode
|
|
||||||
_dlg.close()
|
|
||||||
seed = wallet.make_seed()
|
|
||||||
|
|
||||||
return self.show_seed(password=new_password, wallet=wallet,
|
|
||||||
wallet_name=wallet_name, mode=mode,
|
|
||||||
seed=seed)
|
|
||||||
|
|
||||||
# change password mode
|
|
||||||
try:
|
|
||||||
seed = wallet.decode_seed(password)
|
|
||||||
except BaseException:
|
|
||||||
return app.show_error(_('Incorrect Password'), duration=.5)
|
|
||||||
|
|
||||||
# test carefully
|
|
||||||
try:
|
|
||||||
wallet.update_password(seed, password, new_password)
|
|
||||||
except BaseException:
|
|
||||||
return app.show_error(_('Failed to update password'), exit=True)
|
|
||||||
else:
|
else:
|
||||||
app.show_info_bubble(
|
app = App.get_running_app()
|
||||||
text=_('Password successfully updated'), duration=1,
|
app.show_error(_('Passwords do not match'), duration=.5)
|
||||||
pos=_btn.pos)
|
popup = PasswordDialog('Confirm PIN', callback)
|
||||||
_dlg.close()
|
popup.open()
|
||||||
|
|
||||||
if instance is None: # in initial phase
|
def terminate(self):
|
||||||
self.load_wallet()
|
self.wallet.start_threads(self.network)
|
||||||
self.app.update_wallet()
|
app.load_wallet(self.wallet)
|
||||||
|
self.dispatch('on_wizard_complete', wallet)
|
||||||
from electrum_gui.kivy.uix.dialogs.create_restore import ChangePasswordDialog
|
|
||||||
cpd = ChangePasswordDialog(
|
|
||||||
message=msg,
|
|
||||||
mode=mode,
|
|
||||||
on_release=partial(on_release,
|
|
||||||
wallet, seed)).open()
|
|
||||||
|
|
||||||
def load_network(self, wallet, mode='create'):
|
|
||||||
#if not self.config.get('server'):
|
|
||||||
if self.network:
|
|
||||||
if self.network.interfaces:
|
|
||||||
if mode not in ('restore', 'create'):
|
|
||||||
self.network_dialog()
|
|
||||||
else:
|
|
||||||
app.show_error(_('You are offline'))
|
|
||||||
self.network.stop()
|
|
||||||
self.network = None
|
|
||||||
|
|
||||||
if mode in ('restore', 'create'):
|
|
||||||
# auto cycle
|
|
||||||
self.config.set_key('auto_cycle', True, True)
|
|
||||||
|
|
||||||
# start wallet threads
|
|
||||||
wallet.start_threads(self.network)
|
|
||||||
|
|
||||||
if not mode == 'restore':
|
|
||||||
return self.dispatch('on_wizard_complete', wallet)
|
|
||||||
|
|
||||||
def get_text(text):
|
|
||||||
def set_text(*l): app.info_bubble.ids.lbl.text=text
|
|
||||||
Clock.schedule_once(set_text)
|
|
||||||
|
|
||||||
def on_complete(*l):
|
|
||||||
if not self.network:
|
|
||||||
app.show_info(
|
|
||||||
_("This wallet was restored offline. It may contain more"
|
|
||||||
" addresses than displayed."), duration=.5)
|
|
||||||
return self.dispatch('on_wizard_complete', wallet)
|
|
||||||
|
|
||||||
if wallet.is_found():
|
|
||||||
app.show_info(_("Recovery successful"), duration=.5)
|
|
||||||
else:
|
|
||||||
app.show_info(_("No transactions found for this seed"),
|
|
||||||
duration=.5)
|
|
||||||
return self.dispatch('on_wizard_complete', wallet)
|
|
||||||
|
|
||||||
self.waiting_dialog(lambda: wallet.restore(get_text),
|
|
||||||
on_complete=on_complete)
|
|
||||||
|
|
||||||
def on_wizard_complete(self, wallet):
|
def on_wizard_complete(self, wallet):
|
||||||
pass
|
if wallet.is_found():
|
||||||
|
app.show_info(_("Recovery successful"), duration=.5)
|
||||||
|
else:
|
||||||
|
app.show_info(_("No transactions found for this seed"),
|
||||||
|
duration=.5)
|
||||||
|
|
Loading…
Reference in New Issue