Skip to content

Commit 50633b4

Browse files
committed
gui: add coins (UTXOs) tab and makes it view-only
- Shows Coins tab next to Transactions - Adds view-only mode to coin control dialog
1 parent a33bd76 commit 50633b4

File tree

8 files changed

+100
-7
lines changed

8 files changed

+100
-7
lines changed

src/qt/bitcoin.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<file alias="bitcoin">res/icons/bitcoin.png</file>
44
<file alias="address-book">res/icons/address-book.png</file>
55
<file alias="send">res/icons/send.png</file>
6+
<file alias="coins">res/icons/coins.png</file>
67
<file alias="connect_0">res/icons/connect0.png</file>
78
<file alias="connect_1">res/icons/connect1.png</file>
89
<file alias="connect_2">res/icons/connect2.png</file>

src/qt/bitcoingui.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,14 @@ void BitcoinGUI::createActions()
277277
historyAction->setShortcut(QKeySequence(QStringLiteral("Alt+4")));
278278
tabGroup->addAction(historyAction);
279279

280+
showCoinsAction = new QAction(platformStyle->SingleColorIcon(":/icons/coins"), tr("&Coins"), this);
281+
showCoinsAction->setStatusTip(tr("View wallet coins (UTXOs)"));
282+
showCoinsAction->setToolTip(showCoinsAction->statusTip());
283+
showCoinsAction->setCheckable(false);
284+
showCoinsAction->setShortcut(QKeySequence(QStringLiteral("Alt+5")));
285+
tabGroup->addAction(showCoinsAction);
286+
connect(showCoinsAction, &QAction::triggered, this, &BitcoinGUI::showCoins);
287+
280288
#ifdef ENABLE_WALLET
281289
// These showNormalIfMinimized are needed because Send Coins and Receive Coins
282290
// can be triggered from the tray menu, and need to show the GUI to be useful.
@@ -601,6 +609,7 @@ void BitcoinGUI::createToolBars()
601609
toolbar->addAction(sendCoinsAction);
602610
toolbar->addAction(receiveCoinsAction);
603611
toolbar->addAction(historyAction);
612+
toolbar->addAction(showCoinsAction);
604613
overviewAction->setChecked(true);
605614

606615
#ifdef ENABLE_WALLET
@@ -1468,6 +1477,16 @@ void BitcoinGUI::updateWalletStatus()
14681477
}
14691478
#endif // ENABLE_WALLET
14701479

1480+
#ifdef ENABLE_WALLET
1481+
void BitcoinGUI::showCoins()
1482+
{
1483+
if (!walletFrame) return;
1484+
if (WalletView* wv = walletFrame->currentWalletView()) {
1485+
wv->showCoinsDialog();
1486+
}
1487+
}
1488+
#endif // ENABLE_WALLET
1489+
14711490
void BitcoinGUI::updateProxyIcon()
14721491
{
14731492
std::string ip_port;
@@ -1680,3 +1699,10 @@ void UnitDisplayStatusBarControl::onMenuSelection(QAction* action)
16801699
optionsModel->setDisplayUnit(action->data());
16811700
}
16821701
}
1702+
1703+
void UnitDisplayStatusBarControl::showCoins()
1704+
{
1705+
if (BitcoinGUI* window = qobject_cast<BitcoinGUI*>(parent())) {
1706+
window->showCoins();
1707+
}
1708+
}

src/qt/bitcoingui.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class BitcoinGUI : public QMainWindow
136136
QAction* historyAction = nullptr;
137137
QAction* quitAction = nullptr;
138138
QAction* sendCoinsAction = nullptr;
139+
QAction* showCoinsAction = nullptr;
139140
QAction* usedSendingAddressesAction = nullptr;
140141
QAction* usedReceivingAddressesAction = nullptr;
141142
QAction* signMessageAction = nullptr;
@@ -283,6 +284,8 @@ public Q_SLOTS:
283284
void gotoReceiveCoinsPage();
284285
/** Switch to send coins page */
285286
void gotoSendCoinsPage(QString addr = "");
287+
/** Switch to show coins page*/
288+
void showCoins();
286289

