2020-12-31 05:48:25 -03:00
|
|
|
// Copyright (c) 2011-2020 The Bitcoin Core developers
|
2014-12-13 01:09:33 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 12:20:43 -03:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <qt/transactionview.h>
|
2011-06-28 15:41:56 -04:00
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <qt/addresstablemodel.h>
|
|
|
|
#include <qt/bitcoinunits.h>
|
|
|
|
#include <qt/csvmodelwriter.h>
|
|
|
|
#include <qt/editaddressdialog.h>
|
2020-01-11 09:35:34 -03:00
|
|
|
#include <qt/guiutil.h>
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <qt/optionsmodel.h>
|
|
|
|
#include <qt/platformstyle.h>
|
|
|
|
#include <qt/transactiondescdialog.h>
|
|
|
|
#include <qt/transactionfilterproxy.h>
|
|
|
|
#include <qt/transactionrecord.h>
|
|
|
|
#include <qt/transactiontablemodel.h>
|
|
|
|
#include <qt/walletmodel.h>
|
2013-04-13 02:13:08 -03:00
|
|
|
|
2020-06-19 18:14:17 -04:00
|
|
|
#include <node/ui_interface.h>
|
2011-06-28 15:41:56 -04:00
|
|
|
|
2018-08-01 12:43:46 -04:00
|
|
|
#include <QApplication>
|
2011-06-28 15:41:56 -04:00
|
|
|
#include <QComboBox>
|
2013-04-13 02:13:08 -03:00
|
|
|
#include <QDateTimeEdit>
|
2014-04-24 17:21:45 -03:00
|
|
|
#include <QDesktopServices>
|
2011-06-28 15:41:56 -04:00
|
|
|
#include <QDoubleValidator>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QHeaderView>
|
2011-07-22 12:30:25 -04:00
|
|
|
#include <QLabel>
|
2013-04-13 02:13:08 -03:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QScrollBar>
|
2021-01-31 12:15:57 -03:00
|
|
|
#include <QSettings>
|
2013-04-13 02:13:08 -03:00
|
|
|
#include <QTableView>
|
2017-08-06 16:55:14 -04:00
|
|
|
#include <QTimer>
|
2014-04-24 17:21:45 -03:00
|
|
|
#include <QUrl>
|
2013-04-13 02:13:08 -03:00
|
|
|
#include <QVBoxLayout>
|
2011-06-28 15:41:56 -04:00
|
|
|
|
2015-07-28 10:20:14 -03:00
|
|
|
TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *parent) :
|
2020-01-26 17:19:39 -03:00
|
|
|
QWidget(parent)
|
2011-06-28 15:41:56 -04:00
|
|
|
{
|
|
|
|
// Build filter row
|
2011-07-03 14:59:56 -04:00
|
|
|
setContentsMargins(0,0,0,0);
|
|
|
|
|
2011-06-28 15:41:56 -04:00
|
|
|
QHBoxLayout *hlayout = new QHBoxLayout();
|
2011-07-03 14:59:56 -04:00
|
|
|
hlayout->setContentsMargins(0,0,0,0);
|
2015-07-28 10:20:14 -03:00
|
|
|
|
|
|
|
if (platformStyle->getUseExtraSpacing()) {
|
|
|
|
hlayout->setSpacing(5);
|
|
|
|
hlayout->addSpacing(26);
|
|
|
|
} else {
|
|
|
|
hlayout->setSpacing(0);
|
|
|
|
hlayout->addSpacing(23);
|
|
|
|
}
|
2011-06-28 15:41:56 -04:00
|
|
|
|
2014-08-09 20:26:04 -04:00
|
|
|
watchOnlyWidget = new QComboBox(this);
|
|
|
|
watchOnlyWidget->setFixedWidth(24);
|
|
|
|
watchOnlyWidget->addItem("", TransactionFilterProxy::WatchOnlyFilter_All);
|
2015-07-28 10:20:14 -03:00
|
|
|
watchOnlyWidget->addItem(platformStyle->SingleColorIcon(":/icons/eye_plus"), "", TransactionFilterProxy::WatchOnlyFilter_Yes);
|
|
|
|
watchOnlyWidget->addItem(platformStyle->SingleColorIcon(":/icons/eye_minus"), "", TransactionFilterProxy::WatchOnlyFilter_No);
|
2014-08-09 20:26:04 -04:00
|
|
|
hlayout->addWidget(watchOnlyWidget);
|
|
|
|
|
2011-06-28 15:41:56 -04:00
|
|
|
dateWidget = new QComboBox(this);
|
2015-07-28 10:20:14 -03:00
|
|
|
if (platformStyle->getUseExtraSpacing()) {
|
|
|
|
dateWidget->setFixedWidth(121);
|
|
|
|
} else {
|
|
|
|
dateWidget->setFixedWidth(120);
|
|
|
|
}
|
2011-06-28 15:41:56 -04:00
|
|
|
dateWidget->addItem(tr("All"), All);
|
|
|
|
dateWidget->addItem(tr("Today"), Today);
|
|
|
|
dateWidget->addItem(tr("This week"), ThisWeek);
|
|
|
|
dateWidget->addItem(tr("This month"), ThisMonth);
|
2011-07-01 14:28:11 -04:00
|
|
|
dateWidget->addItem(tr("Last month"), LastMonth);
|
2011-06-28 15:41:56 -04:00
|
|
|
dateWidget->addItem(tr("This year"), ThisYear);
|
|
|
|
dateWidget->addItem(tr("Range..."), Range);
|
|
|
|
hlayout->addWidget(dateWidget);
|
|
|
|
|
|
|
|
typeWidget = new QComboBox(this);
|
2015-07-28 10:20:14 -03:00
|
|
|
if (platformStyle->getUseExtraSpacing()) {
|
|
|
|
typeWidget->setFixedWidth(121);
|
|
|
|
} else {
|
|
|
|
typeWidget->setFixedWidth(120);
|
|
|
|
}
|
2011-06-28 15:41:56 -04:00
|
|
|
|
|
|
|
typeWidget->addItem(tr("All"), TransactionFilterProxy::ALL_TYPES);
|
|
|
|
typeWidget->addItem(tr("Received with"), TransactionFilterProxy::TYPE(TransactionRecord::RecvWithAddress) |
|
2011-12-28 07:14:05 -03:00
|
|
|
TransactionFilterProxy::TYPE(TransactionRecord::RecvFromOther));
|
2011-06-28 15:41:56 -04:00
|
|
|
typeWidget->addItem(tr("Sent to"), TransactionFilterProxy::TYPE(TransactionRecord::SendToAddress) |
|
2011-12-28 07:14:05 -03:00
|
|
|
TransactionFilterProxy::TYPE(TransactionRecord::SendToOther));
|
2011-06-28 15:41:56 -04:00
|
|
|
typeWidget->addItem(tr("To yourself"), TransactionFilterProxy::TYPE(TransactionRecord::SendToSelf));
|
2011-07-07 04:43:04 -04:00
|
|
|
typeWidget->addItem(tr("Mined"), TransactionFilterProxy::TYPE(TransactionRecord::Generated));
|
2011-06-28 15:41:56 -04:00
|
|
|
typeWidget->addItem(tr("Other"), TransactionFilterProxy::TYPE(TransactionRecord::Other));
|
|
|
|
|
|
|
|
hlayout->addWidget(typeWidget);
|
|
|
|
|
2017-09-25 01:13:27 -03:00
|
|
|
search_widget = new QLineEdit(this);
|
2017-09-25 01:18:35 -03:00
|
|
|
search_widget->setPlaceholderText(tr("Enter address, transaction id, or label to search"));
|
2017-09-25 01:13:27 -03:00
|
|
|
hlayout->addWidget(search_widget);
|
2011-06-28 15:41:56 -04:00
|
|
|
|
|
|
|
amountWidget = new QLineEdit(this);
|
2011-08-28 09:12:26 -03:00
|
|
|
amountWidget->setPlaceholderText(tr("Min amount"));
|
2015-07-28 10:20:14 -03:00
|
|
|
if (platformStyle->getUseExtraSpacing()) {
|
|
|
|
amountWidget->setFixedWidth(97);
|
|
|
|
} else {
|
|
|
|
amountWidget->setFixedWidth(100);
|
|
|
|
}
|
2018-09-09 07:54:11 -03:00
|
|
|
QDoubleValidator *amountValidator = new QDoubleValidator(0, 1e20, 8, this);
|
|
|
|
QLocale amountLocale(QLocale::C);
|
|
|
|
amountLocale.setNumberOptions(QLocale::RejectGroupSeparator);
|
|
|
|
amountValidator->setLocale(amountLocale);
|
|
|
|
amountWidget->setValidator(amountValidator);
|
2011-06-28 15:41:56 -04:00
|
|
|
hlayout->addWidget(amountWidget);
|
|
|
|
|
2017-08-06 16:55:14 -04:00
|
|
|
// Delay before filtering transactions in ms
|
|
|
|
static const int input_filter_delay = 200;
|
|
|
|
|
|
|
|
QTimer* amount_typing_delay = new QTimer(this);
|
|
|
|
amount_typing_delay->setSingleShot(true);
|
|
|
|
amount_typing_delay->setInterval(input_filter_delay);
|
|
|
|
|
|
|
|
QTimer* prefix_typing_delay = new QTimer(this);
|
|
|
|
prefix_typing_delay->setSingleShot(true);
|
|
|
|
prefix_typing_delay->setInterval(input_filter_delay);
|
|
|
|
|
2011-06-28 15:41:56 -04:00
|
|
|
QVBoxLayout *vlayout = new QVBoxLayout(this);
|
2011-07-03 14:59:56 -04:00
|
|
|
vlayout->setContentsMargins(0,0,0,0);
|
|
|
|
vlayout->setSpacing(0);
|
2011-06-28 15:41:56 -04:00
|
|
|
|
2021-01-31 12:20:19 -03:00
|
|
|
transactionView = new QTableView(this);
|
|
|
|
transactionView->setObjectName("transactionView");
|
2011-06-28 15:41:56 -04:00
|
|
|
vlayout->addLayout(hlayout);
|
2011-07-22 12:30:25 -04:00
|
|
|
vlayout->addWidget(createDateRangeWidget());
|
2021-01-31 12:20:19 -03:00
|
|
|
vlayout->addWidget(transactionView);
|
2011-06-28 15:41:56 -04:00
|
|
|
vlayout->setSpacing(0);
|
2021-01-31 12:20:19 -03:00
|
|
|
int width = transactionView->verticalScrollBar()->sizeHint().width();
|
2011-06-28 15:41:56 -04:00
|
|
|
// Cover scroll bar width with spacing
|
2015-07-28 10:20:14 -03:00
|
|
|
if (platformStyle->getUseExtraSpacing()) {
|
|
|
|
hlayout->addSpacing(width+2);
|
|
|
|
} else {
|
|
|
|
hlayout->addSpacing(width);
|
|
|
|
}
|
2021-01-31 12:20:19 -03:00
|
|
|
transactionView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
|
|
|
transactionView->setTabKeyNavigation(false);
|
|
|
|
transactionView->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
transactionView->installEventFilter(this);
|
2021-01-31 12:25:01 -03:00
|
|
|
transactionView->setAlternatingRowColors(true);
|
|
|
|
transactionView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
transactionView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
|
|
transactionView->setSortingEnabled(true);
|
|
|
|
transactionView->verticalHeader()->hide();
|
|
|
|
|
2021-01-31 12:15:57 -03:00
|
|
|
QSettings settings;
|
|
|
|
if (!transactionView->horizontalHeader()->restoreState(settings.value("TransactionViewHeaderState").toByteArray())) {
|
|
|
|
transactionView->setColumnWidth(TransactionTableModel::Status, STATUS_COLUMN_WIDTH);
|
|
|
|
transactionView->setColumnWidth(TransactionTableModel::Watchonly, WATCHONLY_COLUMN_WIDTH);
|
|
|
|
transactionView->setColumnWidth(TransactionTableModel::Date, DATE_COLUMN_WIDTH);
|
|
|
|
transactionView->setColumnWidth(TransactionTableModel::Type, TYPE_COLUMN_WIDTH);
|
|
|
|
transactionView->setColumnWidth(TransactionTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH);
|
|
|
|
transactionView->horizontalHeader()->setMinimumSectionSize(MINIMUM_COLUMN_WIDTH);
|
|
|
|
transactionView->horizontalHeader()->setStretchLastSection(true);
|
|
|
|
}
|
2011-06-28 15:41:56 -04:00
|
|
|
|
2011-07-08 16:27:36 -04:00
|
|
|
// Actions
|
2016-03-17 13:54:54 -03:00
|
|
|
abandonAction = new QAction(tr("Abandon transaction"), this);
|
2017-02-03 18:04:39 -03:00
|
|
|
bumpFeeAction = new QAction(tr("Increase transaction fee"), this);
|
2017-03-09 19:56:23 -03:00
|
|
|
bumpFeeAction->setObjectName("bumpFeeAction");
|
2020-01-26 17:19:39 -03:00
|
|
|
copyAddressAction = new QAction(tr("Copy address"), this);
|
|
|
|
copyLabelAction = new QAction(tr("Copy label"), this);
|
2011-12-04 10:14:10 -03:00
|
|
|
QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
|
2013-03-21 06:33:36 -03:00
|
|
|
QAction *copyTxIDAction = new QAction(tr("Copy transaction ID"), this);
|
2015-11-17 07:17:09 -03:00
|
|
|
QAction *copyTxHexAction = new QAction(tr("Copy raw transaction"), this);
|
2016-03-01 16:16:32 -03:00
|
|
|
QAction *copyTxPlainText = new QAction(tr("Copy full transaction details"), this);
|
2021-02-24 04:54:43 -03:00
|
|
|
QAction *editLabelAction = new QAction(tr("Edit address label"), this);
|
2012-05-06 10:24:15 -04:00
|
|
|
QAction *showDetailsAction = new QAction(tr("Show transaction details"), this);
|
2011-07-08 16:27:36 -04:00
|
|
|
|
2016-11-18 11:47:20 -03:00
|
|
|
contextMenu = new QMenu(this);
|
2017-03-09 19:56:23 -03:00
|
|
|
contextMenu->setObjectName("contextMenu");
|
2011-07-08 16:27:36 -04:00
|
|
|
contextMenu->addAction(copyAddressAction);
|
|
|
|
contextMenu->addAction(copyLabelAction);
|
2011-12-04 10:14:10 -03:00
|
|
|
contextMenu->addAction(copyAmountAction);
|
2013-03-21 06:33:36 -03:00
|
|
|
contextMenu->addAction(copyTxIDAction);
|
2015-11-17 07:17:09 -03:00
|
|
|
contextMenu->addAction(copyTxHexAction);
|
2016-03-01 16:16:32 -03:00
|
|
|
contextMenu->addAction(copyTxPlainText);
|
2011-07-08 16:27:36 -04:00
|
|
|
contextMenu->addAction(showDetailsAction);
|
2016-03-17 13:54:54 -03:00
|
|
|
contextMenu->addSeparator();
|
2017-02-03 18:04:39 -03:00
|
|
|
contextMenu->addAction(bumpFeeAction);
|
2016-03-17 13:54:54 -03:00
|
|
|
contextMenu->addAction(abandonAction);
|
2021-02-24 04:35:55 -03:00
|
|
|
contextMenu->addAction(editLabelAction);
|
2011-07-08 16:27:36 -04:00
|
|
|
|
2018-06-24 11:18:22 -04:00
|
|
|
connect(dateWidget, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &TransactionView::chooseDate);
|
|
|
|
connect(typeWidget, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &TransactionView::chooseType);
|
|
|
|
connect(watchOnlyWidget, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &TransactionView::chooseWatchonly);
|
|
|
|
connect(amountWidget, &QLineEdit::textChanged, amount_typing_delay, static_cast<void (QTimer::*)()>(&QTimer::start));
|
|
|
|
connect(amount_typing_delay, &QTimer::timeout, this, &TransactionView::changedAmount);
|
|
|
|
connect(search_widget, &QLineEdit::textChanged, prefix_typing_delay, static_cast<void (QTimer::*)()>(&QTimer::start));
|
|
|
|
connect(prefix_typing_delay, &QTimer::timeout, this, &TransactionView::changedSearch);
|
|
|
|
|
2021-01-31 12:20:19 -03:00
|
|
|
connect(transactionView, &QTableView::doubleClicked, this, &TransactionView::doubleClicked);
|
|
|
|
connect(transactionView, &QTableView::customContextMenuRequested, this, &TransactionView::contextualMenu);
|
2018-06-24 11:18:22 -04:00
|
|
|
|
|
|
|
connect(bumpFeeAction, &QAction::triggered, this, &TransactionView::bumpFee);
|
|
|
|
connect(abandonAction, &QAction::triggered, this, &TransactionView::abandonTx);
|
|
|
|
connect(copyAddressAction, &QAction::triggered, this, &TransactionView::copyAddress);
|
|
|
|
connect(copyLabelAction, &QAction::triggered, this, &TransactionView::copyLabel);
|
|
|
|
connect(copyAmountAction, &QAction::triggered, this, &TransactionView::copyAmount);
|
|
|
|
connect(copyTxIDAction, &QAction::triggered, this, &TransactionView::copyTxID);
|
|
|
|
connect(copyTxHexAction, &QAction::triggered, this, &TransactionView::copyTxHex);
|
|
|
|
connect(copyTxPlainText, &QAction::triggered, this, &TransactionView::copyTxPlainText);
|
2021-02-24 04:35:55 -03:00
|
|
|
connect(editLabelAction, &QAction::triggered, this, &TransactionView::editLabel);
|
2018-06-24 11:18:22 -04:00
|
|
|
connect(showDetailsAction, &QAction::triggered, this, &TransactionView::showDetails);
|
|
|
|
// Double-clicking on a transaction on the transaction history page shows details
|
|
|
|
connect(this, &TransactionView::doubleClicked, this, &TransactionView::showDetails);
|
2018-08-01 12:43:46 -04:00
|
|
|
// Highlight transaction after fee bump
|
|
|
|
connect(this, &TransactionView::bumpedFee, [this](const uint256& txid) {
|
|
|
|
focusTransaction(txid);
|
|
|
|
});
|
2011-06-28 15:41:56 -04:00
|
|
|
}
|
|
|
|
|
2021-01-31 12:15:57 -03:00
|
|
|
TransactionView::~TransactionView()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
settings.setValue("TransactionViewHeaderState", transactionView->horizontalHeader()->saveState());
|
|
|
|
}
|
|
|
|
|
2016-09-09 08:43:29 -03:00
|
|
|
void TransactionView::setModel(WalletModel *_model)
|
2011-06-28 15:41:56 -04:00
|
|
|
{
|
2016-09-09 08:43:29 -03:00
|
|
|
this->model = _model;
|
|
|
|
if(_model)
|
2011-11-08 17:18:36 -03:00
|
|
|
{
|
|
|
|
transactionProxyModel = new TransactionFilterProxy(this);
|
2016-09-09 08:43:29 -03:00
|
|
|
transactionProxyModel->setSourceModel(_model->getTransactionTableModel());
|
2011-11-08 17:18:36 -03:00
|
|
|
transactionProxyModel->setDynamicSortFilter(true);
|
2012-07-17 05:38:18 -04:00
|
|
|
transactionProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
transactionProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
2011-11-08 17:18:36 -03:00
|
|
|
transactionProxyModel->setSortRole(Qt::EditRole);
|
|
|
|
transactionView->setModel(transactionProxyModel);
|
2021-02-27 12:41:51 -03:00
|
|
|
transactionView->sortByColumn(TransactionTableModel::Date, Qt::DescendingOrder);
|
2014-04-24 17:21:45 -03:00
|
|
|
|
2016-09-09 08:43:29 -03:00
|
|
|
if (_model->getOptionsModel())
|
2014-04-24 17:21:45 -03:00
|
|
|
{
|
|
|
|
// Add third party transaction URLs to context menu
|
2020-08-09 12:53:25 -04:00
|
|
|
QStringList listUrls = GUIUtil::SplitSkipEmptyParts(_model->getOptionsModel()->getThirdPartyTxUrls(), "|");
|
2014-04-24 17:21:45 -03:00
|
|
|
for (int i = 0; i < listUrls.size(); ++i)
|
|
|
|
{
|
2019-08-24 03:22:47 -04:00
|
|
|
QString url = listUrls[i].trimmed();
|
|
|
|
QString host = QUrl(url, QUrl::StrictMode).host();
|
2014-04-24 17:21:45 -03:00
|
|
|
if (!host.isEmpty())
|
|
|
|
{
|
|
|
|
QAction *thirdPartyTxUrlAction = new QAction(host, this); // use host as menu item label
|
|
|
|
if (i == 0)
|
|
|
|
contextMenu->addSeparator();
|
|
|
|
contextMenu->addAction(thirdPartyTxUrlAction);
|
2019-08-24 03:22:47 -04:00
|
|
|
connect(thirdPartyTxUrlAction, &QAction::triggered, [this, url] { openThirdPartyTxUrl(url); });
|
2014-04-24 17:21:45 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-09 20:26:04 -04:00
|
|
|
|
|
|
|
// show/hide column Watch-only
|
2017-04-17 19:56:44 -03:00
|
|
|
updateWatchOnlyColumn(_model->wallet().haveWatchOnly());
|
2014-08-09 20:26:04 -04:00
|
|
|
|
|
|
|
// Watch-only signal
|
2018-06-24 11:18:22 -04:00
|
|
|
connect(_model, &WalletModel::notifyWatchonlyChanged, this, &TransactionView::updateWatchOnlyColumn);
|
2011-11-08 17:18:36 -03:00
|
|
|
}
|
2011-06-28 15:41:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransactionView::chooseDate(int idx)
|
|
|
|
{
|
2018-03-01 06:40:36 -03:00
|
|
|
if (!transactionProxyModel) return;
|
2011-06-28 15:41:56 -04:00
|
|
|
QDate current = QDate::currentDate();
|
2011-07-22 12:30:25 -04:00
|
|
|
dateRangeWidget->setVisible(false);
|
2011-06-28 15:41:56 -04:00
|
|
|
switch(dateWidget->itemData(idx).toInt())
|
|
|
|
{
|
|
|
|
case All:
|
|
|
|
transactionProxyModel->setDateRange(
|
|
|
|
TransactionFilterProxy::MIN_DATE,
|
|
|
|
TransactionFilterProxy::MAX_DATE);
|
|
|
|
break;
|
|
|
|
case Today:
|
|
|
|
transactionProxyModel->setDateRange(
|
2020-08-09 09:25:22 -04:00
|
|
|
GUIUtil::StartOfDay(current),
|
2011-06-28 15:41:56 -04:00
|
|
|
TransactionFilterProxy::MAX_DATE);
|
|
|
|
break;
|
|
|
|
case ThisWeek: {
|
2012-07-25 20:48:39 -04:00
|
|
|
// Find last Monday
|
2011-06-28 15:41:56 -04:00
|
|
|
QDate startOfWeek = current.addDays(-(current.dayOfWeek()-1));
|
|
|
|
transactionProxyModel->setDateRange(
|
2020-08-09 09:25:22 -04:00
|
|
|
GUIUtil::StartOfDay(startOfWeek),
|
2011-06-28 15:41:56 -04:00
|
|
|
TransactionFilterProxy::MAX_DATE);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case ThisMonth:
|
|
|
|
transactionProxyModel->setDateRange(
|
2020-08-09 09:25:22 -04:00
|
|
|
GUIUtil::StartOfDay(QDate(current.year(), current.month(), 1)),
|
2011-06-28 15:41:56 -04:00
|
|
|
TransactionFilterProxy::MAX_DATE);
|
|
|
|
break;
|
2011-07-01 14:28:11 -04:00
|
|
|
case LastMonth:
|
|
|
|
transactionProxyModel->setDateRange(
|
2020-08-09 09:25:22 -04:00
|
|
|
GUIUtil::StartOfDay(QDate(current.year(), current.month(), 1).addMonths(-1)),
|
|
|
|
GUIUtil::StartOfDay(QDate(current.year(), current.month(), 1)));
|
2011-07-01 14:28:11 -04:00
|
|
|
break;
|
2011-06-28 15:41:56 -04:00
|
|
|
case ThisYear:
|
|
|
|
transactionProxyModel->setDateRange(
|
2020-08-09 09:25:22 -04:00
|
|
|
GUIUtil::StartOfDay(QDate(current.year(), 1, 1)),
|
2011-06-28 15:41:56 -04:00
|
|
|
TransactionFilterProxy::MAX_DATE);
|
|
|
|
break;
|
|
|
|
case Range:
|
2011-07-22 12:30:25 -04:00
|
|
|
dateRangeWidget->setVisible(true);
|
|
|
|
dateRangeChanged();
|
2011-06-28 15:41:56 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransactionView::chooseType(int idx)
|
|
|
|
{
|
2011-11-08 17:18:36 -03:00
|
|
|
if(!transactionProxyModel)
|
|
|
|
return;
|
2011-06-28 15:41:56 -04:00
|
|
|
transactionProxyModel->setTypeFilter(
|
|
|
|
typeWidget->itemData(idx).toInt());
|
|
|
|
}
|
|
|
|
|
2014-08-09 20:26:04 -04:00
|
|
|
void TransactionView::chooseWatchonly(int idx)
|
|
|
|
{
|
|
|
|
if(!transactionProxyModel)
|
|
|
|
return;
|
|
|
|
transactionProxyModel->setWatchOnlyFilter(
|
2017-06-01 10:13:35 -04:00
|
|
|
static_cast<TransactionFilterProxy::WatchOnlyFilter>(watchOnlyWidget->itemData(idx).toInt()));
|
2014-08-09 20:26:04 -04:00
|
|
|
}
|
|
|
|
|
2017-09-25 01:13:27 -03:00
|
|
|
void TransactionView::changedSearch()
|
2011-06-28 15:41:56 -04:00
|
|
|
{
|
2011-11-08 17:18:36 -03:00
|
|
|
if(!transactionProxyModel)
|
|
|
|
return;
|
2017-09-25 01:13:27 -03:00
|
|
|
transactionProxyModel->setSearchString(search_widget->text());
|
2011-06-28 15:41:56 -04:00
|
|
|
}
|
|
|
|
|
2017-08-06 16:55:14 -04:00
|
|
|
void TransactionView::changedAmount()
|
2011-06-28 15:41:56 -04:00
|
|
|
{
|
2011-11-08 17:18:36 -03:00
|
|
|
if(!transactionProxyModel)
|
|
|
|
return;
|
2014-04-22 19:46:19 -03:00
|
|
|
CAmount amount_parsed = 0;
|
2017-08-06 16:55:14 -04:00
|
|
|
if (BitcoinUnits::parse(model->getOptionsModel()->getDisplayUnit(), amountWidget->text(), &amount_parsed)) {
|
2011-06-28 15:41:56 -04:00
|
|
|
transactionProxyModel->setMinAmount(amount_parsed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
transactionProxyModel->setMinAmount(0);
|
|
|
|
}
|
|
|
|
}
|
2011-07-07 08:27:16 -04:00
|
|
|
|
|
|
|
void TransactionView::exportClicked()
|
|
|
|
{
|
2017-06-26 16:02:51 -04:00
|
|
|
if (!model || !model->getOptionsModel()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-07 08:27:16 -04:00
|
|
|
// CSV is currently the only supported format
|
2013-10-26 14:21:10 -03:00
|
|
|
QString filename = GUIUtil::getSaveFileName(this,
|
|
|
|
tr("Export Transaction History"), QString(),
|
2021-02-23 12:17:24 -03:00
|
|
|
tr("Comma separated file", "Name of CSV file format") + QLatin1String(" (*.csv)"), nullptr);
|
2011-07-07 08:27:16 -04:00
|
|
|
|
2013-10-26 14:21:10 -03:00
|
|
|
if (filename.isNull())
|
|
|
|
return;
|
2011-07-14 20:11:11 -04:00
|
|
|
|
2011-07-07 08:27:16 -04:00
|
|
|
CSVModelWriter writer(filename);
|
|
|
|
|
|
|
|
// name, column, role
|
|
|
|
writer.setModel(transactionProxyModel);
|
2011-08-28 09:12:26 -03:00
|
|
|
writer.addColumn(tr("Confirmed"), 0, TransactionTableModel::ConfirmedRole);
|
2017-04-17 19:56:44 -03:00
|
|
|
if (model->wallet().haveWatchOnly())
|
2014-08-28 17:20:46 -04:00
|
|
|
writer.addColumn(tr("Watch-only"), TransactionTableModel::Watchonly);
|
2011-08-28 09:12:26 -03:00
|
|
|
writer.addColumn(tr("Date"), 0, TransactionTableModel::DateRole);
|
|
|
|
writer.addColumn(tr("Type"), TransactionTableModel::Type, Qt::EditRole);
|
|
|
|
writer.addColumn(tr("Label"), 0, TransactionTableModel::LabelRole);
|
|
|
|
writer.addColumn(tr("Address"), 0, TransactionTableModel::AddressRole);
|
2014-06-07 02:20:22 -04:00
|
|
|
writer.addColumn(BitcoinUnits::getAmountColumnTitle(model->getOptionsModel()->getDisplayUnit()), 0, TransactionTableModel::FormattedAmountRole);
|
2018-03-06 17:22:50 -03:00
|
|
|
writer.addColumn(tr("ID"), 0, TransactionTableModel::TxHashRole);
|
2011-07-07 08:27:16 -04:00
|
|
|
|
2013-10-26 14:21:10 -03:00
|
|
|
if(!writer.write()) {
|
2015-07-14 08:59:05 -03:00
|
|
|
Q_EMIT message(tr("Exporting Failed"), tr("There was an error trying to save the transaction history to %1.").arg(filename),
|
2013-10-26 14:21:10 -03:00
|
|
|
CClientUIInterface::MSG_ERROR);
|
|
|
|
}
|
|
|
|
else {
|
2015-07-14 08:59:05 -03:00
|
|
|
Q_EMIT message(tr("Exporting Successful"), tr("The transaction history was successfully saved to %1.").arg(filename),
|
2013-10-26 14:21:10 -03:00
|
|
|
CClientUIInterface::MSG_INFORMATION);
|
2011-07-07 08:27:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-08 16:27:36 -04:00
|
|
|
void TransactionView::contextualMenu(const QPoint &point)
|
|
|
|
{
|
|
|
|
QModelIndex index = transactionView->indexAt(point);
|
2016-03-17 13:54:54 -03:00
|
|
|
QModelIndexList selection = transactionView->selectionModel()->selectedRows(0);
|
2016-06-24 06:05:45 -04:00
|
|
|
if (selection.empty())
|
|
|
|
return;
|
2016-03-17 13:54:54 -03:00
|
|
|
|
|
|
|
// check if transaction can be abandoned, disable context menu action in case it doesn't
|
|
|
|
uint256 hash;
|
|
|
|
hash.SetHex(selection.at(0).data(TransactionTableModel::TxHashRole).toString().toStdString());
|
2017-04-17 19:56:44 -03:00
|
|
|
abandonAction->setEnabled(model->wallet().transactionCanBeAbandoned(hash));
|
|
|
|
bumpFeeAction->setEnabled(model->wallet().transactionCanBeBumped(hash));
|
2020-01-26 17:19:39 -03:00
|
|
|
copyAddressAction->setEnabled(GUIUtil::hasEntryData(transactionView, 0, TransactionTableModel::AddressRole));
|
|
|
|
copyLabelAction->setEnabled(GUIUtil::hasEntryData(transactionView, 0, TransactionTableModel::LabelRole));
|
2016-03-17 13:54:54 -03:00
|
|
|
|
2020-01-11 09:35:34 -03:00
|
|
|
if (index.isValid()) {
|
|
|
|
GUIUtil::PopupMenu(contextMenu, transactionView->viewport()->mapToGlobal(point));
|
2011-07-08 16:27:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-17 13:54:54 -03:00
|
|
|
void TransactionView::abandonTx()
|
|
|
|
{
|
|
|
|
if(!transactionView || !transactionView->selectionModel())
|
|
|
|
return;
|
|
|
|
QModelIndexList selection = transactionView->selectionModel()->selectedRows(0);
|
|
|
|
|
|
|
|
// get the hash from the TxHashRole (QVariant / QString)
|
|
|
|
uint256 hash;
|
|
|
|
QString hashQStr = selection.at(0).data(TransactionTableModel::TxHashRole).toString();
|
|
|
|
hash.SetHex(hashQStr.toStdString());
|
|
|
|
|
|
|
|
// Abandon the wallet transaction over the walletModel
|
2017-04-17 19:56:44 -03:00
|
|
|
model->wallet().abandonTransaction(hash);
|
2016-03-17 13:54:54 -03:00
|
|
|
|
|
|
|
// Update the table
|
|
|
|
model->getTransactionTableModel()->updateTransaction(hashQStr, CT_UPDATED, false);
|
|
|
|
}
|
|
|
|
|
2017-02-03 18:04:39 -03:00
|
|
|
void TransactionView::bumpFee()
|
|
|
|
{
|
|
|
|
if(!transactionView || !transactionView->selectionModel())
|
|
|
|
return;
|
|
|
|
QModelIndexList selection = transactionView->selectionModel()->selectedRows(0);
|
|
|
|
|
|
|
|
// get the hash from the TxHashRole (QVariant / QString)
|
|
|
|
uint256 hash;
|
|
|
|
QString hashQStr = selection.at(0).data(TransactionTableModel::TxHashRole).toString();
|
|
|
|
hash.SetHex(hashQStr.toStdString());
|
|
|
|
|
|
|
|
// Bump tx fee over the walletModel
|
2018-08-01 12:43:46 -04:00
|
|
|
uint256 newHash;
|
|
|
|
if (model->bumpFee(hash, newHash)) {
|
2017-05-11 04:33:40 -03:00
|
|
|
// Update the table
|
2018-08-01 12:43:46 -04:00
|
|
|
transactionView->selectionModel()->clearSelection();
|
2017-03-09 19:56:23 -03:00
|
|
|
model->getTransactionTableModel()->updateTransaction(hashQStr, CT_UPDATED, true);
|
2018-08-01 12:43:46 -04:00
|
|
|
|
|
|
|
qApp->processEvents();
|
|
|
|
Q_EMIT bumpedFee(newHash);
|
2017-05-11 04:33:40 -03:00
|
|
|
}
|
2017-02-03 18:04:39 -03:00
|
|
|
}
|
|
|
|
|
2011-07-08 16:27:36 -04:00
|
|
|
void TransactionView::copyAddress()
|
|
|
|
{
|
2011-12-04 10:14:10 -03:00
|
|
|
GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::AddressRole);
|
2011-07-08 16:27:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransactionView::copyLabel()
|
|
|
|
{
|
2011-12-04 10:14:10 -03:00
|
|
|
GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::LabelRole);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransactionView::copyAmount()
|
|
|
|
{
|
|
|
|
GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::FormattedAmountRole);
|
2011-07-08 16:27:36 -04:00
|
|
|
}
|
|
|
|
|
2013-03-21 06:33:36 -03:00
|
|
|
void TransactionView::copyTxID()
|
|
|
|
{
|
2018-03-06 17:22:50 -03:00
|
|
|
GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::TxHashRole);
|
2013-03-21 06:33:36 -03:00
|
|
|
}
|
|
|
|
|
2015-11-17 07:17:09 -03:00
|
|
|
void TransactionView::copyTxHex()
|
|
|
|
{
|
|
|
|
GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::TxHexRole);
|
|
|
|
}
|
|
|
|
|
2016-03-01 16:16:32 -03:00
|
|
|
void TransactionView::copyTxPlainText()
|
|
|
|
{
|
|
|
|
GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::TxPlainTextRole);
|
|
|
|
}
|
|
|
|
|
2021-02-24 04:35:55 -03:00
|
|
|
void TransactionView::editLabel()
|
|
|
|
{
|
|
|
|
if(!transactionView->selectionModel() ||!model)
|
|
|
|
return;
|
|
|
|
QModelIndexList selection = transactionView->selectionModel()->selectedRows();
|
|
|
|
if(!selection.isEmpty())
|
|
|
|
{
|
|
|
|
AddressTableModel *addressBook = model->getAddressTableModel();
|
|
|
|
if(!addressBook)
|
|
|
|
return;
|
|
|
|
QString address = selection.at(0).data(TransactionTableModel::AddressRole).toString();
|
|
|
|
if(address.isEmpty())
|
|
|
|
{
|
|
|
|
// If this transaction has no associated address, exit
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Is address in address book? Address book can miss address when a transaction is
|
|
|
|
// sent from outside the UI.
|
|
|
|
int idx = addressBook->lookupAddress(address);
|
|
|
|
if(idx != -1)
|
|
|
|
{
|
|
|
|
// Edit sending / receiving address
|
|
|
|
QModelIndex modelIdx = addressBook->index(idx, 0, QModelIndex());
|
|
|
|
// Determine type of address, launch appropriate editor dialog type
|
|
|
|
QString type = modelIdx.data(AddressTableModel::TypeRole).toString();
|
|
|
|
|
|
|
|
EditAddressDialog dlg(
|
|
|
|
type == AddressTableModel::Receive
|
|
|
|
? EditAddressDialog::EditReceivingAddress
|
|
|
|
: EditAddressDialog::EditSendingAddress, this);
|
|
|
|
dlg.setModel(addressBook);
|
|
|
|
dlg.loadRow(idx);
|
|
|
|
dlg.exec();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Add sending address
|
|
|
|
EditAddressDialog dlg(EditAddressDialog::NewSendingAddress,
|
|
|
|
this);
|
|
|
|
dlg.setModel(addressBook);
|
|
|
|
dlg.setAddress(address);
|
|
|
|
dlg.exec();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-08 16:27:36 -04:00
|
|
|
void TransactionView::showDetails()
|
|
|
|
{
|
2011-11-08 17:18:36 -03:00
|
|
|
if(!transactionView->selectionModel())
|
|
|
|
return;
|
2011-07-08 16:27:36 -04:00
|
|
|
QModelIndexList selection = transactionView->selectionModel()->selectedRows();
|
|
|
|
if(!selection.isEmpty())
|
|
|
|
{
|
2016-04-25 11:01:28 -03:00
|
|
|
TransactionDescDialog *dlg = new TransactionDescDialog(selection.at(0));
|
|
|
|
dlg->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
dlg->show();
|
2011-07-08 16:27:36 -04:00
|
|
|
}
|
|
|
|
}
|
2011-07-22 12:30:25 -04:00
|
|
|
|
2014-04-24 17:21:45 -03:00
|
|
|
void TransactionView::openThirdPartyTxUrl(QString url)
|
|
|
|
{
|
|
|
|
if(!transactionView || !transactionView->selectionModel())
|
|
|
|
return;
|
|
|
|
QModelIndexList selection = transactionView->selectionModel()->selectedRows(0);
|
|
|
|
if(!selection.isEmpty())
|
|
|
|
QDesktopServices::openUrl(QUrl::fromUserInput(url.replace("%s", selection.at(0).data(TransactionTableModel::TxHashRole).toString())));
|
|
|
|
}
|
|
|
|
|
2011-07-22 12:30:25 -04:00
|
|
|
QWidget *TransactionView::createDateRangeWidget()
|
|
|
|
{
|
|
|
|
dateRangeWidget = new QFrame();
|
|
|
|
dateRangeWidget->setFrameStyle(QFrame::Panel | QFrame::Raised);
|
|
|
|
dateRangeWidget->setContentsMargins(1,1,1,1);
|
|
|
|
QHBoxLayout *layout = new QHBoxLayout(dateRangeWidget);
|
|
|
|
layout->setContentsMargins(0,0,0,0);
|
|
|
|
layout->addSpacing(23);
|
2011-08-28 09:12:26 -03:00
|
|
|
layout->addWidget(new QLabel(tr("Range:")));
|
2011-07-22 12:30:25 -04:00
|
|
|
|
|
|
|
dateFrom = new QDateTimeEdit(this);
|
|
|
|
dateFrom->setDisplayFormat("dd/MM/yy");
|
|
|
|
dateFrom->setCalendarPopup(true);
|
|
|
|
dateFrom->setMinimumWidth(100);
|
|
|
|
dateFrom->setDate(QDate::currentDate().addDays(-7));
|
|
|
|
layout->addWidget(dateFrom);
|
2011-08-28 09:12:26 -03:00
|
|
|
layout->addWidget(new QLabel(tr("to")));
|
2011-07-22 12:30:25 -04:00
|
|
|
|
|
|
|
dateTo = new QDateTimeEdit(this);
|
|
|
|
dateTo->setDisplayFormat("dd/MM/yy");
|
|
|
|
dateTo->setCalendarPopup(true);
|
|
|
|
dateTo->setMinimumWidth(100);
|
|
|
|
dateTo->setDate(QDate::currentDate());
|
|
|
|
layout->addWidget(dateTo);
|
|
|
|
layout->addStretch();
|
|
|
|
|
|
|
|
// Hide by default
|
|
|
|
dateRangeWidget->setVisible(false);
|
|
|
|
|
|
|
|
// Notify on change
|
2018-06-24 11:18:22 -04:00
|
|
|
connect(dateFrom, &QDateTimeEdit::dateChanged, this, &TransactionView::dateRangeChanged);
|
|
|
|
connect(dateTo, &QDateTimeEdit::dateChanged, this, &TransactionView::dateRangeChanged);
|
2011-07-22 12:30:25 -04:00
|
|
|
|
|
|
|
return dateRangeWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransactionView::dateRangeChanged()
|
|
|
|
{
|
2011-11-08 17:18:36 -03:00
|
|
|
if(!transactionProxyModel)
|
|
|
|
return;
|
2011-07-22 12:30:25 -04:00
|
|
|
transactionProxyModel->setDateRange(
|
2020-08-09 09:25:22 -04:00
|
|
|
GUIUtil::StartOfDay(dateFrom->date()),
|
|
|
|
GUIUtil::StartOfDay(dateTo->date()).addDays(1));
|
2011-07-22 12:30:25 -04:00
|
|
|
}
|
2012-05-12 07:19:44 -04:00
|
|
|
|
|
|
|
void TransactionView::focusTransaction(const QModelIndex &idx)
|
|
|
|
{
|
|
|
|
if(!transactionProxyModel)
|
|
|
|
return;
|
|
|
|
QModelIndex targetIdx = transactionProxyModel->mapFromSource(idx);
|
|
|
|
transactionView->scrollTo(targetIdx);
|
|
|
|
transactionView->setCurrentIndex(targetIdx);
|
|
|
|
transactionView->setFocus();
|
|
|
|
}
|
2014-03-21 02:45:47 -03:00
|
|
|
|
2018-03-01 06:40:36 -03:00
|
|
|
void TransactionView::focusTransaction(const uint256& txid)
|
|
|
|
{
|
|
|
|
if (!transactionProxyModel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const QModelIndexList results = this->model->getTransactionTableModel()->match(
|
|
|
|
this->model->getTransactionTableModel()->index(0,0),
|
|
|
|
TransactionTableModel::TxHashRole,
|
|
|
|
QString::fromStdString(txid.ToString()), -1);
|
|
|
|
|
|
|
|
transactionView->setFocus();
|
|
|
|
transactionView->selectionModel()->clearSelection();
|
|
|
|
for (const QModelIndex& index : results) {
|
|
|
|
const QModelIndex targetIndex = transactionProxyModel->mapFromSource(index);
|
|
|
|
transactionView->selectionModel()->select(
|
|
|
|
targetIndex,
|
|
|
|
QItemSelectionModel::Rows | QItemSelectionModel::Select);
|
|
|
|
// Called once per destination to ensure all results are in view, unless
|
|
|
|
// transactions are not ordered by (ascending or descending) date.
|
|
|
|
transactionView->scrollTo(targetIndex);
|
|
|
|
// scrollTo() does not scroll far enough the first time when transactions
|
|
|
|
// are ordered by ascending date.
|
|
|
|
if (index == results[0]) transactionView->scrollTo(targetIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 18:50:09 -04:00
|
|
|
// Need to override default Ctrl+C action for amount as default behaviour is just to copy DisplayRole text
|
|
|
|
bool TransactionView::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::KeyPress)
|
|
|
|
{
|
|
|
|
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
|
|
|
|
if (ke->key() == Qt::Key_C && ke->modifiers().testFlag(Qt::ControlModifier))
|
|
|
|
{
|
2016-03-01 16:16:32 -03:00
|
|
|
GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::TxPlainTextRole);
|
|
|
|
return true;
|
2014-05-09 18:50:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return QWidget::eventFilter(obj, event);
|
|
|
|
}
|
2014-08-09 20:26:04 -04:00
|
|
|
|
|
|
|
// show/hide column Watch-only
|
|
|
|
void TransactionView::updateWatchOnlyColumn(bool fHaveWatchOnly)
|
|
|
|
{
|
|
|
|
watchOnlyWidget->setVisible(fHaveWatchOnly);
|
|
|
|
transactionView->setColumnHidden(TransactionTableModel::Watchonly, !fHaveWatchOnly);
|
|
|
|
}
|