Skip to content

Commit 14fe096

Browse files
meshcolliderknst
authored andcommitted
Merge bitcoin#17587: gui: show watch-only balance in send screen
4a96e45 [gui] send: show watch-only balance in send screen (Sjors Provoost) 2689c8f [test] qt: add send screen balance test (Sjors Provoost) Pull request description: Now that we can create a PSBT from a watch-only wallet (bitcoin#16944), we should also display the watch-only balance on the send screen. Before: <img width="1008" alt="before" src="https://user-images.githubusercontent.com/10217/69533384-030e9180-0f78-11ea-9748-c32c957e822e.png"> After: <img width="1009" alt="Schermafbeelding 2019-11-26 om 11 44 17" src="https://user-images.githubusercontent.com/10217/69622879-19811f80-1042-11ea-8279-091012f39b38.png"> 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 4a96e45 jb55: utACK 4a96e45 promag: reACK 4a96e45, rebased and label change since last review. instagibbs: code review and light test ACK bitcoin@4a96e45 Tree-SHA512: 4213549888bd309f72bdbba1453218f4a2b07e809100d786a3791897c75468f9092b06fe4b971942b1c228aa75ee7c04971f262ca9a478b42756e056eb534620
1 parent 25dcd84 commit 14fe096

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

src/qt/forms/sendcoinsdialog.ui

+1-1
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@
11161116
<number>3</number>
11171117
</property>
11181118
<item>
1119-
<widget class="QLabel" name="labelBalanceText">
1119+
<widget class="QLabel" name="labelBalanceName">
11201120
<property name="text">
11211121
<string>Balance:</string>
11221122
</property>

src/qt/res/css/general.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ QDialog#SendCoinsDialog .QScrollArea#scrollArea .QWidget#scrollAreaWidgetContent
16941694
background-color: #00000000;
16951695
}
16961696

1697-
QDialog#SendCoinsDialog QLabel#labelBalanceText,
1697+
QDialog#SendCoinsDialog QLabel#labelBalanceName,
16981698
QDialog#SendCoinsDialog QLabel#labelBalance {
16991699
qproperty-alignment: 'AlignLeading | AlignLeft';
17001700
min-height: 20px;

src/qt/sendcoinsdialog.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ SendCoinsDialog::SendCoinsDialog(bool _fCoinJoin, QWidget* parent) :
7979
}, GUIUtil::FontWeight::Bold);
8080

8181
GUIUtil::setFont({ui->labelBalance,
82-
ui->labelBalanceText
82+
ui->labelBalanceName,
8383
}, GUIUtil::FontWeight::Bold, 14);
8484

8585
GUIUtil::setFont({ui->labelCoinControlFeatures
@@ -641,14 +641,18 @@ void SendCoinsDialog::setBalance(const interfaces::WalletBalances& balances)
641641
{
642642
if(model && model->getOptionsModel())
643643
{
644-
CAmount bal = 0;
644+
CAmount balance = 0;
645645
if (m_coin_control->IsUsingCoinJoin()) {
646-
bal = balances.anonymized_balance;
646+
balance = balances.anonymized_balance;
647647
} else {
648-
bal = balances.balance;
648+
balance = balances.balance;
649649
}
650650

651-
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), bal));
651+
if (model->privateKeysDisabled()) {
652+
balance = balances.watch_only_balance;
653+
ui->labelBalanceName->setText(tr("Watch-only balance:"));
654+
}
655+
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), balance));
652656
}
653657
}
654658

src/qt/test/wallettests.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ void TestGUI(interfaces::Node& node)
139139
sendCoinsDialog.setModel(&walletModel);
140140
transactionView.setModel(&walletModel);
141141

142+
{
143+
// Check balance in send dialog
144+
QLabel* balanceLabel = sendCoinsDialog.findChild<QLabel*>("labelBalance");
145+
QString balanceText = balanceLabel->text();
146+
int unit = walletModel.getOptionsModel()->getDisplayUnit();
147+
CAmount balance = walletModel.wallet().getBalance();
148+
QString balanceComparison = BitcoinUnits::formatWithUnit(unit, balance, false /*, BitcoinUnits::separatorAlways*/);
149+
QCOMPARE(balanceText, balanceComparison);
150+
}
151+
142152
// Send two transactions, and verify they are added to transaction list.
143153
TransactionTableModel* transactionTableModel = walletModel.getTransactionTableModel();
144154
QCOMPARE(transactionTableModel->rowCount({}), 105);

0 commit comments

Comments
 (0)