Skip to content

Commit aa7ff86

Browse files
committed
[GUI][Wallet] Use unlock context for HD upgrade
1 parent 060790f commit aa7ff86

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/qt/pivx/topbar.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,14 @@ void TopBar::showUpgradeDialog()
516516
if (ask(title,
517517
tr("Upgrading to HD wallet will improve\nthe wallet's reliability and security.\n\n\nNote that you will need to MAKE\nA NEW BACKUP of your wallet\nafter upgrade it.\n"))) {
518518

519-
// If the wallet is locked, notify that the wallet needs to be unlocked first.
520-
if (walletModel->isWalletLocked()) {
521-
warn(title, tr("Cannot upgrade a locked wallet. Please unlock it first.\n\nOnce it's unlocked you can continue the upgrade\nprocess clicking on the 'HD' icon at the top bar.\n"));
519+
pctx = new WalletModel::UnlockContext(walletModel->requestUnlock());
520+
if (!pctx->isValid()) {
521+
warn(tr("Upgrade Wallet"), tr("Wallet unlock cancelled"));
522+
// delete unlock context
523+
delete pctx;
524+
pctx = nullptr;
522525
return;
523526
}
524-
525527
// Action performed on a separate thread, it's locking cs_main and cs_wallet.
526528
LoadingDialog *dialog = new LoadingDialog(window);
527529
dialog->execute(this, REQUEST_UPGRADE_WALLET);
@@ -535,13 +537,7 @@ void TopBar::loadWalletModel()
535537
if (walletModel->isHDEnabled()) {
536538
ui->pushButtonHDUpgrade->setVisible(false);
537539
} else {
538-
connect(ui->pushButtonHDUpgrade, &ExpandableButton::Mouse_Pressed, [this]() {
539-
if (walletModel->isWalletLocked()) {
540-
inform(tr("Cannot upgrade a locked wallet. Please unlock it first."));
541-
return;
542-
}
543-
showUpgradeDialog();
544-
});
540+
connect(ui->pushButtonHDUpgrade, &ExpandableButton::Mouse_Pressed, this, &TopBar::showUpgradeDialog);
545541

546542
// Upgrade wallet timer, only once. launched 4 seconds after the wallet started.
547543
QTimer::singleShot(4000, [this](){
@@ -700,6 +696,11 @@ void TopBar::updateHDState(const bool& upgraded, const QString& upgradeError)
700696
} else {
701697
warn(tr("Upgrade Wallet Error"), upgradeError);
702698
}
699+
// delete global unlock context
700+
if (pctx) {
701+
delete pctx;
702+
pctx = nullptr;
703+
}
703704
}
704705

705706
void TopBar::run(int type)

src/qt/pivx/topbar.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ private Q_SLOTS:
8282
QTimer* timerStakingIcon = nullptr;
8383
bool isInitializing = true;
8484

85+
// pointer to global unlock context (for multithread unlock/relock)
86+
WalletModel::UnlockContext* pctx = nullptr;
87+
8588
void updateTorIcon();
8689
};
8790

0 commit comments

Comments
 (0)