PRCYCoin  2.0.0.7rc1
P2P Digital Currency
revealtxdialog.cpp
Go to the documentation of this file.
1 #include "revealtxdialog.h"
2 #include "ui_revealtxdialog.h"
3 #include "bitcoinunits.h"
4 #include "chainparams.h"
5 #include "guiutil.h"
6 #include "wallet/wallet.h"
7 
8 #include <QClipboard>
9 #include <QDesktopServices>
10 #include <QKeyEvent>
11 #include <QPushButton>
12 #include <QUrl>
13 
15  QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint),
16  ui(new Ui::RevealTxDialog)
17 {
18  ui->setupUi(this);
19 
20  ui->pushButtonCopyID->setStyleSheet("background:transparent;");
21  ui->pushButtonCopyID->setIcon(QIcon(":/icons/editcopy"));
22  connect(ui->pushButtonCopyID, SIGNAL(clicked()), this, SLOT(copyID()));
23 
24  ui->pushButtonCopyAddr->setStyleSheet("background:transparent;");
25  ui->pushButtonCopyAddr->setIcon(QIcon(":/icons/editcopy"));
26  connect(ui->pushButtonCopyAddr, SIGNAL(clicked()), this, SLOT(copyAddress()));
27 
28  ui->pushButtonCopyPrivKey->setStyleSheet("background:transparent;");
29  ui->pushButtonCopyPrivKey->setIcon(QIcon(":/icons/editcopy"));
30  connect(ui->pushButtonCopyPrivKey, SIGNAL(clicked()), this, SLOT(copyPrivateKey()));
31 
32  ui->pushButtonCopyTxAmount->setStyleSheet("background:transparent;");
33  ui->pushButtonCopyTxAmount->setIcon(QIcon(":/icons/editcopy"));
34  connect(ui->pushButtonCopyTxAmount, SIGNAL(clicked()), this, SLOT(copyTxAmount()));
35 
36  ui->pushButtonCopyTxFee->setStyleSheet("background:transparent;");
37  ui->pushButtonCopyTxFee->setIcon(QIcon(":/icons/editcopy"));
38  connect(ui->pushButtonCopyTxFee, SIGNAL(clicked()), this, SLOT(copyTxFee()));
39 
40  ui->pushButtonCopyTxPaymentID->setStyleSheet("background:transparent;");
41  ui->pushButtonCopyTxPaymentID->setIcon(QIcon(":/icons/editcopy"));
42  connect(ui->pushButtonCopyTxPaymentID, SIGNAL(clicked()), this, SLOT(copyTxPaymentID()));
43 
44  ui->pushButtonCopyTxRingSize->setStyleSheet("background:transparent;");
45  ui->pushButtonCopyTxRingSize->setIcon(QIcon(":/icons/editcopy"));
46  connect(ui->pushButtonCopyTxRingSize, SIGNAL(clicked()), this, SLOT(copyTxRingSize()));
47 
48  ui->pushButtonOpenTXID->setStyleSheet("background:transparent;");
49  ui->pushButtonOpenTXID->setIcon(QIcon(":/icons/eye"));
50  connect(ui->pushButtonOpenTXID, SIGNAL(clicked()), this, SLOT(openTXinExplorer()));
51 
52  ui->buttonBox->button(QDialogButtonBox::Reset)->setText("Delete Transaction?");
53  connect(ui->buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()), this, SLOT(deleteTransaction()));
54 }
55 
57 {
58  delete ui;
59 }
60 
61 void RevealTxDialog::setTxID(QString strId)
62 {
63  ui->lblTxID->setText(strId);
64 }
65 
66 void RevealTxDialog::setTxAddress(QString strAddr)
67 {
68  ui->lblAddress->setText(strAddr);
69 }
70 
71 void RevealTxDialog::setTxPrivKey(QString strPrivKey)
72 {
73  ui->lblPrivateKey->setText(strPrivKey);
74 }
75 
76 void RevealTxDialog::setTxAmount(QString amount)
77 {
78  int nDisplayUnit;
79  ui->lblTxAmount->setText(amount.append(" PRCY"));
80 }
81 
83 {
84  int nDisplayUnit;
85  ui->lblTxFee->setText(BitcoinUnits::formatHtmlWithUnit(0, fee, false, BitcoinUnits::separatorAlways));
86 }
87 
88 void RevealTxDialog::setTxPaymentID(uint64_t paymentID)
89 {
90  if (paymentID == 0) {
91  ui->pushButtonCopyTxPaymentID->hide();
92  ui->label_7->hide();
93  ui->lblTxPaymentID->hide();
94  }
95  ui->lblTxPaymentID->setText(QString::number(paymentID));
96 }
97 
98 void RevealTxDialog::setTxRingSize(int64_t ringSize)
99 {
100  ui->lblTxRingSize->setText(QString::number(ringSize));
101 }
102 
104 {
105  //We currently don't do anything on accept
106 }
107 
109  QClipboard *clipboard = QApplication::clipboard();
110  clipboard->setText(ui->lblTxID->text());
111 }
112 
114  QClipboard *clipboard = QApplication::clipboard();
115  clipboard->setText(ui->lblAddress->text());
116 }
117 
119  QClipboard *clipboard = QApplication::clipboard();
120  clipboard->setText(ui->lblPrivateKey->text());
121 }
122 
124  QClipboard *clipboard = QApplication::clipboard();
125  clipboard->setText(ui->lblTxAmount->text());
126 }
127 
129  QClipboard *clipboard = QApplication::clipboard();
130  clipboard->setText(ui->lblTxFee->text());
131 }
132 
134  QClipboard *clipboard = QApplication::clipboard();
135  clipboard->setText(ui->lblTxPaymentID->text());
136 }
137 
139  QClipboard *clipboard = QApplication::clipboard();
140  clipboard->setText(ui->lblTxRingSize->text());
141 }
142 
144 {
145  QString URL;
146  // Adjust link depending on Network
147  if (Params().NetworkID() == CBaseChainParams::MAIN) {
148  URL = "https://explorer.prcycoin.com/tx/";
149  } else if (Params().NetworkID() == CBaseChainParams::TESTNET){
150  URL = "https://testnet.prcycoin.com/tx/";
151  }
152  QDesktopServices::openUrl(QUrl(URL.append(ui->lblTxID->text())));
153 }
154 
156 {
157  bool hideSuccess = settings.value("fHideDeleteSuccess", false).toBool();
158 
159  QMessageBox::StandardButton reply;
160  reply = QMessageBox::question(this, tr("Are You Sure?"),
161  tr("Are you sure you would like to delete this transaction from the local wallet?\n\nNote: They can only be restored from backup or rescan."),
162  QMessageBox::Yes|QMessageBox::No);
163  if (reply == QMessageBox::Yes) {
164  // If it might be a Masternode collateral by value, double check
165  if (ui->lblTxAmount->text() == "5000.00000000 PRCY") {
166  QMessageBox::StandardButton doubleCheck;
167  doubleCheck = QMessageBox::question(this, tr("Potential Masternode Collateral Detected!"),
168  tr("Potential Masternode Collateral Detected!\nAre you sure?\n\nNote: They can only be restored from backup or rescan."),
169  QMessageBox::Yes|QMessageBox::No);
170  if (doubleCheck == QMessageBox::No) {
171  return;
172  }
173  }
174 
175  // Get the hash from the TXID
176  uint256 hash;
177  hash.SetHex(ui->lblTxID->text().toStdString().c_str());
178 
179  // Check it exists
180  if (!pwalletMain->mapWallet.count(hash)) {
181  QMessageBox msgBox;
182  msgBox.setWindowTitle(tr("Invalid or non-wallet transaction id"));
183  msgBox.setIcon(QMessageBox::Critical);
184  msgBox.setText(tr("Invalid or non-wallet transaction id."));
185  msgBox.setStyleSheet(GUIUtil::loadStyleSheet());
186  msgBox.exec();
187  return;
188  }
189  // Erase it
190  if (!pwalletMain->EraseFromWallet(hash)) {
191  QMessageBox msgBox;
192  msgBox.setWindowTitle(tr("Unable to delete transaction id"));
193  msgBox.setIcon(QMessageBox::Critical);
194  msgBox.setText(tr("Unable to delete transaction id."));
195  msgBox.setStyleSheet(GUIUtil::loadStyleSheet());
196  msgBox.exec();
197  return;
198  }
199 
200  // Display Success! dialog if not disabled
201  QMessageBox msgBox;
202  QCheckBox *cb = new QCheckBox(tr("Do not show successful confirmation again"));
203  QPushButton *okButton = msgBox.addButton(tr("OK"), QMessageBox::ActionRole);
204  msgBox.setCheckBox(cb);
205 
206  if (!hideSuccess) {
207  msgBox.setWindowTitle(tr("Success!"));
208  msgBox.setIcon(QMessageBox::Information);
209  msgBox.setText(tr("Transaction ID successfully deleted."));
210  msgBox.setStyleSheet(GUIUtil::loadStyleSheet());
211  msgBox.exec();
212  if (msgBox.clickedButton() == okButton) {
213  if (cb->isChecked()) {
214  settings.setValue("fHideDeleteSuccess", true);
215  } else {
216  settings.setValue("fHideDeleteSuccess", false);
217  }
218  }
219  }
220  accept();
221  } else {
222  return;
223  }
224 }
225 
226 void RevealTxDialog::keyPressEvent(QKeyEvent* event)
227 {
228  if (event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete) { // press backspace/delete -> delete transaction
229  event->ignore();
231  } else if (event->key() == Qt::Key_Escape) { // press escape -> reject
232  event->ignore();
233  reject();
234  } else if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { // press enter/return -> accept
235  event->ignore();
236  accept();
237  }
238 }
RevealTxDialog::openTXinExplorer
void openTXinExplorer()
Definition: revealtxdialog.cpp:143
CWallet::mapWallet
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:344
RevealTxDialog::copyTxAmount
void copyTxAmount()
Definition: revealtxdialog.cpp:123
RevealTxDialog::settings
QSettings settings
Definition: revealtxdialog.h:44
RevealTxDialog::setTxFee
void setTxFee(CAmount fee)
Definition: revealtxdialog.cpp:82
RevealTxDialog::setTxPrivKey
void setTxPrivKey(QString strPrivKey)
Definition: revealtxdialog.cpp:71
wallet.h
chainparams.h
RevealTxDialog::copyTxRingSize
void copyTxRingSize()
Definition: revealtxdialog.cpp:138
RevealTxDialog::setTxRingSize
void setTxRingSize(int64_t ringSize)
Definition: revealtxdialog.cpp:98
RevealTxDialog::setTxAmount
void setTxAmount(QString amount)
Definition: revealtxdialog.cpp:76
RevealTxDialog::copyPrivateKey
void copyPrivateKey()
Definition: revealtxdialog.cpp:118
RevealTxDialog
Definition: revealtxdialog.h:14
RevealTxDialog::copyTxPaymentID
void copyTxPaymentID()
Definition: revealtxdialog.cpp:133
RevealTxDialog::keyPressEvent
void keyPressEvent(QKeyEvent *event)
Definition: revealtxdialog.cpp:226
CBaseChainParams::MAIN
@ MAIN
Definition: chainparamsbase.h:19
CAmount
int64_t CAmount
Amount in PRCY (Can be negative)
Definition: amount.h:17
RevealTxDialog::copyAddress
void copyAddress()
Definition: revealtxdialog.cpp:113
RevealTxDialog::setTxAddress
void setTxAddress(QString strAddr)
Definition: revealtxdialog.cpp:66
guiutil.h
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
base_uint::SetHex
void SetHex(const char *psz)
Definition: arith_uint256.cpp:164
RevealTxDialog::setTxID
void setTxID(QString strId)
Definition: revealtxdialog.cpp:61
CBaseChainParams::TESTNET
@ TESTNET
Definition: chainparamsbase.h:20
RevealTxDialog::ui
Ui::RevealTxDialog * ui
Definition: revealtxdialog.h:43
RevealTxDialog::~RevealTxDialog
~RevealTxDialog()
Definition: revealtxdialog.cpp:56
RevealTxDialog::deleteTransaction
void deleteTransaction()
Definition: revealtxdialog.cpp:155
RevealTxDialog::RevealTxDialog
RevealTxDialog(QWidget *parent=0)
Definition: revealtxdialog.cpp:14
Ui
Definition: 2faconfirmdialog.h:7
RevealTxDialog::on_buttonBox_accepted
void on_buttonBox_accepted()
Definition: revealtxdialog.cpp:103
BitcoinUnits::separatorAlways
@ separatorAlways
Definition: bitcoinunits.h:69
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:463
bitcoinunits.h
BitcoinUnits::formatHtmlWithUnit
static QString formatHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Definition: bitcoinunits.cpp:195
GUIUtil::loadStyleSheet
QString loadStyleSheet()
Load global CSS theme.
Definition: guiutil.cpp:721
CWallet::EraseFromWallet
bool EraseFromWallet(const uint256 &hash)
Definition: wallet.cpp:1320
pwalletMain
CWallet * pwalletMain
Definition: wallet.cpp:49
RevealTxDialog::setTxPaymentID
void setTxPaymentID(uint64_t paymentID)
Definition: revealtxdialog.cpp:88
revealtxdialog.h
RevealTxDialog::copyID
void copyID()
Definition: revealtxdialog.cpp:108
RevealTxDialog::copyTxFee
void copyTxFee()
Definition: revealtxdialog.cpp:128