Skip to content

Commit

Permalink
qt: mask values on transactions view
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomartin4btc committed Feb 28, 2023
1 parent 4f841cb commit d41037b
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 8 deletions.
11 changes: 10 additions & 1 deletion src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ void BitcoinGUI::createActions()
m_wallet_controller->closeAllWallets(this);
});
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::setPrivacy);
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::enableHistoryAction);
}
#endif // ENABLE_WALLET

Expand Down Expand Up @@ -668,6 +669,12 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
}

#ifdef ENABLE_WALLET
void BitcoinGUI::enableHistoryAction(bool privacy)
{
historyAction->setEnabled(!privacy);
if (historyAction->isChecked()) gotoOverviewPage();
}

void BitcoinGUI::setWalletController(WalletController* wallet_controller)
{
assert(!m_wallet_controller);
Expand Down Expand Up @@ -716,7 +723,9 @@ void BitcoinGUI::addWallet(WalletModel* walletModel)
connect(wallet_view, &WalletView::encryptionStatusChanged, this, &BitcoinGUI::updateWalletStatus);
connect(wallet_view, &WalletView::incomingTransaction, this, &BitcoinGUI::incomingTransaction);
connect(this, &BitcoinGUI::setPrivacy, wallet_view, &WalletView::setPrivacy);
wallet_view->setPrivacy(isPrivacyModeActivated());
const bool privacy = isPrivacyModeActivated();
wallet_view->setPrivacy(privacy);
enableHistoryAction(privacy);
const QString display_name = walletModel->getDisplayName();
m_wallet_selector->addItem(display_name, QVariant::fromValue(walletModel));
}
Expand Down
2 changes: 2 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ public Q_SLOTS:
void gotoVerifyMessageTab(QString addr = "");
/** Load Partially Signed Bitcoin Transaction from file or clipboard */
void gotoLoadPSBT(bool from_clipboard = false);
/** Enable history action when privacy is changed */
void enableHistoryAction(bool privacy);

/** Show open dialog */
void openClicked();
Expand Down
4 changes: 2 additions & 2 deletions src/qt/bitcoinunits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ QString BitcoinUnits::formatHtmlWithUnit(Unit unit, const CAmount& amount, bool
return QString("<span style='white-space: nowrap;'>%1</span>").arg(str);
}

QString BitcoinUnits::formatWithPrivacy(Unit unit, const CAmount& amount, SeparatorStyle separators, bool privacy)
QString BitcoinUnits::formatWithPrivacy(Unit unit, const CAmount& amount, SeparatorStyle separators, bool privacy, bool acceptNegativeAmount)
{
assert(amount >= 0);
if (!acceptNegativeAmount) assert(amount >= 0);
QString value;
if (privacy) {
value = format(unit, 0, false, separators, true).replace('0', '#');
Expand Down
2 changes: 1 addition & 1 deletion src/qt/bitcoinunits.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class BitcoinUnits: public QAbstractListModel
//! Format as HTML string (with unit)
static QString formatHtmlWithUnit(Unit unit, const CAmount& amount, bool plussign = false, SeparatorStyle separators = SeparatorStyle::STANDARD);
//! Format as string (with unit) of fixed length to preserve privacy, if it is set.
static QString formatWithPrivacy(Unit unit, const CAmount& amount, SeparatorStyle separators, bool privacy);
static QString formatWithPrivacy(Unit unit, const CAmount& amount, SeparatorStyle separators, bool privacy, bool acceptNegativeAmount = false);
//! Parse string to coin amount
static bool parse(Unit unit, const QString& value, CAmount* val_out);
//! Gets title for amount column including current display unit if optionsModel reference available */
Expand Down
2 changes: 1 addition & 1 deletion src/qt/overviewpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent)

void OverviewPage::handleTransactionClicked(const QModelIndex &index)
{
if(filter)
if(filter && !m_privacy)
Q_EMIT transactionClicked(filter->mapToSource(index));
}

Expand Down
12 changes: 9 additions & 3 deletions src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ QVariant TransactionTableModel::addressColor(const TransactionRecord *wtx) const

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

void TransactionTableModel::refreshAmounts()
{
Q_EMIT dataChanged(index(0, Amount), index(priv->size()-1, Amount));
}

void TransactionTableModel::updateDisplayUnit()
{
// emit dataChanged to update Amount column with the current unit
updateAmountColumnTitle();
Q_EMIT dataChanged(index(0, Amount), index(priv->size()-1, Amount));
refreshAmounts(); // refresh 'Amount' column to update the current unit
}

void TransactionTablePriv::NotifyTransactionChanged(const uint256 &hash, ChangeType status)
Expand Down
2 changes: 2 additions & 0 deletions src/qt/transactiontablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public Q_SLOTS:
void updateTransaction(const QString &hash, int status, bool showTransaction);
void updateConfirmations();
void updateDisplayUnit();
// Triggers a re-paint of the 'Amount' column.
void refreshAmounts();
/** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
void updateAmountColumnTitle();
/* Needed to update fProcessingQueuedTransactions through a QueuedConnection */
Expand Down
1 change: 1 addition & 0 deletions src/qt/walletview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ WalletView::WalletView(WalletModel* wallet_model, const PlatformStyle* _platform
connect(transactionView, &TransactionView::message, this, &WalletView::message);

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

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

0 comments on commit d41037b

Please sign in to comment.