forked from ciphrex/mSIGNA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccounthistorydialog.cpp
195 lines (166 loc) · 5.59 KB
/
accounthistorydialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
///////////////////////////////////////////////////////////////////////////////
//
// mSIGNA
//
// accounthistorydialog.cpp
//
// Copyright (c) 2013 Eric Lombrozo
//
// All Rights Reserved.
#include "settings.h"
#include "accounthistorydialog.h"
// Models/Views
#include "txmodel.h"
#include "txview.h"
// Subdialogs
#include "rawtxdialog.h"
#include <QAction>
#include <QMenu>
#include <QVBoxLayout>
#include <QMessageBox>
#include <QUrl>
#include <QDesktopServices>
#include <CoinDB/Vault.h>
#include <CoinQ/CoinQ_netsync.h>
AccountHistoryDialog::AccountHistoryDialog(CoinDB::Vault* vault, const QString& accountName, CoinQ::Network::NetworkSync* networkSync, QWidget* parent)
: QDialog(parent), currentRow(-1)
{
resize(QSize(800, 400));
createActions();
createMenus();
accountHistoryModel = new TxModel(vault, accountName, this);
accountHistoryModel->update();
accountHistoryView = new TxView(this);
accountHistoryView->setModel(accountHistoryModel);
accountHistoryView->setMenu(menu);
accountHistoryView->update();
txSelectionModel = accountHistoryView->selectionModel();
connect(txSelectionModel, &QItemSelectionModel::currentChanged,
this, &AccountHistoryDialog::updateCurrentTx);
/*
connect(txSelectionModel, &QItemSelectionModel::selectionChanged,
this, &AccountHistoryDialog::updateSelectedTxs);
*/
QVBoxLayout* mainLayout = new QVBoxLayout();
mainLayout->addWidget(accountHistoryView);
setLayout(mainLayout);
setWindowTitle(getDefaultSettings().getAppName() + " - " + accountName + tr(" account history"));
this->networkSync = networkSync;
}
void AccountHistoryDialog::updateCurrentTx(const QModelIndex& current, const QModelIndex& /*previous*/)
{
currentRow = current.row();
if (currentRow != -1) {
QStandardItem* typeItem = accountHistoryModel->item(currentRow, 6);
int type = typeItem->data(Qt::UserRole).toInt();
if (type == CoinDB::Tx::UNSIGNED) {
signTxAction->setEnabled(true);
}
else {
signTxAction->setEnabled(false);
}
if (networkSync && networkSync->connected() && type == CoinDB::Tx::UNSENT) {
sendTxAction->setEnabled(true);
}
else {
sendTxAction->setEnabled(false);
}
if (type == CoinDB::Tx::PROPAGATED) {
viewTxOnWebAction->setEnabled(true);
}
else {
viewTxOnWebAction->setEnabled(false);
}
viewRawTxAction->setEnabled(true);
deleteTxAction->setEnabled(true);
return;
}
signTxAction->setEnabled(false);
viewRawTxAction->setEnabled(false);
viewTxOnWebAction->setEnabled(false);
deleteTxAction->setEnabled(false);
}
void AccountHistoryDialog::signTx()
{
try {
accountHistoryModel->signTx(currentRow);
accountHistoryView->update();
}
catch (const std::exception& e) {
QMessageBox::critical(this, tr("Error"), e.what());
}
}
void AccountHistoryDialog::sendTx()
{
try {
throw std::runtime_error("Unsupported operation.");
//accountHistoryModel->sendTx(currentRow, networkSync);
//accountHistoryView->update();
}
catch (const std::exception& e) {
QMessageBox::critical(this, tr("Error"), e.what());
}
}
void AccountHistoryDialog::viewRawTx()
{
try {
std::shared_ptr<CoinDB::Tx> tx = accountHistoryModel->getTx(currentRow);
RawTxDialog rawTxDlg(tr("Raw Transaction"));
rawTxDlg.setRawTx(tx->raw());
rawTxDlg.exec();
}
catch (const std::exception& e) {
QMessageBox::critical(this, tr("Error"), e.what());
}
}
void AccountHistoryDialog::viewTxOnWeb()
{
const QString URL_PREFIX("https://blockchain.info/tx/");
try {
std::shared_ptr<CoinDB::Tx> tx = accountHistoryModel->getTx(currentRow);
if (!QDesktopServices::openUrl(QUrl(URL_PREFIX + QString::fromStdString(uchar_vector(tx->hash()).getHex())))) {
throw std::runtime_error(tr("Unable to open browser.").toStdString());
}
}
catch (const std::exception& e) {
QMessageBox::critical(this, tr("Error"), e.what());
}
}
void AccountHistoryDialog::deleteTx()
{
try {
accountHistoryModel->deleteTx(currentRow);
accountHistoryView->update();
emit txDeleted();
}
catch (const std::exception& e) {
QMessageBox::critical(this, tr("Error"), e.what());
}
}
void AccountHistoryDialog::createActions()
{
signTxAction = new QAction(tr("Sign Transaction"), this);
signTxAction->setEnabled(false);
connect(signTxAction, SIGNAL(triggered()), this, SLOT(signTx()));
sendTxAction = new QAction(tr("Send Transaction"), this);
sendTxAction->setEnabled(false);
connect(sendTxAction, SIGNAL(triggered()), this, SLOT(sendTx()));
viewRawTxAction = new QAction(tr("View Raw Transaction"), this);
viewRawTxAction->setEnabled(false);
connect(viewRawTxAction, SIGNAL(triggered()), this, SLOT(viewRawTx()));
viewTxOnWebAction = new QAction(tr("View At Blockchain.info"), this);
viewTxOnWebAction->setEnabled(false);
connect(viewTxOnWebAction, SIGNAL(triggered()), this, SLOT(viewTxOnWeb()));
deleteTxAction = new QAction(tr("Delete Transaction"), this);
deleteTxAction->setEnabled(false);
connect(deleteTxAction, SIGNAL(triggered()), this, SLOT(deleteTx()));
}
void AccountHistoryDialog::createMenus()
{
menu = new QMenu();
menu->addAction(signTxAction);
menu->addAction(sendTxAction);
menu->addAction(viewRawTxAction);
menu->addAction(viewTxOnWebAction);
menu->addAction(deleteTxAction);
}