Qml wizard warn wrong electrum seed - #10895
Conversation
dcbf073 to
2617807
Compare
| return plugin.wizard_entry_for_device(_info, new_wallet=new_wallet) | ||
|
|
||
| def validate_seed(self, seed: str, seed_variant: str, wallet_type: str) -> Tuple[bool, str, str, bool]: | ||
| def _warning_wrong_electrum_seed_type(self, seed_type: str) -> str: |
There was a problem hiding this comment.
This could be used to deduplicate the identical warning in seed_dialog.py:
electrum/electrum/gui/qt/seed_dialog.py
Lines 325 to 331 in a8ff16a
This works (click to expand)
diff --git a/electrum/gui/qt/seed_dialog.py b/electrum/gui/qt/seed_dialog.py
index 0b0da25ae3..e5ffe9c6b9 100644
--- a/electrum/gui/qt/seed_dialog.py
+++ b/electrum/gui/qt/seed_dialog.py
@@ -36,6 +36,7 @@ from electrum.mnemonic import Mnemonic, calc_seed_type, is_any_2fa_seed_type
from electrum import old_mnemonic
from electrum import slip39
from electrum.util import ChoiceItem
+from electrum.wizard import KeystoreWizard
from .util import (
Buttons, OkButton, WWLabel, ButtonsTextEdit, icon_path, EnterButton,
@@ -322,13 +323,7 @@ class SeedWidget(QWidget):
t = calc_seed_type(s)
label = _('Seed Type') + ': ' + t if t else ''
if t and not valid: # electrum seed, but does not conform to dialog rules
- wiztype_fullname = _('Wallet with two-factor authentication') if is_any_2fa_seed_type(t) else _("Standard wallet")
- msg = ' '.join([
- '<b>' + _('Warning') + ':</b> ',
- _("Looks like you have entered a valid seed of type '{}' but this dialog does not support such seeds.").format(t),
- _("If unsure, try restoring as '{}'.").format(wiztype_fullname),
- ])
- self.seed_warning.setText(msg)
+ self.seed_warning.setText(KeystoreWizard.warning_wrong_electrum_seed_type(t))
else:
self.seed_warning.setText("")
diff --git a/electrum/wizard.py b/electrum/wizard.py
index d8773f82a1..2b15a06e47 100644
--- a/electrum/wizard.py
+++ b/electrum/wizard.py
@@ -312,7 +312,8 @@ class KeystoreWizard(AbstractWizard):
run_hook('init_wallet_wizard', self) # TODO: currently only used for hww, hook name might be confusing
return plugin.wizard_entry_for_device(_info, new_wallet=new_wallet)
- def _warning_wrong_electrum_seed_type(self, seed_type: str) -> str:
+ @staticmethod
+ def warning_wrong_electrum_seed_type(seed_type: str) -> str:
if not seed_type:
return ''
wiztype_fullname = _('Wallet with two-factor authentication') if is_any_2fa_seed_type(seed_type) \
@@ -359,11 +360,11 @@ class KeystoreWizard(AbstractWizard):
# check if seed matches wallet type
if wallet_type == '2fa' and not is_any_2fa_seed_type(seed_type):
seed_valid = False
- warning = self._warning_wrong_electrum_seed_type(seed_type)
+ warning = self.warning_wrong_electrum_seed_type(seed_type)
elif wallet_type == 'standard' and seed_type not in ['old', 'standard', 'segwit', 'bip39', 'slip39']:
seed_valid = False
if seed_variant == 'electrum':
- warning = self._warning_wrong_electrum_seed_type(seed_type)
+ warning = self.warning_wrong_electrum_seed_type(seed_type)
elif wallet_type == 'multisig' and seed_type not in ['standard', 'segwit', 'bip39', 'slip39']:
seed_valid = False
There was a problem hiding this comment.
Yes I saw that, but I held off on refactoring this like you suggested above because it felt like a circular dependency using the class and its static member in a control that is typically imported in a wizard.
There was a problem hiding this comment.
somewhat related, I have long thought we have too many top-level modules (.py files directly in electrum/). One idea for a new folder is mnemonic/, which would include:
- mnemonic.py
- old_mnemonic.py
- slip39.py
- the "bip39" parts extracted from keystore.py, in a new bip39.py
(EDIT: there is also bip39_recovery.py, bip39_wallet_formats.json, perhaps even the whole wordlist/ folder)
If we had that folder, you could somewhat more cleanly also add another module there for shared UI code, and put this function there.
There was a problem hiding this comment.
You can also add a FIXME pointing out where the duplication is, and we can fix it later, if you want. We should definitely try to avoid unmarked duplication though.
I can do the above mentioned refactor but don't want to hold up this PR on that.
| warning = self._warning_wrong_electrum_seed_type(seed_type) | ||
| elif wallet_type == 'multisig' and seed_type not in ['standard', 'segwit', 'bip39', 'slip39']: | ||
| seed_valid = False | ||
|
|
There was a problem hiding this comment.
On desktop we also show a warning if the user enters the wrong seed type into the multisig wizard:
| warning = self._warning_wrong_electrum_seed_type(seed_type) | |
2617807 to
90fd2c5
Compare
90fd2c5 to
be9fb4b
Compare
No description provided.