electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 193c29af87406646c7db54b0095a2c88ad6d8553
parent cc33b752e20b084570c9fdbca4afb7a6bb0d128f
Author: SomberNight <somber.night@protonmail.com>
Date:   Thu,  5 Nov 2020 01:02:11 +0100

wizard, multisig: on bip39/hw ks, only ask for script type for 1st ks

When setting up a multisig wallet, there is no point in asking for the
script type for each cosigner (bip39/hw) -- we can just ask for the
first one. If the first keystore is an electrum seed, we end up never asking :)

Diffstat:
Melectrum/base_wizard.py | 31+++++++++++++++++++++++++++----
Melectrum/gui/qt/installwizard.py | 6++++--
2 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/electrum/base_wizard.py b/electrum/base_wizard.py @@ -410,6 +410,7 @@ class BaseWizard(Logger): _('You can override the suggested derivation path.'), _('If you are not sure what this is, leave this field unchanged.') ]) + hide_choices = False if self.wallet_type == 'multisig': # There is no general standard for HD multisig. # For legacy, this is partially compatible with BIP45; assumes index=0 @@ -420,6 +421,14 @@ class BaseWizard(Logger): ('p2wsh-p2sh', 'p2sh-segwit multisig (p2wsh-p2sh)', purpose48_derivation(0, xtype='p2wsh-p2sh')), ('p2wsh', 'native segwit multisig (p2wsh)', purpose48_derivation(0, xtype='p2wsh')), ] + # if this is not the first cosigner, pre-select the expected script type, + # and hide the choices + script_type = self.get_script_type_of_wallet() + if script_type is not None: + script_types = [*zip(*choices)][0] + chosen_idx = script_types.index(script_type) + default_choice_idx = chosen_idx + hide_choices = True else: default_choice_idx = 2 choices = [ @@ -430,9 +439,16 @@ class BaseWizard(Logger): while True: try: self.derivation_and_script_type_gui_specific_dialog( - run_next=f, title=_('Script type and Derivation path'), message1=message1, - message2=message2, choices=choices, test_text=is_bip32_derivation, - default_choice_idx=default_choice_idx, get_account_xpub=get_account_xpub) + run_next=f, + title=_('Script type and Derivation path'), + message1=message1, + message2=message2, + choices=choices, + test_text=is_bip32_derivation, + default_choice_idx=default_choice_idx, + get_account_xpub=get_account_xpub, + hide_choices=hide_choices, + ) return except ScriptTypeNotSupported as e: self.show_error(e) @@ -529,7 +545,14 @@ class BaseWizard(Logger): k = keystore.from_bip39_seed(seed, passphrase, derivation, xtype=script_type) self.on_keystore(k) - def on_keystore(self, k): + def get_script_type_of_wallet(self) -> Optional[str]: + if len(self.keystores) > 0: + ks = self.keystores[0] + if isinstance(ks, keystore.Xpub): + return xpub_type(ks.xpub) + return None + + def on_keystore(self, k: KeyStore): has_xpub = isinstance(k, keystore.Xpub) if has_xpub: t1 = xpub_type(k.xpub) diff --git a/electrum/gui/qt/installwizard.py b/electrum/gui/qt/installwizard.py @@ -610,11 +610,12 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard): title: str, message1: str, choices: List[Tuple[str, str, str]], + hide_choices: bool = False, message2: str, test_text: Callable[[str], int], run_next, default_choice_idx: int = 0, - get_account_xpub=None + get_account_xpub=None, ) -> Tuple[str, str]: vbox = QVBoxLayout() @@ -640,7 +641,8 @@ class InstallWizard(QDialog, MessageBoxMixin, BaseWizard): line.setText(c_default_text[idx]) clayout = ChoicesLayout(message1, c_titles, on_choice_click, checked_index=default_choice_idx) - vbox.addLayout(clayout.layout()) + if not hide_choices: + vbox.addLayout(clayout.layout()) vbox.addWidget(WWLabel(message2))