2424
2525#ifdef ENABLE_WALLET
2626#include < qt/paymentserver.h>
27- #include < qt/walletmodel .h>
27+ #include < qt/walletcontroller .h>
2828#endif
2929
3030#include < interfaces/handler.h>
@@ -184,10 +184,6 @@ BitcoinApplication::BitcoinApplication(interfaces::Node& node, int &argc, char *
184184 clientModel(nullptr ),
185185 window(nullptr ),
186186 pollShutdownTimer(nullptr ),
187- #ifdef ENABLE_WALLET
188- paymentServer (nullptr ),
189- m_wallet_models(),
190- #endif
191187 returnValue(0 ),
192188 platformStyle(nullptr )
193189{
@@ -316,11 +312,8 @@ void BitcoinApplication::requestShutdown()
316312 pollShutdownTimer->stop ();
317313
318314#ifdef ENABLE_WALLET
319- window->removeAllWallets ();
320- for (const WalletModel* walletModel : m_wallet_models) {
321- delete walletModel;
322- }
323- m_wallet_models.clear ();
315+ delete m_wallet_controller;
316+ m_wallet_controller = nullptr ;
324317#endif
325318 delete clientModel;
326319 clientModel = nullptr ;
@@ -331,35 +324,6 @@ void BitcoinApplication::requestShutdown()
331324 Q_EMIT requestedShutdown ();
332325}
333326
334- void BitcoinApplication::addWallet (WalletModel* walletModel)
335- {
336- #ifdef ENABLE_WALLET
337- window->addWallet (walletModel);
338-
339- if (m_wallet_models.empty ()) {
340- window->setCurrentWallet (walletModel);
341- }
342-
343- #ifdef ENABLE_BIP70
344- connect (walletModel, &WalletModel::coinsSent,
345- paymentServer, &PaymentServer::fetchPaymentACK);
346- #endif
347- connect (walletModel, &WalletModel::unload, this , &BitcoinApplication::removeWallet);
348-
349- m_wallet_models.push_back (walletModel);
350- #endif
351- }
352-
353- void BitcoinApplication::removeWallet ()
354- {
355- #ifdef ENABLE_WALLET
356- WalletModel* walletModel = static_cast <WalletModel*>(sender ());
357- m_wallet_models.erase (std::find (m_wallet_models.begin (), m_wallet_models.end (), walletModel));
358- window->removeWallet (walletModel);
359- walletModel->deleteLater ();
360- #endif
361- }
362-
363327void BitcoinApplication::initializeResult (bool success)
364328{
365329 qDebug () << __func__ << " : Initialization result: " << success;
@@ -370,26 +334,22 @@ void BitcoinApplication::initializeResult(bool success)
370334 // Log this only after AppInitMain finishes, as then logging setup is guaranteed complete
371335 qWarning () << " Platform customization:" << platformStyle->getName ();
372336#ifdef ENABLE_WALLET
337+ m_wallet_controller = new WalletController (m_node, platformStyle, optionsModel, this );
373338#ifdef ENABLE_BIP70
374339 PaymentServer::LoadRootCAs ();
375340#endif
376- if (paymentServer) paymentServer->setOptionsModel (optionsModel);
341+ if (paymentServer) {
342+ paymentServer->setOptionsModel (optionsModel);
343+ #ifdef ENABLE_BIP70
344+ connect (m_wallet_controller, &WalletController::coinsSent, paymentServer, &PaymentServer::fetchPaymentACK);
345+ #endif
346+ }
377347#endif
378348
379349 clientModel = new ClientModel (m_node, optionsModel);
380350 window->setClientModel (clientModel);
381-
382351#ifdef ENABLE_WALLET
383- m_handler_load_wallet = m_node.handleLoadWallet ([this ](std::unique_ptr<interfaces::Wallet> wallet) {
384- WalletModel* wallet_model = new WalletModel (std::move (wallet), m_node, platformStyle, optionsModel, nullptr );
385- // Fix wallet model thread affinity.
386- wallet_model->moveToThread (thread ());
387- QMetaObject::invokeMethod (this , " addWallet" , Qt::QueuedConnection, Q_ARG (WalletModel*, wallet_model));
388- });
389-
390- for (auto & wallet : m_node.getWallets ()) {
391- addWallet (new WalletModel (std::move (wallet), m_node, platformStyle, optionsModel));
392- }
352+ window->setWalletController (m_wallet_controller);
393353#endif
394354
395355 // If -min option passed, start window minimized (iconified) or minimized to tray
@@ -493,9 +453,6 @@ int GuiMain(int argc, char* argv[])
493453 // IMPORTANT if it is no longer a typedef use the normal variant above
494454 qRegisterMetaType< CAmount >(" CAmount" );
495455 qRegisterMetaType< std::function<void ()> >(" std::function<void()>" );
496- #ifdef ENABLE_WALLET
497- qRegisterMetaType<WalletModel*>(" WalletModel*" );
498- #endif
499456
500457 // / 2. Parse command-line options. We do this after qt in order to show an error if there are problems parsing these
501458 // Command-line options take precedence:
0 commit comments