Skip to content

Commit e545503

Browse files
committed
Merge #13097: ui: Support wallets loaded dynamically
2e75134 fixup! ui: Support wallets loaded dynamically (João Barbosa) 0e674ba ui: Support wallets loaded dynamically (João Barbosa) 1c8fe0b ui: Remove unnecessary variable fFirstWallet (João Barbosa) Pull request description: Add support in the UI for wallets loaded dynamically. Tree-SHA512: 4016d61580b31e28c49861b1cb0e77fac5417f9676a6ce6156be28cb6059fdf3d3dd4d57dbbc22a574ad428c2a4a3702aedca596a84e644ce148e1084feb29c9
2 parents 2a7c53b + 2e75134 commit e545503

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

doc/release-notes-pr10740.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Previously, wallets could only be loaded at startup, by specifying `-wallet` par
55

66
The wallet can be specified as file/directory basename (which must be located in the `walletdir` directory), or as an absolute path to a file/directory.
77

8-
This feature is currently only available through the RPC interface. Wallets loaded in this way will not display in the bitcoin-qt GUI.
8+
This feature is currently only available through the RPC interface. Wallets loaded in this way will display in the bitcoin-qt GUI.

src/qt/bitcoin.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public Q_SLOTS:
234234
void shutdownResult();
235235
/// Handle runaway exceptions. Shows a message box with the problem and quits the program.
236236
void handleRunawayException(const QString &message);
237+
void addWallet(WalletModel* walletModel);
237238

238239
Q_SIGNALS:
239240
void requestedInitialize();
@@ -251,6 +252,7 @@ public Q_SLOTS:
251252
#ifdef ENABLE_WALLET
252253
PaymentServer* paymentServer;
253254
std::vector<WalletModel*> m_wallet_models;
255+
std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
254256
#endif
255257
int returnValue;
256258
const PlatformStyle *platformStyle;
@@ -447,6 +449,22 @@ void BitcoinApplication::requestShutdown()
447449
Q_EMIT requestedShutdown();
448450
}
449451

452+
void BitcoinApplication::addWallet(WalletModel* walletModel)
453+
{
454+
#ifdef ENABLE_WALLET
455+
window->addWallet(walletModel);
456+
457+
if (m_wallet_models.empty()) {
458+
window->setCurrentWallet(walletModel->getWalletName());
459+
}
460+
461+
connect(walletModel, SIGNAL(coinsSent(WalletModel*, SendCoinsRecipient, QByteArray)),
462+
paymentServer, SLOT(fetchPaymentACK(WalletModel*, const SendCoinsRecipient&, QByteArray)));
463+
464+
m_wallet_models.push_back(walletModel);
465+
#endif
466+
}
467+
450468
void BitcoinApplication::initializeResult(bool success)
451469
{
452470
qDebug() << __func__ << ": Initialization result: " << success;
@@ -465,21 +483,13 @@ void BitcoinApplication::initializeResult(bool success)
465483
window->setClientModel(clientModel);
466484

467485
#ifdef ENABLE_WALLET
468-
bool fFirstWallet = true;
469-
auto wallets = m_node.getWallets();
470-
for (auto& wallet : wallets) {
471-
WalletModel * const walletModel = new WalletModel(std::move(wallet), m_node, platformStyle, optionsModel);
472-
473-
window->addWallet(walletModel);
474-
if (fFirstWallet) {
475-
window->setCurrentWallet(walletModel->getWalletName());
476-
fFirstWallet = false;
477-
}
486+
m_handler_load_wallet = m_node.handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) {
487+
QMetaObject::invokeMethod(this, "addWallet", Qt::QueuedConnection,
488+
Q_ARG(WalletModel*, new WalletModel(std::move(wallet), m_node, platformStyle, optionsModel)));
489+
});
478490

479-
connect(walletModel, SIGNAL(coinsSent(WalletModel*,SendCoinsRecipient,QByteArray)),
480-
paymentServer, SLOT(fetchPaymentACK(WalletModel*,const SendCoinsRecipient&,QByteArray)));
481-
482-
m_wallet_models.push_back(walletModel);
491+
for (auto& wallet : m_node.getWallets()) {
492+
addWallet(new WalletModel(std::move(wallet), m_node, platformStyle, optionsModel));
483493
}
484494
#endif
485495

@@ -595,6 +605,9 @@ int main(int argc, char *argv[])
595605
// IMPORTANT if it is no longer a typedef use the normal variant above
596606
qRegisterMetaType< CAmount >("CAmount");
597607
qRegisterMetaType< std::function<void(void)> >("std::function<void(void)>");
608+
#ifdef ENABLE_WALLET
609+
qRegisterMetaType<WalletModel*>("WalletModel*");
610+
#endif
598611

599612
/// 3. Application identification
600613
// must be set before OptionsModel is initialized or translations are loaded,

src/qt/walletframe.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ bool WalletFrame::addWallet(WalletModel *walletModel)
5757
walletView->setWalletModel(walletModel);
5858
walletView->showOutOfSyncWarning(bOutOfSync);
5959

60-
/* TODO we should goto the currently selected page once dynamically adding wallets is supported */
61-
walletView->gotoOverviewPage();
60+
WalletView* current_wallet_view = currentWalletView();
61+
if (current_wallet_view) {
62+
walletView->setCurrentIndex(current_wallet_view->currentIndex());
63+
} else {
64+
walletView->gotoOverviewPage();
65+
}
66+
6267
walletStack->addWidget(walletView);
6368
mapWalletViews[name] = walletView;
6469

0 commit comments

Comments
 (0)