3737
3838TransactionView::TransactionView (const PlatformStyle *platformStyle, QWidget *parent) :
3939 QWidget(parent), model(0 ), transactionProxyModel(0 ),
40- transactionView(0 )
40+ transactionView(0 ), abandonAction( 0 )
4141{
4242 // Build filter row
4343 setContentsMargins (0 ,0 ,0 ,0 );
@@ -137,6 +137,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
137137 transactionView = view;
138138
139139 // Actions
140+ abandonAction = new QAction (tr (" Abandon transaction" ), this );
140141 QAction *copyAddressAction = new QAction (tr (" Copy address" ), this );
141142 QAction *copyLabelAction = new QAction (tr (" Copy label" ), this );
142143 QAction *copyAmountAction = new QAction (tr (" Copy amount" ), this );
@@ -153,8 +154,10 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
153154 contextMenu->addAction (copyTxIDAction);
154155 contextMenu->addAction (copyTxHexAction);
155156 contextMenu->addAction (copyTxPlainText);
156- contextMenu->addAction (editLabelAction);
157157 contextMenu->addAction (showDetailsAction);
158+ contextMenu->addSeparator ();
159+ contextMenu->addAction (abandonAction);
160+ contextMenu->addAction (editLabelAction);
158161
159162 mapperThirdPartyTxUrls = new QSignalMapper (this );
160163
@@ -170,6 +173,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
170173 connect (view, SIGNAL (doubleClicked (QModelIndex)), this , SIGNAL (doubleClicked (QModelIndex)));
171174 connect (view, SIGNAL (customContextMenuRequested (QPoint)), this , SLOT (contextualMenu (QPoint)));
172175
176+ connect (abandonAction, SIGNAL (triggered ()), this , SLOT (abandonTx ()));
173177 connect (copyAddressAction, SIGNAL (triggered ()), this , SLOT (copyAddress ()));
174178 connect (copyLabelAction, SIGNAL (triggered ()), this , SLOT (copyLabel ()));
175179 connect (copyAmountAction, SIGNAL (triggered ()), this , SLOT (copyAmount ()));
@@ -360,12 +364,37 @@ void TransactionView::exportClicked()
360364void TransactionView::contextualMenu (const QPoint &point)
361365{
362366 QModelIndex index = transactionView->indexAt (point);
367+ QModelIndexList selection = transactionView->selectionModel ()->selectedRows (0 );
368+
369+ // check if transaction can be abandoned, disable context menu action in case it doesn't
370+ uint256 hash;
371+ hash.SetHex (selection.at (0 ).data (TransactionTableModel::TxHashRole).toString ().toStdString ());
372+ abandonAction->setEnabled (model->transactionCanBeAbandoned (hash));
373+
363374 if (index.isValid ())
364375 {
365376 contextMenu->exec (QCursor::pos ());
366377 }
367378}
368379
380+ void TransactionView::abandonTx ()
381+ {
382+ if (!transactionView || !transactionView->selectionModel ())
383+ return ;
384+ QModelIndexList selection = transactionView->selectionModel ()->selectedRows (0 );
385+
386+ // get the hash from the TxHashRole (QVariant / QString)
387+ uint256 hash;
388+ QString hashQStr = selection.at (0 ).data (TransactionTableModel::TxHashRole).toString ();
389+ hash.SetHex (hashQStr.toStdString ());
390+
391+ // Abandon the wallet transaction over the walletModel
392+ model->abandonTransaction (hash);
393+
394+ // Update the table
395+ model->getTransactionTableModel ()->updateTransaction (hashQStr, CT_UPDATED, false );
396+ }
397+
369398void TransactionView::copyAddress ()
370399{
371400 GUIUtil::copyEntryData (transactionView, 0 , TransactionTableModel::AddressRole);
0 commit comments