Skip to content

Commit 6d6a7a8

Browse files
committed
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); ```
1 parent 81ea66c commit 6d6a7a8

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/qt/bitcoingui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,10 +632,10 @@ void BitcoinGUI::setWalletController(WalletController* wallet_controller)
632632
void BitcoinGUI::addWallet(WalletModel* walletModel)
633633
{
634634
if (!walletFrame) return;
635+
if (!walletFrame->addWallet(walletModel)) return;
635636
const QString display_name = walletModel->getDisplayName();
636637
setWalletActionsEnabled(true);
637638
rpcConsole->addWallet(walletModel);
638-
walletFrame->addWallet(walletModel);
639639
m_wallet_selector->addItem(display_name, QVariant::fromValue(walletModel));
640640
if (m_wallet_selector->count() == 2) {
641641
m_wallet_selector_label_action->setVisible(true);

src/qt/walletframe.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ void WalletFrame::setClientModel(ClientModel *_clientModel)
3939
this->clientModel = _clientModel;
4040
}
4141

42-
void WalletFrame::addWallet(WalletModel *walletModel)
42+
bool WalletFrame::addWallet(WalletModel *walletModel)
4343
{
44-
if (!gui || !clientModel || !walletModel) return;
44+
if (!gui || !clientModel || !walletModel) return false;
4545

46-
if (mapWalletViews.count(walletModel) > 0) return;
46+
if (mapWalletViews.count(walletModel) > 0) return false;
4747

4848
WalletView *walletView = new WalletView(platformStyle, this);
4949
walletView->setBitcoinGUI(gui);
@@ -67,6 +67,8 @@ void WalletFrame::addWallet(WalletModel *walletModel)
6767
});
6868

6969
connect(walletView, &WalletView::outOfSyncWarningClicked, this, &WalletFrame::outOfSyncWarningClicked);
70+
71+
return true;
7072
}
7173

7274
void WalletFrame::setCurrentWallet(WalletModel* wallet_model)

src/qt/walletframe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class WalletFrame : public QFrame
3636

3737
void setClientModel(ClientModel *clientModel);
3838

39-
void addWallet(WalletModel *walletModel);
39+
bool addWallet(WalletModel *walletModel);
4040
void setCurrentWallet(WalletModel* wallet_model);
4141
void removeWallet(WalletModel* wallet_model);
4242
void removeAllWallets();

0 commit comments

Comments
 (0)