Skip to content

Commit be263fa

Browse files
committed
Merge #12421: [qt] navigate to transaction history page after send
e7d9fc5 [qt] navigate to transaction history page after send (Sjors Provoost) Pull request description: Before this change QT just remained on the Send tab, which I found confusing. Now it switches to the Transactions tab. This makes it more clear to the user that the send actually succeeded, and here they can monitor progress. Ideally I would like to highlight the transaction, e.g. by refactoring `TransactionView::focusTransaction(const QModelIndex &idx)` to accept a transaction hash, but I'm not sure how to do that. Tree-SHA512: 8aa93e03874de8434e18951f8aec47377814c0bcaf7eda4766fc41d5a4e32806346e12e4139e4d45468dfdf0b786f5a7faa393a31b8cd6c65ccac21fb3782c33
2 parents 32987d5 + e7d9fc5 commit be263fa

File tree

6 files changed

+42
-3
lines changed

6 files changed

+42
-3
lines changed

src/qt/bitcoin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <init.h>
3030
#include <rpc/server.h>
3131
#include <ui_interface.h>
32+
#include <uint256.h>
3233
#include <util.h>
3334
#include <warnings.h>
3435

@@ -80,6 +81,7 @@ Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
8081
// Declare meta types used for QMetaObject::invokeMethod
8182
Q_DECLARE_METATYPE(bool*)
8283
Q_DECLARE_METATYPE(CAmount)
84+
Q_DECLARE_METATYPE(uint256)
8385

8486
static void InitMessage(const std::string &message)
8587
{

src/qt/sendcoinsdialog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ void SendCoinsDialog::on_sendButton_clicked()
369369
accept();
370370
CoinControlDialog::coinControl()->UnSelectAll();
371371
coinControlUpdateLabels();
372+
Q_EMIT coinsSent(currentTransaction.getTransaction()->GetHash());
372373
}
373374
fNewRecipientAllowed = true;
374375
}

src/qt/sendcoinsdialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public Q_SLOTS:
5454
void setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance,
5555
const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance);
5656

57+
Q_SIGNALS:
58+
void coinsSent(const uint256& txid);
59+
5760
private:
5861
Ui::SendCoinsDialog *ui;
5962
ClientModel *clientModel;

src/qt/transactionview.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ void TransactionView::setModel(WalletModel *_model)
263263

264264
void TransactionView::chooseDate(int idx)
265265
{
266-
if(!transactionProxyModel)
267-
return;
266+
if (!transactionProxyModel) return;
268267
QDate current = QDate::currentDate();
269268
dateRangeWidget->setVisible(false);
270269
switch(dateWidget->itemData(idx).toInt())
@@ -592,6 +591,32 @@ void TransactionView::focusTransaction(const QModelIndex &idx)
592591
transactionView->setFocus();
593592
}
594593

594+
void TransactionView::focusTransaction(const uint256& txid)
595+
{
596+
if (!transactionProxyModel)
597+
return;
598+
599+
const QModelIndexList results = this->model->getTransactionTableModel()->match(
600+
this->model->getTransactionTableModel()->index(0,0),
601+
TransactionTableModel::TxHashRole,
602+
QString::fromStdString(txid.ToString()), -1);
603+
604+
transactionView->setFocus();
605+
transactionView->selectionModel()->clearSelection();
606+
for (const QModelIndex& index : results) {
607+
const QModelIndex targetIndex = transactionProxyModel->mapFromSource(index);
608+
transactionView->selectionModel()->select(
609+
targetIndex,
610+
QItemSelectionModel::Rows | QItemSelectionModel::Select);
611+
// Called once per destination to ensure all results are in view, unless
612+
// transactions are not ordered by (ascending or descending) date.
613+
transactionView->scrollTo(targetIndex);
614+
// scrollTo() does not scroll far enough the first time when transactions
615+
// are ordered by ascending date.
616+
if (index == results[0]) transactionView->scrollTo(targetIndex);
617+
}
618+
}
619+
595620
// We override the virtual resizeEvent of the QWidget to adjust tables column
596621
// sizes as the tables width is proportional to the dialogs width.
597622
void TransactionView::resizeEvent(QResizeEvent* event)

src/qt/transactionview.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include <qt/guiutil.h>
99

10+
#include <uint256.h>
11+
1012
#include <QWidget>
1113
#include <QKeyEvent>
1214

@@ -116,7 +118,7 @@ public Q_SLOTS:
116118
void changedSearch();
117119
void exportClicked();
118120
void focusTransaction(const QModelIndex&);
119-
121+
void focusTransaction(const uint256& txid);
120122
};
121123

122124
#endif // BITCOIN_QT_TRANSACTIONVIEW_H

src/qt/walletview.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent):
6868
connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex)));
6969
connect(overviewPage, SIGNAL(outOfSyncWarningClicked()), this, SLOT(requestedSyncWarningInfo()));
7070

71+
// Highlight transaction after send
72+
connect(sendCoinsPage, SIGNAL(coinsSent(uint256)), transactionView, SLOT(focusTransaction(uint256)));
73+
7174
// Double-clicking on a transaction on the transaction history page shows details
7275
connect(transactionView, SIGNAL(doubleClicked(QModelIndex)), transactionView, SLOT(showDetails()));
7376

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

97+
// Navigate to transaction history page after send
98+
connect(sendCoinsPage, SIGNAL(coinsSent(uint256)), gui, SLOT(gotoHistoryPage()));
99+
94100
// Receive and report messages
95101
connect(this, SIGNAL(message(QString,QString,unsigned int)), gui, SLOT(message(QString,QString,unsigned int)));
96102

0 commit comments

Comments
 (0)