287290
/** Show Sign/Verify Message dialog and switch to sign message tab */
288291
void gotoSignMessageTab(QString addr = "");
@@ -351,6 +354,7 @@ private Q_SLOTS:
351354
void updateDisplayUnit(BitcoinUnit newUnits);
352355
/** Tells underlying optionsModel to update its current display unit. */
353356
void onMenuSelection(QAction* action);
357+
void showCoins();
354358
};
355359

356360
#endif // BITCOIN_QT_BITCOINGUI_H

src/qt/coincontroldialog.cpp

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,34 @@ void CoinControlDialog::changeEvent(QEvent* e)
550550
QDialog::changeEvent(e);
551551
}
552552

553+
void CoinControlDialog::setViewOnly(bool view_only)
554+
{
555+
m_view_only = view_only;
556+
557+
ui->pushButtonSelectAll->setVisible(!view_only);
558+
ui->treeWidget->setColumnHidden(COLUMN_CHECKBOX, view_only);
559+
ui->frame->setVisible(!view_only);
560+
561+
ui->labelCoinControlQuantity->setVisible(!view_only);
562+
ui->labelCoinControlAmount->setVisible(!view_only);
563+
ui->labelCoinControlFee->setVisible(!view_only);
564+
ui->labelCoinControlAfterFee->setVisible(!view_only);
565+
ui->labelCoinControlBytes->setVisible(!view_only);
566+
ui->labelCoinControlChange->setVisible(!view_only);
567+
568+
ui->labelCoinControlQuantityText->setVisible(!view_only);
569+
ui->labelCoinControlAmountText->setVisible(!view_only);
570+
ui->labelCoinControlFeeText->setVisible(!view_only);
571+
ui->labelCoinControlAfterFeeText->setVisible(!view_only);
572+
ui->labelCoinControlBytesText->setVisible(!view_only);
573+
ui->labelCoinControlChangeText->setVisible(!view_only);
574+
575+
if (view_only) {
576+
lockAction->setVisible(false);
577+
unlockAction->setVisible(false);
578+
}
579+
}
580+
553581
void CoinControlDialog::updateView()
554582
{
555583
if (!model || !model->getOptionsModel() || !model->getAddressTableModel())
@@ -560,8 +588,14 @@ void CoinControlDialog::updateView()
560588
ui->treeWidget->clear();
561589
ui->treeWidget->setEnabled(false); // performance, otherwise updateLabels would be called for every checked checkbox
562590
ui->treeWidget->setAlternatingRowColors(!treeMode);
563-
QFlags<Qt::ItemFlag> flgCheckbox = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
564-
QFlags<Qt::ItemFlag> flgTristate = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsAutoTristate;
591+
592+
QFlags<Qt::ItemFlag> flgCheckbox = m_view_only ?
593+
(Qt::ItemIsSelectable | Qt::ItemIsEnabled) :
594+
(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
595+
596+
QFlags<Qt::ItemFlag> flgTristate = m_view_only ?
597+
(Qt::ItemIsSelectable | Qt::ItemIsEnabled) :
598+
(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsAutoTristate);
565599

566600
BitcoinUnit nDisplayUnit = model->getOptionsModel()->getDisplayUnit();
567601

@@ -578,7 +612,10 @@ void CoinControlDialog::updateView()
578612
itemWalletAddress = new CCoinControlWidgetItem(ui->treeWidget);
579613

580614
itemWalletAddress->setFlags(flgTristate);
581-
itemWalletAddress->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked);
615+
616+
if (!m_view_only) {
617+
itemWalletAddress->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked);
618+
}
582619

