Skip to content

Commit 931707c

Browse files
kwvgUdjinM6
andcommitted
feat(qt): enable wallet rescan for multiple loaded wallets
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
1 parent 025df83 commit 931707c

2 files changed

Lines changed: 34 additions & 24 deletions

File tree

src/qt/rpcconsole.cpp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, QWidget* parent, Qt::WindowFlags
580580
#ifdef ENABLE_WALLET
581581
connect(ui->btn_rescan1, &QPushButton::clicked, this, &RPCConsole::walletRescan1);
582582
connect(ui->btn_rescan2, &QPushButton::clicked, this, &RPCConsole::walletRescan2);
583+
connect(ui->WalletSelector, qOverload<int>(&QComboBox::currentIndexChanged), this, &RPCConsole::onWalletChanged);
583584
#endif // ENABLE_WALLET
584585
connect(ui->btn_reindex, &QPushButton::clicked, this, &RPCConsole::walletReindex);
585586

@@ -833,40 +834,29 @@ void RPCConsole::addWallet(WalletModel * const walletModel)
833834
if (ui->WalletSelector->count() == 2) {
834835
// First wallet added, set to default to match wallet RPC behavior
835836
ui->WalletSelector->setCurrentIndex(1);
836-
// The only loaded wallet
837-
ui->btn_rescan1->setEnabled(true);
838-
ui->btn_rescan2->setEnabled(true);
839-
QString wallet_path = GUIUtil::PathToQString(GetWalletDir()) + QDir::separator().toLatin1();
840-
QString wallet_name = walletModel->getWalletName().isEmpty() ? "wallet.dat" : walletModel->getWalletName();
841-
ui->wallet_path->setText(wallet_path + wallet_name);
842-
} else {
837+
}
838+
839+
// Update wallet path and button states for currently selected wallet
840+
onWalletChanged();
841+
842+
// Show wallet selector when multiple wallets are loaded
843+
if (ui->WalletSelector->count() > 2) {
843844
ui->WalletSelector->setVisible(true);
844845
ui->WalletSelectorLabel->setVisible(true);
845-
// No wallet recovery for multiple loaded wallets
846-
ui->btn_rescan1->setEnabled(false);
847-
ui->btn_rescan2->setEnabled(false);
848-
ui->wallet_path->clear();
849846
}
850847
}
851848

852849
void RPCConsole::removeWallet(WalletModel * const walletModel)
853850
{
854851
ui->WalletSelector->removeItem(ui->WalletSelector->findData(QVariant::fromValue(walletModel)));
852+
853+
// Update wallet path and button states for currently selected wallet (or clear/disable if none)
854+
onWalletChanged();
855+
856+
// Hide wallet selector when back to single wallet
855857
if (ui->WalletSelector->count() == 2) {
856858
ui->WalletSelector->setVisible(false);
857859
ui->WalletSelectorLabel->setVisible(false);
858-
// Back to the only loaded wallet
859-
ui->btn_rescan1->setEnabled(true);
860-
ui->btn_rescan2->setEnabled(true);
861-
WalletModel* wallet_model = ui->WalletSelector->itemData(1).value<WalletModel*>();
862-
QString wallet_path = GUIUtil::PathToQString(GetWalletDir()) + QDir::separator().toLatin1();
863-
QString wallet_name = wallet_model->getWalletName().isEmpty() ? "wallet.dat" : wallet_model->getWalletName();
864-
ui->wallet_path->setText(wallet_path + wallet_name);
865-
} else {
866-
// No wallet recovery for multiple loaded wallets
867-
ui->btn_rescan1->setEnabled(false);
868-
ui->btn_rescan2->setEnabled(false);
869-
ui->wallet_path->clear();
870860
}
871861
}
872862

@@ -875,6 +865,24 @@ void RPCConsole::setCurrentWallet(WalletModel* const wallet_model)
875865
QVariant data = QVariant::fromValue(wallet_model);
876866
ui->WalletSelector->setCurrentIndex(ui->WalletSelector->findData(data));
877867
}
868+
869+
void RPCConsole::onWalletChanged()
870+
{
871+
WalletModel* wallet_model = ui->WalletSelector->currentData().value<WalletModel*>();
872+
if (wallet_model) {
873+
QString wallet_path = GUIUtil::PathToQString(GetWalletDir()) + QDir::separator().toLatin1();
874+
QString wallet_name = wallet_model->getWalletName().isEmpty() ? "wallet.dat" : wallet_model->getWalletName();
875+
ui->wallet_path->setText(wallet_path + wallet_name);
876+
// Enable rescan buttons when a valid wallet is selected
877+
ui->btn_rescan1->setEnabled(true);
878+
ui->btn_rescan2->setEnabled(true);
879+
} else {
880+
ui->wallet_path->clear();
881+
// Disable rescan buttons when no wallet is selected (e.g., "(none)")
882+
ui->btn_rescan1->setEnabled(false);
883+
ui->btn_rescan2->setEnabled(false);
884+
}
885+
}
878886
#endif
879887

880888
static QString categoryClass(int category)
@@ -931,7 +939,7 @@ void RPCConsole::walletRescan(bool from_genesis)
931939
return;
932940
}
933941

934-
WalletModel* wallet_model{ui->WalletSelector->itemData(1).value<WalletModel*>()};
942+
WalletModel* wallet_model{ui->WalletSelector->currentData().value<WalletModel*>()};
935943
if (!wallet_model) {
936944
QMessageBox::critical(this, PACKAGE_NAME, QObject::tr("Error: Rescan failed. Wallet not loaded."));
937945
return;

src/qt/rpcconsole.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ public Q_SLOTS:
181181
#ifdef ENABLE_WALLET
182182
/** Initiate a wallet rescan */
183183
void walletRescan(bool from_genesis);
184+
/** Update wallet UI when selected wallet changes */
185+
void onWalletChanged();
184186
#endif // ENABLE_WALLET
185187

186188
enum ColumnWidths

0 commit comments

Comments
 (0)