wizard: cleanup, variable naming consistency, imports, invalid accept handler now raises
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import copy
|
import copy
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from typing import List, TYPE_CHECKING, Tuple, NamedTuple, Any, Dict, Optional, Union
|
from typing import List, NamedTuple, Any, Dict, Optional
|
||||||
|
|
||||||
from electrum.logging import get_logger
|
from electrum.logging import get_logger
|
||||||
from electrum.storage import WalletStorage, StorageEncryptionVersion
|
from electrum.storage import WalletStorage, StorageEncryptionVersion
|
||||||
@@ -60,23 +60,24 @@ class AbstractWizard:
|
|||||||
if 'accept' in nav:
|
if 'accept' in nav:
|
||||||
# allow python scope to append to wizard_data before
|
# allow python scope to append to wizard_data before
|
||||||
# adding to stack or finishing
|
# adding to stack or finishing
|
||||||
if callable(nav['accept']):
|
view_accept = nav['accept']
|
||||||
nav['accept'](wizard_data)
|
if callable(view_accept):
|
||||||
|
view_accept(wizard_data)
|
||||||
else:
|
else:
|
||||||
self._logger.error(f'accept handler for view {view} not callable')
|
raise Exception(f'accept handler for view {view} is not callable')
|
||||||
|
|
||||||
if 'next' not in nav:
|
if 'next' not in nav:
|
||||||
# finished
|
# finished
|
||||||
self.finished(wizard_data)
|
self.finished(wizard_data)
|
||||||
return WizardViewState(None, wizard_data, {})
|
return WizardViewState(None, wizard_data, {})
|
||||||
|
|
||||||
nexteval = nav['next']
|
view_next = nav['next']
|
||||||
# simple string based next view
|
if isinstance(view_next, str):
|
||||||
if isinstance(nexteval, str):
|
# string literal
|
||||||
new_view = WizardViewState(nexteval, wizard_data, {})
|
new_view = WizardViewState(view_next, wizard_data, {})
|
||||||
else:
|
elif callable(view_next):
|
||||||
# handler fn based next view
|
# handler fn based
|
||||||
nv = nexteval(wizard_data)
|
nv = view_next(wizard_data)
|
||||||
self._logger.debug(repr(nv))
|
self._logger.debug(repr(nv))
|
||||||
|
|
||||||
# append wizard_data and params if not returned
|
# append wizard_data and params if not returned
|
||||||
@@ -88,6 +89,8 @@ class AbstractWizard:
|
|||||||
new_view = WizardViewState(nv[0], nv[1], {})
|
new_view = WizardViewState(nv[0], nv[1], {})
|
||||||
else:
|
else:
|
||||||
new_view = nv
|
new_view = nv
|
||||||
|
else:
|
||||||
|
raise Exception(f'next handler for view {view} is not callable nor a string literal')
|
||||||
|
|
||||||
self._logger.debug(f'resolve_next view is {new_view}')
|
self._logger.debug(f'resolve_next view is {new_view}')
|
||||||
|
|
||||||
@@ -117,15 +120,16 @@ class AbstractWizard:
|
|||||||
if 'last' not in nav:
|
if 'last' not in nav:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
lastnav = nav['last']
|
view_last = nav['last']
|
||||||
# bool literal
|
if isinstance(view_last, bool):
|
||||||
if isinstance(lastnav, bool):
|
# bool literal
|
||||||
return lastnav
|
self._logger.debug(f'view "{view}" last: {view_last}')
|
||||||
elif callable(lastnav):
|
return view_last
|
||||||
|
elif callable(view_last):
|
||||||
# handler fn based
|
# handler fn based
|
||||||
l = lastnav(wizard_data)
|
is_last = view_last(wizard_data)
|
||||||
self._logger.debug(f'view "{view}" last: {l}')
|
self._logger.debug(f'view "{view}" last: {is_last}')
|
||||||
return l
|
return is_last
|
||||||
else:
|
else:
|
||||||
raise Exception(f'last handler for view {view} is not callable nor a bool literal')
|
raise Exception(f'last handler for view {view} is not callable nor a bool literal')
|
||||||
|
|
||||||
@@ -203,7 +207,7 @@ class NewWalletWizard(AbstractWizard):
|
|||||||
'multisig': {
|
'multisig': {
|
||||||
'next': 'keystore_type'
|
'next': 'keystore_type'
|
||||||
},
|
},
|
||||||
'multisig_cosigner_keystore': { # this view should set 'multisig_current_cosigner'
|
'multisig_cosigner_keystore': { # this view should set 'multisig_current_cosigner'
|
||||||
'next': self.on_cosigner_keystore_type
|
'next': self.on_cosigner_keystore_type
|
||||||
},
|
},
|
||||||
'multisig_cosigner_key': {
|
'multisig_cosigner_key': {
|
||||||
@@ -320,8 +324,7 @@ class NewWalletWizard(AbstractWizard):
|
|||||||
All master keys need to be bip32, and e.g. Ypub cannot be mixed with Zpub.
|
All master keys need to be bip32, and e.g. Ypub cannot be mixed with Zpub.
|
||||||
If True, need to prevent wallet-creation.
|
If True, need to prevent wallet-creation.
|
||||||
"""
|
"""
|
||||||
xpubs = []
|
xpubs = [self.keystore_from_data(wizard_data['wallet_type'], wizard_data).get_master_public_key()]
|
||||||
xpubs.append(self.keystore_from_data(wizard_data['wallet_type'], wizard_data).get_master_public_key())
|
|
||||||
for cosigner in wizard_data['multisig_cosigner_data']:
|
for cosigner in wizard_data['multisig_cosigner_data']:
|
||||||
data = wizard_data['multisig_cosigner_data'][cosigner]
|
data = wizard_data['multisig_cosigner_data'][cosigner]
|
||||||
xpubs.append(self.keystore_from_data(wizard_data['wallet_type'], data).get_master_public_key())
|
xpubs.append(self.keystore_from_data(wizard_data['wallet_type'], data).get_master_public_key())
|
||||||
@@ -358,10 +361,6 @@ class NewWalletWizard(AbstractWizard):
|
|||||||
else:
|
else:
|
||||||
raise Exception('no seed or master_key in data')
|
raise Exception('no seed or master_key in data')
|
||||||
|
|
||||||
def finished(self, wizard_data):
|
|
||||||
self._logger.debug('finished')
|
|
||||||
# override
|
|
||||||
|
|
||||||
def create_storage(self, path, data):
|
def create_storage(self, path, data):
|
||||||
assert data['wallet_type'] in ['standard', '2fa', 'imported', 'multisig']
|
assert data['wallet_type'] in ['standard', '2fa', 'imported', 'multisig']
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user