From d48a10f435cafc18fdcd418d144622d8c5f9a348 Mon Sep 17 00:00:00 2001 From: Samuel Dobson Date: Fri, 29 Nov 2019 23:15:55 +1300 Subject: [PATCH] Merge #17587: gui: show watch-only balance in send screen 4a96e459d733f1b6427221aaa1874ea00f79988a [gui] send: show watch-only balance in send screen (Sjors Provoost) 2689c8fd7159f47248c5fc365463be8b0e8b039c [test] qt: add send screen balance test (Sjors Provoost) Pull request description: Now that we can create a PSBT from a watch-only wallet (#16944), we should also display the watch-only balance on the send screen. Before: before After: Schermafbeelding 2019-11-26 om 11 44 17 I added a test to check the balance on the send screen, but it only covers regular wallets. A better would add a watch-only only wallet. ACKs for top commit: meshcollider: utACK 4a96e459d733f1b6427221aaa1874ea00f79988a jb55: utACK 4a96e459d733f1b6427221aaa1874ea00f79988a promag: reACK 4a96e45, rebased and label change since last review. instagibbs: code review and light test ACK https://github.com/bitcoin/bitcoin/pull/17587/commits/4a96e459d733f1b6427221aaa1874ea00f79988a Tree-SHA512: 4213549888bd309f72bdbba1453218f4a2b07e809100d786a3791897c75468f9092b06fe4b971942b1c228aa75ee7c04971f262ca9a478b42756e056eb534620 --- src/qt/forms/sendcoinsdialog.ui | 2 +- src/qt/res/css/general.css | 2 +- src/qt/sendcoinsdialog.cpp | 15 +++++++++------ src/qt/test/wallettests.cpp | 10 ++++++++++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/qt/forms/sendcoinsdialog.ui b/src/qt/forms/sendcoinsdialog.ui index e682b2f20d..f70d9e9bd9 100644 --- a/src/qt/forms/sendcoinsdialog.ui +++ b/src/qt/forms/sendcoinsdialog.ui @@ -1116,7 +1116,7 @@ 3 - + Balance: diff --git a/src/qt/res/css/general.css b/src/qt/res/css/general.css index 9c62c7651a..a7b39c2b06 100644 --- a/src/qt/res/css/general.css +++ b/src/qt/res/css/general.css @@ -1694,7 +1694,7 @@ QDialog#SendCoinsDialog .QScrollArea#scrollArea .QWidget#scrollAreaWidgetContent background-color: #00000000; } -QDialog#SendCoinsDialog QLabel#labelBalanceText, +QDialog#SendCoinsDialog QLabel#labelBalanceName, QDialog#SendCoinsDialog QLabel#labelBalance { qproperty-alignment: 'AlignLeading | AlignLeft'; min-height: 20px; diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index 889fa610d8..53c19a9389 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -79,7 +79,7 @@ SendCoinsDialog::SendCoinsDialog(bool _fCoinJoin, QWidget* parent) : }, GUIUtil::FontWeight::Bold); GUIUtil::setFont({ui->labelBalance, - ui->labelBalanceText + ui->labelBalanceName, }, GUIUtil::FontWeight::Bold, 14); GUIUtil::setFont({ui->labelCoinControlFeatures @@ -641,14 +641,17 @@ void SendCoinsDialog::setBalance(const interfaces::WalletBalances& balances) { if(model && model->getOptionsModel()) { - CAmount bal = 0; - if (m_coin_control->IsUsingCoinJoin()) { - bal = balances.anonymized_balance; + CAmount balance = 0; + if (model->privateKeysDisabled()) { + balance = balances.watch_only_balance; + ui->labelBalanceName->setText(tr("Watch-only balance:")); + } else if (m_coin_control->IsUsingCoinJoin()) { + balance = balances.anonymized_balance; } else { - bal = balances.balance; + balance = balances.balance; } - ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), bal)); + ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), balance)); } } diff --git a/src/qt/test/wallettests.cpp b/src/qt/test/wallettests.cpp index 75df8da71d..d8e2630a29 100644 --- a/src/qt/test/wallettests.cpp +++ b/src/qt/test/wallettests.cpp @@ -139,6 +139,16 @@ void TestGUI(interfaces::Node& node) sendCoinsDialog.setModel(&walletModel); transactionView.setModel(&walletModel); + { + // Check balance in send dialog + QLabel* balanceLabel = sendCoinsDialog.findChild("labelBalance"); + QString balanceText = balanceLabel->text(); + int unit = walletModel.getOptionsModel()->getDisplayUnit(); + CAmount balance = walletModel.wallet().getBalance(); + QString balanceComparison = BitcoinUnits::formatWithUnit(unit, balance, false /*, BitcoinUnits::separatorAlways*/); + QCOMPARE(balanceText, balanceComparison); + } + // Send two transactions, and verify they are added to transaction list. TransactionTableModel* transactionTableModel = walletModel.getTransactionTableModel(); QCOMPARE(transactionTableModel->rowCount({}), 105);