Skip to content

Commit cd98b71

Browse files
committed
gui: 'getAvailableBalance', include watch only balance
Only for wallets with private keys disabled. The returned amount need to include the watch-only available balance too. Solves #26687.
1 parent 74eac3a commit cd98b71

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/qt/walletmodel.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,5 +613,17 @@ uint256 WalletModel::getLastBlockProcessed() const
613613

614614
CAmount WalletModel::getAvailableBalance(const CCoinControl* control)
615615
{
616-
return control && control->HasSelected() ? wallet().getAvailableBalance(*control) : getCachedBalance().balance;
616+
// No selected coins, return the cached balance
617+
if (!control || !control->HasSelected()) {
618+
const interfaces::WalletBalances& balances = getCachedBalance();
619+
CAmount available_balance = balances.balance;
620+
// if wallet private keys are disabled, this is a watch-only wallet
621+
// so, let's include the watch-only balance.
622+
if (balances.have_watch_only && m_wallet->privateKeysDisabled()) {
623+
available_balance += balances.watch_only_balance;
624+
}
625+
return available_balance;
626+
}
627+
// Fetch balance from the wallet, taking into account the selected coins
628+
return wallet().getAvailableBalance(*control);
617629
}

0 commit comments

Comments
 (0)