Skip to content

Commit d41037b

Browse files
qt: mask values on transactions view
1 parent 4f841cb commit d41037b

File tree

8 files changed

+28
-8
lines changed

8 files changed

+28
-8
lines changed

src/qt/bitcoingui.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ void BitcoinGUI::createActions()
456456
m_wallet_controller->closeAllWallets(this);
457457
});
458458
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::setPrivacy);
459+
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::enableHistoryAction);
459460
}
460461
#endif // ENABLE_WALLET
461462

@@ -668,6 +669,12 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
668669
}
669670

670671
#ifdef ENABLE_WALLET
672+
void BitcoinGUI::enableHistoryAction(bool privacy)
673+
{
674+
historyAction->setEnabled(!privacy);
675+
if (historyAction->isChecked()) gotoOverviewPage();
676+
}
677+
671678
void BitcoinGUI::setWalletController(WalletController* wallet_controller)
672679
{
673680
assert(!m_wallet_controller);
@@ -716,7 +723,9 @@ void BitcoinGUI::addWallet(WalletModel* walletModel)
716723
connect(wallet_view, &WalletView::encryptionStatusChanged, this, &BitcoinGUI::updateWalletStatus);
717724
connect(wallet_view, &WalletView::incomingTransaction, this, &BitcoinGUI::incomingTransaction);
718725
connect(this, &BitcoinGUI::setPrivacy, wallet_view, &WalletView::setPrivacy);
719-
wallet_view->setPrivacy(isPrivacyModeActivated());
726+
const bool privacy = isPrivacyModeActivated();
727+
wallet_view->setPrivacy(privacy);
728+
enableHistoryAction(privacy);
720729
const QString display_name = walletModel->getDisplayName();
721730
m_wallet_selector->addItem(display_name, QVariant::fromValue(walletModel));
722731
}

src/qt/bitcoingui.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ public Q_SLOTS:
288288
void gotoVerifyMessageTab(QString addr = "");
289289
/** Load Partially Signed Bitcoin Transaction from file or clipboard */
290290
void gotoLoadPSBT(bool from_clipboard = false);
291+
/** Enable history action when privacy is changed */
292+
void enableHistoryAction(bool privacy);
291293

292294
/** Show open dialog */
293295
void openClicked();

src/qt/bitcoinunits.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ QString BitcoinUnits::formatHtmlWithUnit(Unit unit, const CAmount& amount, bool
140140
return QString("<span style='white-space: nowrap;'>%1</span>").arg(str);
141141
}
142142

143-
QString BitcoinUnits::formatWithPrivacy(Unit unit, const CAmount& amount, SeparatorStyle separators, bool privacy)
143+
QString BitcoinUnits::formatWithPrivacy(Unit unit, const CAmount& amount, SeparatorStyle separators, bool privacy, bool acceptNegativeAmount)
144144
{
145-
assert(amount >= 0);
145+
if (!acceptNegativeAmount) assert(amount >= 0);
146146
QString value;
147147
if (privacy) {
148148
value = format(unit, 0, false, separators, true).replace('0', '#');

src/qt/bitcoinunits.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class BitcoinUnits: public QAbstractListModel
7777
//! Format as HTML string (with unit)
7878
static QString formatHtmlWithUnit(Unit unit, const CAmount& amount, bool plussign = false, SeparatorStyle separators = SeparatorStyle::STANDARD);
7979
//! Format as string (with unit) of fixed length to preserve privacy, if it is set.
80-
static QString formatWithPrivacy(Unit unit, const CAmount& amount, SeparatorStyle separators, bool privacy);
80+
static QString formatWithPrivacy(Unit unit, const CAmount& amount, SeparatorStyle separators, bool privacy, bool acceptNegativeAmount = false);
8181
//! Parse string to coin amount
8282
static bool parse(Unit unit, const QString& value, CAmount* val_out);
8383
//! Gets title for amount column including current display unit if optionsModel reference available */

src/qt/overviewpage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent)
166166

167167
void OverviewPage::handleTransactionClicked(const QModelIndex &index)
168168
{
169-
if(filter)
169+
if(filter && !m_privacy)
170170
Q_EMIT transactionClicked(filter->mapToSource(index));
171171
}
172172

src/qt/transactiontablemodel.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,9 @@ QVariant TransactionTableModel::addressColor(const TransactionRecord *wtx) const
451451

452452
QString TransactionTableModel::formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed, BitcoinUnits::SeparatorStyle separators) const
453453
{
454-
QString str = BitcoinUnits::format(walletModel->getOptionsModel()->getDisplayUnit(), wtx->credit + wtx->debit, false, separators);
454+
const bool privacy = walletModel->getOptionsModel()->getOption(OptionsModel::MaskValues).toBool();
455+
BitcoinUnit unit = walletModel->getOptionsModel()->getDisplayUnit();
456+
QString str = BitcoinUnits::formatWithPrivacy(unit, wtx->credit + wtx->debit, separators, privacy, true);
455457
if(showUnconfirmed)
456458
{
457459
if(!wtx->status.countsForBalance)
@@ -698,11 +700,15 @@ QModelIndex TransactionTableModel::index(int row, int column, const QModelIndex
698700
return QModelIndex();
699701
}
700702

703+
void TransactionTableModel::refreshAmounts()
704+
{
705+
Q_EMIT dataChanged(index(0, Amount), index(priv->size()-1, Amount));
706+
}
707+
701708
void TransactionTableModel::updateDisplayUnit()
702709
{
703-
// emit dataChanged to update Amount column with the current unit
704710
updateAmountColumnTitle();
705-
Q_EMIT dataChanged(index(0, Amount), index(priv->size()-1, Amount));
711+
refreshAmounts(); // refresh 'Amount' column to update the current unit
706712
}
707713

708714
void TransactionTablePriv::NotifyTransactionChanged(const uint256 &hash, ChangeType status)

src/qt/transactiontablemodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public Q_SLOTS:
112112
void updateTransaction(const QString &hash, int status, bool showTransaction);
113113
void updateConfirmations();
114114
void updateDisplayUnit();
115+
// Triggers a re-paint of the 'Amount' column.
116+
void refreshAmounts();
115117
/** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
116118
void updateAmountColumnTitle();
117119
/* Needed to update fProcessingQueuedTransactions through a QueuedConnection */

src/qt/walletview.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ WalletView::WalletView(WalletModel* wallet_model, const PlatformStyle* _platform
9393
connect(transactionView, &TransactionView::message, this, &WalletView::message);
9494

9595
connect(this, &WalletView::setPrivacy, overviewPage, &OverviewPage::setPrivacy);
96+
connect(this, &WalletView::setPrivacy, walletModel->getTransactionTableModel(), &TransactionTableModel::refreshAmounts);
9697

9798
// Receive and pass through messages from wallet model
9899
connect(walletModel, &WalletModel::message, this, &WalletView::message);

0 commit comments

Comments
 (0)