Skip to content

Commit a0b15cf

Browse files
UdjinM6claude
authored andcommitted
refactor: Simplify wallet lock state handling in CreateWalletActivity
Simplify the lock state tracking logic in CreateWalletActivity::finish() since mixing-only unlock state is impossible for newly created wallets. Changes: - Use getEncryptionStatus() instead of tracking multiple state variables - Replace was_locked and was_unlocked_for_mixing with single was_locked check - Remove restoreWalletLockState() helper method - inline simple lock call - Add comment explaining why mixing state is impossible at creation time Before: Tracked both was_locked and was_unlocked_for_mixing states After: Only track was_locked since new wallets can only be: * Unencrypted (unlocked) * Encrypted and locked (need to unlock to show mnemonic) This is clearer and removes unnecessary complexity for an impossible state. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 34914f1 commit a0b15cf

File tree

2 files changed

+14
-41
lines changed

2 files changed

+14
-41
lines changed

src/qt/walletcontroller.cpp

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,11 @@ void CreateWalletActivity::finish()
293293
}
294294

295295
// Unlock wallet if encrypted (needed to retrieve mnemonic)
296-
bool was_locked = false;
297-
bool was_unlocked_for_mixing = false;
298-
WalletModel::EncryptionStatus enc_status = m_wallet_model->getEncryptionStatus();
299-
if (enc_status == WalletModel::Locked || enc_status == WalletModel::UnlockedForMixingOnly) {
300-
was_locked = (enc_status == WalletModel::Locked);
301-
was_unlocked_for_mixing = (enc_status == WalletModel::UnlockedForMixingOnly);
302-
// Unlock fully (not just for mixing) to retrieve mnemonic
296+
// Note: Newly created wallet can only be locked (if encrypted) or unencrypted.
297+
// Mixing-only unlock state is not possible at wallet creation time.
298+
const bool was_locked = (m_wallet_model->getEncryptionStatus() == WalletModel::Locked);
299+
if (was_locked) {
300+
// Unlock to retrieve mnemonic using passphrase from wallet creation
303301
if (!m_wallet_model->setWalletLocked(false, m_passphrase, false)) {
304302
QMessageBox::warning(m_parent_widget, tr("Unlock failed"),
305303
tr("Failed to unlock wallet for mnemonic verification. Wallet creation completed but verification skipped."));
@@ -316,7 +314,9 @@ void CreateWalletActivity::finish()
316314

317315
if (!has_mnemonic || mnemonic.empty()) {
318316
// No mnemonic found - log warning and skip verification
319-
restoreWalletLockState(was_locked, was_unlocked_for_mixing);
317+
if (was_locked) {
318+
m_wallet_model->setWalletLocked(true);
319+
}
320320
// Clear sensitive data before showing message
321321
mnemonic.assign(mnemonic.size(), 0);
322322
mnemonic_passphrase.assign(mnemonic_passphrase.size(), 0);
@@ -340,11 +340,15 @@ void CreateWalletActivity::finish()
340340

341341
if (verify_dialog.exec() == QDialog::Accepted) {
342342
// Verification successful
343-
restoreWalletLockState(was_locked, was_unlocked_for_mixing);
343+
if (was_locked) {
344+
m_wallet_model->setWalletLocked(true);
345+
}
344346
Q_EMIT created(m_wallet_model);
345347
} else {
346348
// User cancelled verification
347-
restoreWalletLockState(was_locked, was_unlocked_for_mixing);
349+
if (was_locked) {
350+
m_wallet_model->setWalletLocked(true);
351+
}
348352
QMessageBox::warning(m_parent_widget, tr("Verification cancelled"),
349353
tr("You cancelled mnemonic verification. Please make sure you have saved your mnemonic phrase safely."));
350354
Q_EMIT created(m_wallet_model);
@@ -357,36 +361,6 @@ void CreateWalletActivity::finish()
357361
Q_EMIT finished();
358362
}
359363

360-
void CreateWalletActivity::restoreWalletLockState(bool was_locked, bool was_unlocked_for_mixing)
361-
{
362-
if (!was_locked && !was_unlocked_for_mixing) {
363-
return; // Wallet was not locked, nothing to restore
364-
}
365-
366-
if (!m_wallet_model) {
367-
return; // Safety check: wallet model not available
368-
}
369-
370-
if (was_unlocked_for_mixing) {
371-
// Restore previous mixing-only unlock state
372-
if (!m_wallet_model->setWalletLocked(true)) {
373-
QMessageBox::warning(m_parent_widget, tr("Warning"),
374-
tr("Failed to lock wallet. Please lock it manually."));
375-
return;
376-
}
377-
if (!m_wallet_model->setWalletLocked(false, m_passphrase, true)) {
378-
QMessageBox::warning(m_parent_widget, tr("Warning"),
379-
tr("Failed to restore mixing unlock state."));
380-
}
381-
} else {
382-
// Restore fully locked state
383-
if (!m_wallet_model->setWalletLocked(true)) {
384-
QMessageBox::warning(m_parent_widget, tr("Warning"),
385-
tr("Failed to lock wallet. Please lock it manually."));
386-
}
387-
}
388-
}
389-
390364
void CreateWalletActivity::create()
391365
{
392366
m_create_wallet_dialog = new CreateWalletDialog(m_parent_widget);

src/qt/walletcontroller.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ class CreateWalletActivity : public WalletControllerActivity
123123
void askPassphrase();
124124
void createWallet();
125125
void finish();
126-
void restoreWalletLockState(bool was_locked, bool was_unlocked_for_mixing);
127126

128127
SecureString m_passphrase;
129128
CreateWalletDialog* m_create_wallet_dialog{nullptr};

0 commit comments

Comments
 (0)