diff --git a/doc/release-notes.md b/doc/release-notes.md --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -9,6 +9,8 @@ `true` with sub-fields `ancestor`, `base`, `modified` and `descendant` denominated in BCH. This new field deprecates previous fee fields, such a `fee`, `modifiedfee`, `ancestorfee` and `descendantfee`. + - Wallets loaded dynamically through the RPC interface will now display in + the bitcoin-qt GUI. Dynamic creation of wallets --------------------------------------- diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -229,6 +229,7 @@ /// Handle runaway exceptions. Shows a message box with the problem and /// quits the program. void handleRunawayException(const QString &message); + void addWallet(WalletModel *walletModel); Q_SIGNALS: void requestedInitialize(Config *config, RPCServer *rpcServer, @@ -247,6 +248,7 @@ #ifdef ENABLE_WALLET PaymentServer *paymentServer; std::vector m_wallet_models; + std::unique_ptr m_handler_load_wallet; #endif int returnValue; const PlatformStyle *platformStyle; @@ -453,6 +455,24 @@ Q_EMIT requestedShutdown(); } +void BitcoinApplication::addWallet(WalletModel *walletModel) { +#ifdef ENABLE_WALLET + window->addWallet(walletModel); + + if (m_wallet_models.empty()) { + window->setCurrentWallet(walletModel->getWalletName()); + } + + connect(walletModel, + SIGNAL(coinsSent(WalletModel *, SendCoinsRecipient, QByteArray)), + paymentServer, + SLOT(fetchPaymentACK(WalletModel *, const SendCoinsRecipient &, + QByteArray))); + + m_wallet_models.push_back(walletModel); +#endif +} + void BitcoinApplication::initializeResult(bool success) { qDebug() << __func__ << ": Initialization result: " << success; returnValue = success ? EXIT_SUCCESS : EXIT_FAILURE; @@ -475,26 +495,18 @@ window->setClientModel(clientModel); #ifdef ENABLE_WALLET - bool fFirstWallet = true; - auto wallets = m_node.getWallets(); - for (auto &wallet : wallets) { - WalletModel *const walletModel = new WalletModel( - std::move(wallet), m_node, platformStyle, optionsModel); - - window->addWallet(walletModel); - if (fFirstWallet) { - window->setCurrentWallet(walletModel->getWalletName()); - fFirstWallet = false; - } - - connect( - walletModel, - SIGNAL(coinsSent(WalletModel *, SendCoinsRecipient, QByteArray)), - paymentServer, - SLOT(fetchPaymentACK(WalletModel *, const SendCoinsRecipient &, - QByteArray))); - - m_wallet_models.push_back(walletModel); + m_handler_load_wallet = m_node.handleLoadWallet( + [this](std::unique_ptr wallet) { + QMetaObject::invokeMethod( + this, "addWallet", Qt::QueuedConnection, + Q_ARG(WalletModel *, + new WalletModel(std::move(wallet), m_node, platformStyle, + optionsModel))); + }); + + for (auto &wallet : m_node.getWallets()) { + addWallet(new WalletModel(std::move(wallet), m_node, platformStyle, + optionsModel)); } #endif @@ -662,6 +674,9 @@ // IMPORTANT if it is no longer a typedef use the normal variant above qRegisterMetaType("Amount"); qRegisterMetaType>("std::function"); +#ifdef ENABLE_WALLET + qRegisterMetaType("WalletModel*"); +#endif // Need to register any types Qt doesn't know about if you intend // to use them with the signal/slot mechanism Qt provides. Even pointers. diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -49,9 +49,13 @@ walletView->setClientModel(clientModel); walletView->showOutOfSyncWarning(bOutOfSync); - /* TODO we should goto the currently selected page once dynamically adding - * wallets is supported */ - walletView->gotoOverviewPage(); + WalletView *current_wallet_view = currentWalletView(); + if (current_wallet_view) { + walletView->setCurrentIndex(current_wallet_view->currentIndex()); + } else { + walletView->gotoOverviewPage(); + } + walletStack->addWidget(walletView); mapWalletViews[name] = walletView;