583620
// label
584621
itemWalletAddress->setText(COLUMN_LABEL, sWalletLabel);
@@ -599,7 +636,9 @@ void CoinControlDialog::updateView()
599636
if (treeMode) itemOutput = new CCoinControlWidgetItem(itemWalletAddress);
600637
else itemOutput = new CCoinControlWidgetItem(ui->treeWidget);
601638
itemOutput->setFlags(flgCheckbox);
602-
itemOutput->setCheckState(COLUMN_CHECKBOX,Qt::Unchecked);
639+
if (!m_view_only) {
640+
itemOutput->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked);
641+
}
603642

604643
// address
605644
CTxDestination outputAddress;
@@ -649,13 +688,15 @@ void CoinControlDialog::updateView()
649688
// disable locked coins
650689
if (model->wallet().isLockedCoin(output))
651690
{
652-
m_coin_control.UnSelect(output); // just to be sure
691+
if (!m_view_only) {
692+
m_coin_control.UnSelect(output); // just to be sure
693+
}
653694
itemOutput->setDisabled(true);
654695
itemOutput->setIcon(COLUMN_CHECKBOX, platformStyle->SingleColorIcon(":/icons/lock_closed"));
655696
}
656697

657698
// set checkbox
658-
if (m_coin_control.IsSelected(output))
699+
if (!m_view_only && m_coin_control.IsSelected(output))
659700
itemOutput->setCheckState(COLUMN_CHECKBOX, Qt::Checked);
660701
}
661702

@@ -669,7 +710,7 @@ void CoinControlDialog::updateView()
669710
}
670711

671712
// expand all partially selected
672-
if (treeMode)
713+
if (treeMode && !m_view_only)
673714
{
674715
for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++)
675716
if (ui->treeWidget->topLevelItem(i)->checkState(COLUMN_CHECKBOX) == Qt::PartiallyChecked)

src/qt/coincontroldialog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class CoinControlDialog : public QDialog
5353
static QList<CAmount> payAmounts;
5454
static bool fSubtractFeeFromAmount;
5555

56+
void setViewOnly(bool view_only);
57+
5658
protected:
5759
void changeEvent(QEvent* e) override;
5860

@@ -71,6 +73,8 @@ class CoinControlDialog : public QDialog
7173

7274
const PlatformStyle *platformStyle;
7375

76+
bool m_view_only{false};
77+
7478
void sortView(int, Qt::SortOrder);
7579
void updateView();
7680

src/qt/res/icons/coins.png

8.51 KB
Loading

src/qt/walletview.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include <qt/transactiontablemodel.h>
1818
#include <qt/transactionview.h>
1919
#include <qt/walletmodel.h>
20+
#include <qt/coincontroldialog.h>
21+
#include <wallet/coincontrol.h>
22+
#include <wallet/coincontrol.h>
2023

2124
#include <interfaces/node.h>
2225
#include <node/interface_ui.h>
@@ -166,6 +169,18 @@ void WalletView::gotoSendCoinsPage(QString addr)
166169
sendCoinsPage->setAddress(addr);
167170
}
168171

172+
void WalletView::showCoinsDialog()
173+
{
174+
if (!walletModel) return;
175+
176+
wallet::CCoinControl coin_control;
177+
178+
CoinControlDialog dlg(coin_control, walletModel, platformStyle, this);
179+
dlg.setViewOnly(true);
180+
dlg.setWindowTitle(tr("Coins (UTXOs)"));
181+
dlg.exec();
182+
}
183+
169184
void WalletView::gotoSignMessageTab(QString addr)
170185
{
171186
// calls show() in showTab_SM()

src/qt/walletview.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public Q_SLOTS:
7979
void gotoReceiveCoinsPage();
8080
/** Switch to send coins page */
8181
void gotoSendCoinsPage(QString addr = "");
82+
/** Switch to show coins page*/
83+
void showCoinsDialog();
8284

8385
/** Show Sign/Verify Message dialog and switch to sign message tab */
8486
void gotoSignMessageTab(QString addr = "");

0 commit comments

Comments
 (0)