Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[qt] navigate to transaction history page after send #12421

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/qt/bitcoin.cpp
Expand Up @@ -29,6 +29,7 @@
#include <init.h>
#include <rpc/server.h>
#include <ui_interface.h>
#include <uint256.h>
#include <util.h>
#include <warnings.h>

Expand Down Expand Up @@ -80,6 +81,7 @@ Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
// Declare meta types used for QMetaObject::invokeMethod
Q_DECLARE_METATYPE(bool*)
Q_DECLARE_METATYPE(CAmount)
Q_DECLARE_METATYPE(uint256)

static void InitMessage(const std::string &message)
{
Expand Down
1 change: 1 addition & 0 deletions src/qt/sendcoinsdialog.cpp
Expand Up @@ -369,6 +369,7 @@ void SendCoinsDialog::on_sendButton_clicked()
accept();
CoinControlDialog::coinControl()->UnSelectAll();
coinControlUpdateLabels();
Q_EMIT coinsSent(currentTransaction.getTransaction()->GetHash());
}
fNewRecipientAllowed = true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/qt/sendcoinsdialog.h
Expand Up @@ -54,6 +54,9 @@ public Q_SLOTS:
void setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance,
const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance);

Q_SIGNALS:
void coinsSent(const uint256& txid);

private:
Ui::SendCoinsDialog *ui;
ClientModel *clientModel;
Expand Down
29 changes: 27 additions & 2 deletions src/qt/transactionview.cpp
Expand Up @@ -263,8 +263,7 @@ void TransactionView::setModel(WalletModel *_model)

void TransactionView::chooseDate(int idx)
{
if(!transactionProxyModel)
return;
if (!transactionProxyModel) return;
QDate current = QDate::currentDate();
dateRangeWidget->setVisible(false);
switch(dateWidget->itemData(idx).toInt())
Expand Down Expand Up @@ -592,6 +591,32 @@ void TransactionView::focusTransaction(const QModelIndex &idx)
transactionView->setFocus();
}

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could ensure first row is visible:

for (...) {
    if (index == results[0]) transactionView->scrollTo(index);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That worked (using transactionProxyModel->mapFromSource) when transactions are ordered by date. Unfortunately when they're ordered in reverse it doesn't scroll all the way to the bottom. Maybe we need to wait a little bit for transactionView to become aware of its new size?

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);
}
}

// We override the virtual resizeEvent of the QWidget to adjust tables column
// sizes as the tables width is proportional to the dialogs width.
void TransactionView::resizeEvent(QResizeEvent* event)
Expand Down
4 changes: 3 additions & 1 deletion src/qt/transactionview.h
Expand Up @@ -7,6 +7,8 @@

#include <qt/guiutil.h>

#include <uint256.h>

#include <QWidget>
#include <QKeyEvent>

Expand Down Expand Up @@ -116,7 +118,7 @@ public Q_SLOTS:
void changedSearch();
void exportClicked();
void focusTransaction(const QModelIndex&);

void focusTransaction(const uint256& txid);
};

#endif // BITCOIN_QT_TRANSACTIONVIEW_H
6 changes: 6 additions & 0 deletions src/qt/walletview.cpp
Expand Up @@ -68,6 +68,9 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent):
connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
connect(overviewPage, SIGNAL(outOfSyncWarningClicked()), this, SLOT(requestedSyncWarningInfo()));

// Highlight transaction after send
connect(sendCoinsPage, SIGNAL(coinsSent(uint256)), transactionView, SLOT(focusTransaction(uint256)));

// Double-clicking on a transaction on the transaction history page shows details
connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));

Expand All @@ -91,6 +94,9 @@ void WalletView::setBitcoinGUI(BitcoinGUI *gui)
// Clicking on a transaction on the overview page simply sends you to transaction history page
connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), gui, SLOT(gotoHistoryPage()));

// Navigate to transaction history page after send
connect(sendCoinsPage, SIGNAL(coinsSent(uint256)), gui, SLOT(gotoHistoryPage()));

// Receive and report messages
connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));

Expand Down