qt: wizard: pass wallet_type to Keystore wizard via initial viewstate
What changed, and why it matters
This commit is a small internal code cleanup in Electrum's Qt graphical interface. It changes how the 'wallet type' is passed into the keystore wizard, moving it from a direct constructor argument into a structured 'view state' object. There is no indication this fixes a security bug; it appears to be a refactoring or bug-fix for wizard behavior.
No security action required. Treat as normal code maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors QEKeystoreWizard initialization. Previously it accepted wallet_type as a positional/keyword argument and stored it in self._wallet_type, which WCExtendKeystore then copied into wizard_data. Now the caller (WalletInfoDialog.enable_keystore) creates a WizardViewState with wallet_type in wizard_data, and the wizard asserts its presence. WCExtendKeystore reads wallet_type from wizard_data instead of the wizard attribute. This aligns state flow with the wizard’s viewstate model.
Changed components
electrum/gui/qt/wallet_info_dialog.pyelectrum/gui/qt/wizard/wallet.pyInspect captured patch +16 / −10
diff --git a/electrum/gui/qt/wallet_info_dialog.py b/electrum/gui/qt/wallet_info_dialog.py
index 7ba9bb6..9d6a26c 100644
--- a/electrum/gui/qt/wallet_info_dialog.py
+++ b/electrum/gui/qt/wallet_info_dialog.py
@@ -14,6 +14,7 @@ from PyQt6.QtWidgets import (
from electrum.plugin import run_hook
from electrum.i18n import _
from electrum.wallet import Multisig_Wallet
+from electrum.wizard import WizardViewState
from .main_window import protected
from electrum.gui.qt.wizard.wallet import QEKeystoreWizard
@@ -192,7 +193,9 @@ class WalletInfoDialog(WindowModalDialog):
self.window.gui_object.reload_windows()
def enable_keystore(self, b: bool):
- dialog = QEKeystoreWizard(self.window.config, self.window.wallet.wallet_type, self.window.gui_object.app, self.window.gui_object.plugins)
+ v = WizardViewState('keystore_type', {'wallet_type': self.window.wallet.wallet_type}, {})
+ dialog = QEKeystoreWizard(config=self.window.config, app=self.window.gui_object.app,
+ plugins=self.window.gui_object.plugins, start_viewstate=v)
result = dialog.run()
if not result:
return
diff --git a/electrum/gui/qt/wizard/wallet.py b/electrum/gui/qt/wizard/wallet.py
index bae3ef9..839d6a8 100644
--- a/electrum/gui/qt/wizard/wallet.py
+++ b/electrum/gui/qt/wizard/wallet.py
@@ -23,7 +23,7 @@ from .wizard import QEAbstractWizard, WizardComponent
from electrum.logging import get_logger, Logger
from electrum import WalletStorage, mnemonic, keystore
from electrum.wallet_db import WalletDB
-from electrum.wizard import NewWalletWizard, KeystoreWizard
+from electrum.wizard import NewWalletWizard, KeystoreWizard, WizardViewState
from electrum.gui.qt.bip39_recovery_dialog import Bip39RecoveryDialog
from electrum.gui.qt.password_dialog import PasswordLayout, PW_NEW, MSG_ENTER_PASSWORD, PasswordLayoutForHW
@@ -51,10 +51,18 @@ MSG_HW_STORAGE_ENCRYPTION = _("Set wallet file encryption.") + '\n'\
class QEKeystoreWizard(KeystoreWizard, QEAbstractWizard, MessageBoxMixin):
_logger = get_logger(__name__)
- def __init__(self, config: 'SimpleConfig', wallet_type: str, app: 'QElectrumApplication', plugins: 'Plugins', *, start_viewstate=None):
+ def __init__(
+ self,
+ *,
+ config: 'SimpleConfig',
+ app: 'QElectrumApplication',
+ plugins: 'Plugins',
+ start_viewstate: WizardViewState = None
+ ):
+ assert 'wallet_type' in start_viewstate.wizard_data, 'wallet_type required'
+
QEAbstractWizard.__init__(self, config, app, start_viewstate=start_viewstate)
KeystoreWizard.__init__(self, plugins)
- self._wallet_type = wallet_type
self.window_title = _('Extend wallet keystore')
# attach gui classes to views
self.navmap_merge({
@@ -417,9 +425,7 @@ class WCKeystoreType(WalletWizardComponent):
self.wizard_data['keystore_type'] = self.choice_w.selected_key
-
class WCExtendKeystore(WalletWizardComponent):
-
def __init__(self, parent, wizard):
WalletWizardComponent.__init__(self, parent, wizard, title=_('Keystore'))
message = _('What type of signing method do you want to add?')
@@ -431,13 +437,10 @@ class WCExtendKeystore(WalletWizardComponent):
self.layout().addWidget(self.choice_w)
self.layout().addStretch(1)
self._valid = True
- self.wizard_data['wallet_type'] = self._wallet_type = wizard._wallet_type
def apply(self):
- self.wizard_data['wallet_type'] = self._wallet_type
self.wizard_data['keystore_type'] = self.choice_w.selected_key
- if multisig_type(self._wallet_type):
- self.wizard_data['wallet_type'] = self._wallet_type = 'multisig'
+ if multisig_type(self.wizard_data['wallet_type']):
self.wizard_data['multisig_participants'] = 2
self.wizard_data['multisig_signatures'] = 2
self.wizard_data['multisig_cosigner_data'] = {}
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.