gui: Fix duplicate wallet showing up

The slot BitcoinGUI::addWallet can be invoked twice for the same
WalletModel due to a concurrent wallet being loaded after the first `connect()`:

```cpp
 connect(wallet_controller, &WalletController::walletAdded, this, &BitcoinGUI::addWallet);
 connect(wallet_controller, &WalletController::walletRemoved, this, &BitcoinGUI::removeWallet);

 for (WalletModel* wallet_model : m_wallet_controller->getOpenWallets()) {
     addWallet(wallet_model);
```
This commit is contained in:
João Barbosa
2019-09-26 21:43:44 +01:00
parent 81ea66c30e
commit 6d6a7a8403
3 changed files with 7 additions and 5 deletions

View File

@@ -632,10 +632,10 @@ void BitcoinGUI::setWalletController(WalletController* wallet_controller)
void BitcoinGUI::addWallet(WalletModel* walletModel) void BitcoinGUI::addWallet(WalletModel* walletModel)
{ {
if (!walletFrame) return; if (!walletFrame) return;
if (!walletFrame->addWallet(walletModel)) return;
const QString display_name = walletModel->getDisplayName(); const QString display_name = walletModel->getDisplayName();
setWalletActionsEnabled(true); setWalletActionsEnabled(true);
rpcConsole->addWallet(walletModel); rpcConsole->addWallet(walletModel);
walletFrame->addWallet(walletModel);
m_wallet_selector->addItem(display_name, QVariant::fromValue(walletModel)); m_wallet_selector->addItem(display_name, QVariant::fromValue(walletModel));
if (m_wallet_selector->count() == 2) { if (m_wallet_selector->count() == 2) {
m_wallet_selector_label_action->setVisible(true); m_wallet_selector_label_action->setVisible(true);

View File

@@ -39,11 +39,11 @@ void WalletFrame::setClientModel(ClientModel *_clientModel)
this->clientModel = _clientModel; this->clientModel = _clientModel;
} }
void WalletFrame::addWallet(WalletModel *walletModel) bool WalletFrame::addWallet(WalletModel *walletModel)
{ {
if (!gui || !clientModel || !walletModel) return; if (!gui || !clientModel || !walletModel) return false;
if (mapWalletViews.count(walletModel) > 0) return; if (mapWalletViews.count(walletModel) > 0) return false;
WalletView *walletView = new WalletView(platformStyle, this); WalletView *walletView = new WalletView(platformStyle, this);
walletView->setBitcoinGUI(gui); walletView->setBitcoinGUI(gui);
@@ -67,6 +67,8 @@ void WalletFrame::addWallet(WalletModel *walletModel)
}); });
connect(walletView, &WalletView::outOfSyncWarningClicked, this, &WalletFrame::outOfSyncWarningClicked); connect(walletView, &WalletView::outOfSyncWarningClicked, this, &WalletFrame::outOfSyncWarningClicked);
return true;
} }
void WalletFrame::setCurrentWallet(WalletModel* wallet_model) void WalletFrame::setCurrentWallet(WalletModel* wallet_model)

View File

@@ -36,7 +36,7 @@ public:
void setClientModel(ClientModel *clientModel); void setClientModel(ClientModel *clientModel);
void addWallet(WalletModel *walletModel); bool addWallet(WalletModel *walletModel);
void setCurrentWallet(WalletModel* wallet_model); void setCurrentWallet(WalletModel* wallet_model);
void removeWallet(WalletModel* wallet_model); void removeWallet(WalletModel* wallet_model);
void removeAllWallets(); void removeAllWallets();