aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfurszy <matiasfurszyfer@protonmail.com>2022-12-14 22:30:59 -0300
committerfurszy <matiasfurszyfer@protonmail.com>2023-04-03 17:23:43 -0300
commitcd98b717398f7b13ace91ea9efac9ce1e60b4d62 (patch)
tree1573dc0e0b3dcdec62f1b3211305b19b3b8c1bdb /src
parent74eac3a82fc948467d5a15a5af420b36ce8eb04a (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/qt/walletmodel.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp
index 61172d1625..565b732bf0 100644
--- a/src/qt/walletmodel.cpp
+++ b/src/qt/walletmodel.cpp
@@ -613,5 +613,17 @@ uint256 WalletModel::getLastBlockProcessed() const
CAmount WalletModel::getAvailableBalance(const CCoinControl* control)
{
- return control && control->HasSelected() ? wallet().getAvailableBalance(*control) : getCachedBalance().balance;
+ // No selected coins, return the cached balance
+ if (!control || !control->HasSelected()) {
+ const interfaces::WalletBalances& balances = getCachedBalance();
+ CAmount available_balance = balances.balance;
+ // if wallet private keys are disabled, this is a watch-only wallet
+ // so, let's include the watch-only balance.
+ if (balances.have_watch_only && m_wallet->privateKeysDisabled()) {
+ available_balance += balances.watch_only_balance;
+ }
+ return available_balance;
+ }
+ // Fetch balance from the wallet, taking into account the selected coins
+ return wallet().getAvailableBalance(*control);
}