Skip to content

Commit abb30de

Browse files
committed
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
2 parents 114e89e + 4a96e45 commit abb30de

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/qt/forms/sendcoinsdialog.ui

+1-1
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ Note: Since the fee is calculated on a per-byte basis, a fee of "100 satoshis p
11901190
<number>3</number>
11911191
</property>
11921192
<item>
1193-
<widget class="QLabel" name="label">
1193+
<widget class="QLabel" name="labelBalanceName">
11941194
<property name="sizePolicy">
11951195
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
11961196
<horstretch>0</horstretch>

src/qt/sendcoinsdialog.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,12 @@ void SendCoinsDialog::setBalance(const interfaces::WalletBalances& balances)
562562
{
563563
if(model && model->getOptionsModel())
564564
{
565-
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), balances.balance));
565+
CAmount balance = balances.balance;
566+
if (model->privateKeysDisabled()) {
567+
balance = balances.watch_only_balance;
568+
ui->labelBalanceName->setText(tr("Watch-only balance:"));
569+
}
570+
ui->labelBalance->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), balance));
566571
}
567572
}
568573

src/qt/test/wallettests.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ void TestGUI(interfaces::Node& node)
170170
sendCoinsDialog.setModel(&walletModel);
171171
transactionView.setModel(&walletModel);
172172

173+
{
174+
// Check balance in send dialog
175+
QLabel* balanceLabel = sendCoinsDialog.findChild<QLabel*>("labelBalance");
176+
QString balanceText = balanceLabel->text();
177+
int unit = walletModel.getOptionsModel()->getDisplayUnit();
178+
CAmount balance = walletModel.wallet().getBalance();
179+
QString balanceComparison = BitcoinUnits::formatWithUnit(unit, balance, false, BitcoinUnits::separatorAlways);
180+
QCOMPARE(balanceText, balanceComparison);
181+
}
182+
173183
// Send two transactions, and verify they are added to transaction list.
174184
TransactionTableModel* transactionTableModel = walletModel.getTransactionTableModel();
175185
QCOMPARE(transactionTableModel->rowCount({}), 105);

0 commit comments

Comments
 (0)