Dash Core  0.12.2.1
P2P Digital Currency
overviewpage.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2015 The Bitcoin Core developers
2 // Copyright (c) 2014-2017 The Dash Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "overviewpage.h"
7 #include "ui_overviewpage.h"
8 
9 #include "bitcoinunits.h"
10 #include "clientmodel.h"
11 #include "guiconstants.h"
12 #include "guiutil.h"
13 #include "init.h"
14 #include "optionsmodel.h"
15 #include "platformstyle.h"
16 #include "transactionfilterproxy.h"
17 #include "transactiontablemodel.h"
18 #include "utilitydialog.h"
19 #include "walletmodel.h"
20 
21 #include "instantx.h"
22 #include "darksendconfig.h"
23 #include "masternode-sync.h"
24 #include "privatesend-client.h"
25 
26 #include <QAbstractItemDelegate>
27 #include <QPainter>
28 #include <QSettings>
29 #include <QTimer>
30 
31 #define ICON_OFFSET 16
32 #define DECORATION_SIZE 54
33 #define NUM_ITEMS 5
34 #define NUM_ITEMS_ADV 7
35 
36 class TxViewDelegate : public QAbstractItemDelegate
37 {
38  Q_OBJECT
39 public:
40  TxViewDelegate(const PlatformStyle *_platformStyle, QObject *parent=nullptr):
41  QAbstractItemDelegate(parent), unit(BitcoinUnits::DASH),
42  platformStyle(_platformStyle)
43  {
44 
45  }
46 
47  inline void paint(QPainter *painter, const QStyleOptionViewItem &option,
48  const QModelIndex &index ) const
49  {
50  painter->save();
51 
52  QIcon icon = qvariant_cast<QIcon>(index.data(TransactionTableModel::RawDecorationRole));
53  QRect mainRect = option.rect;
54  mainRect.moveLeft(ICON_OFFSET);
55  QRect decorationRect(mainRect.topLeft(), QSize(DECORATION_SIZE, DECORATION_SIZE));
56  int xspace = DECORATION_SIZE + 8;
57  int ypad = 6;
58  int halfheight = (mainRect.height() - 2*ypad)/2;
59  QRect amountRect(mainRect.left() + xspace, mainRect.top()+ypad, mainRect.width() - xspace - ICON_OFFSET, halfheight);
60  QRect addressRect(mainRect.left() + xspace, mainRect.top()+ypad+halfheight, mainRect.width() - xspace, halfheight);
61  icon = platformStyle->SingleColorIcon(icon);
62  icon.paint(painter, decorationRect);
63 
64  QDateTime date = index.data(TransactionTableModel::DateRole).toDateTime();
65  QString address = index.data(Qt::DisplayRole).toString();
66  qint64 amount = index.data(TransactionTableModel::AmountRole).toLongLong();
67  bool confirmed = index.data(TransactionTableModel::ConfirmedRole).toBool();
68  QVariant value = index.data(Qt::ForegroundRole);
69  QColor foreground = option.palette.color(QPalette::Text);
70  if(value.canConvert<QBrush>())
71  {
72  QBrush brush = qvariant_cast<QBrush>(value);
73  foreground = brush.color();
74  }
75 
76  painter->setPen(foreground);
77  QRect boundingRect;
78  painter->drawText(addressRect, Qt::AlignLeft|Qt::AlignVCenter, address, &boundingRect);
79 
80  if (index.data(TransactionTableModel::WatchonlyRole).toBool())
81  {
82  QIcon iconWatchonly = qvariant_cast<QIcon>(index.data(TransactionTableModel::WatchonlyDecorationRole));
83  QRect watchonlyRect(boundingRect.right() + 5, mainRect.top()+ypad+halfheight, 16, halfheight);
84  iconWatchonly.paint(painter, watchonlyRect);
85  }
86 
87  if(amount < 0)
88  {
89  foreground = COLOR_NEGATIVE;
90  }
91  else if(!confirmed)
92  {
93  foreground = COLOR_UNCONFIRMED;
94  }
95  else
96  {
97  foreground = option.palette.color(QPalette::Text);
98  }
99  painter->setPen(foreground);
100  QString amountText = BitcoinUnits::floorWithUnit(unit, amount, true, BitcoinUnits::separatorAlways);
101  if(!confirmed)
102  {
103  amountText = QString("[") + amountText + QString("]");
104  }
105  painter->drawText(amountRect, Qt::AlignRight|Qt::AlignVCenter, amountText);
106 
107  painter->setPen(option.palette.color(QPalette::Text));
108  painter->drawText(amountRect, Qt::AlignLeft|Qt::AlignVCenter, GUIUtil::dateTimeStr(date));
109 
110  painter->restore();
111  }
112 
113  inline QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
114  {
115  return QSize(DECORATION_SIZE, DECORATION_SIZE);
116  }
117 
118  int unit;
120 
121 };
122 #include "overviewpage.moc"
123 
124 OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) :
125  QWidget(parent),
126  ui(new Ui::OverviewPage),
127  clientModel(0),
128  walletModel(0),
129  currentBalance(-1),
130  currentUnconfirmedBalance(-1),
131  currentImmatureBalance(-1),
132  currentWatchOnlyBalance(-1),
133  currentWatchUnconfBalance(-1),
134  currentWatchImmatureBalance(-1),
135  txdelegate(new TxViewDelegate(platformStyle, this))
136 {
137  ui->setupUi(this);
138  QString theme = GUIUtil::getThemeName();
139 
140  // Recent transactions
141  ui->listTransactions->setItemDelegate(txdelegate);
142  ui->listTransactions->setIconSize(QSize(DECORATION_SIZE, DECORATION_SIZE));
143  // Note: minimum height of listTransactions will be set later in updateAdvancedPSUI() to reflect actual settings
144  ui->listTransactions->setAttribute(Qt::WA_MacShowFocusRect, false);
145 
146  connect(ui->listTransactions, SIGNAL(clicked(QModelIndex)), this, SLOT(handleTransactionClicked(QModelIndex)));
147 
148  // init "out of sync" warning labels
149  ui->labelWalletStatus->setText("(" + tr("out of sync") + ")");
150  ui->labelPrivateSendSyncStatus->setText("(" + tr("out of sync") + ")");
151  ui->labelTransactionsStatus->setText("(" + tr("out of sync") + ")");
152 
153  // hide PS frame (helps to preserve saved size)
154  // we'll setup and make it visible in updateAdvancedPSUI() later if we are not in litemode
155  ui->framePrivateSend->setVisible(false);
156 
157  // start with displaying the "out of sync" warnings
158  showOutOfSyncWarning(true);
159 
160  // that's it for litemode
161  if(fLiteMode) return;
162 
163  // Disable any PS UI for masternode or when autobackup is disabled or failed for whatever reason
164  if(fMasterNode || nWalletBackups <= 0){
166  if (nWalletBackups <= 0) {
167  ui->labelPrivateSendEnabled->setToolTip(tr("Automatic backups are disabled, no mixing available!"));
168  }
169  } else {
171  ui->togglePrivateSend->setText(tr("Start Mixing"));
172  } else {
173  ui->togglePrivateSend->setText(tr("Stop Mixing"));
174  }
175  // Disable privateSendClient builtin support for automatic backups while we are in GUI,
176  // we'll handle automatic backups and user warnings in privateSendStatus()
178 
179  timer = new QTimer(this);
180  connect(timer, SIGNAL(timeout()), this, SLOT(privateSendStatus()));
181  timer->start(1000);
182  }
183 }
184 
185 void OverviewPage::handleTransactionClicked(const QModelIndex &index)
186 {
187  if(filter)
188  Q_EMIT transactionClicked(filter->mapToSource(index));
189 }
190 
192 {
193  Q_EMIT outOfSyncWarningClicked();
194 }
195 
197 {
198  if(!fLiteMode && !fMasterNode) disconnect(timer, SIGNAL(timeout()), this, SLOT(privateSendStatus()));
199  delete ui;
200 }
201 
202 void OverviewPage::setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance, const CAmount& anonymizedBalance, const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance)
203 {
204  currentBalance = balance;
205  currentUnconfirmedBalance = unconfirmedBalance;
206  currentImmatureBalance = immatureBalance;
207  currentAnonymizedBalance = anonymizedBalance;
208  currentWatchOnlyBalance = watchOnlyBalance;
209  currentWatchUnconfBalance = watchUnconfBalance;
210  currentWatchImmatureBalance = watchImmatureBalance;
215  ui->labelTotal->setText(BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, balance + unconfirmedBalance + immatureBalance, false, BitcoinUnits::separatorAlways));
219  ui->labelWatchTotal->setText(BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, watchOnlyBalance + watchUnconfBalance + watchImmatureBalance, false, BitcoinUnits::separatorAlways));
220 
221  // only show immature (newly mined) balance if it's non-zero, so as not to complicate things
222  // for the non-mining users
223  bool showImmature = immatureBalance != 0;
224  bool showWatchOnlyImmature = watchImmatureBalance != 0;
225 
226  // for symmetry reasons also show immature label when the watch-only one is shown
227  ui->labelImmature->setVisible(showImmature || showWatchOnlyImmature);
228  ui->labelImmatureText->setVisible(showImmature || showWatchOnlyImmature);
229  ui->labelWatchImmature->setVisible(showWatchOnlyImmature); // show watch-only immature balance
230 
232 
233  static int cachedTxLocks = 0;
234 
235  if(cachedTxLocks != nCompleteTXLocks){
236  cachedTxLocks = nCompleteTXLocks;
237  ui->listTransactions->update();
238  }
239 }
240 
241 // show/hide watch-only labels
242 void OverviewPage::updateWatchOnlyLabels(bool showWatchOnly)
243 {
244  ui->labelSpendable->setVisible(showWatchOnly); // show spendable label (only when watch-only is active)
245  ui->labelWatchonly->setVisible(showWatchOnly); // show watch-only label
246  ui->lineWatchBalance->setVisible(showWatchOnly); // show watch-only balance separator line
247  ui->labelWatchAvailable->setVisible(showWatchOnly); // show watch-only available balance
248  ui->labelWatchPending->setVisible(showWatchOnly); // show watch-only pending balance
249  ui->labelWatchTotal->setVisible(showWatchOnly); // show watch-only total balance
250 
251  if (!showWatchOnly){
252  ui->labelWatchImmature->hide();
253  }
254  else{
255  ui->labelBalance->setIndent(20);
256  ui->labelUnconfirmed->setIndent(20);
257  ui->labelImmature->setIndent(20);
258  ui->labelTotal->setIndent(20);
259  }
260 }
261 
263 {
264  this->clientModel = model;
265  if(model)
266  {
267  // Show warning if this is a prerelease version
268  connect(model, SIGNAL(alertsChanged(QString)), this, SLOT(updateAlerts(QString)));
270  }
271 }
272 
274 {
275  this->walletModel = model;
276  if(model && model->getOptionsModel())
277  {
278  // update the display unit, to not use the default ("DASH")
280  // Keep up to date with wallet
283  connect(model, SIGNAL(balanceChanged(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount,CAmount)), this, SLOT(setBalance(CAmount,CAmount,CAmount,CAmount,CAmount,CAmount,CAmount)));
284 
285  connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
286  connect(model->getOptionsModel(), SIGNAL(privateSendRoundsChanged()), this, SLOT(updatePrivateSendProgress()));
287  connect(model->getOptionsModel(), SIGNAL(privateSentAmountChanged()), this, SLOT(updatePrivateSendProgress()));
288  connect(model->getOptionsModel(), SIGNAL(advancedPSUIChanged(bool)), this, SLOT(updateAdvancedPSUI(bool)));
289  // explicitly update PS frame and transaction list to reflect actual settings
291 
292  connect(ui->privateSendAuto, SIGNAL(clicked()), this, SLOT(privateSendAuto()));
293  connect(ui->privateSendReset, SIGNAL(clicked()), this, SLOT(privateSendReset()));
294  connect(ui->privateSendInfo, SIGNAL(clicked()), this, SLOT(privateSendInfo()));
295  connect(ui->togglePrivateSend, SIGNAL(clicked()), this, SLOT(togglePrivateSend()));
297  connect(model, SIGNAL(notifyWatchonlyChanged(bool)), this, SLOT(updateWatchOnlyLabels(bool)));
298  }
299 }
300 
302 {
304  {
306  if(currentBalance != -1)
309 
310  // Update txdelegate->unit with the current unit
312 
313  ui->listTransactions->update();
314  }
315 }
316 
317 void OverviewPage::updateAlerts(const QString &warnings)
318 {
319  this->ui->labelAlerts->setVisible(!warnings.isEmpty());
320  this->ui->labelAlerts->setText(warnings);
321 }
322 
324 {
325  ui->labelWalletStatus->setVisible(fShow);
326  ui->labelPrivateSendSyncStatus->setVisible(fShow);
327  ui->labelTransactionsStatus->setVisible(fShow);
328 }
329 
331 {
333 
334  if(!pwalletMain) return;
335 
336  QString strAmountAndRounds;
338 
339  if(currentBalance == 0)
340  {
341  ui->privateSendProgress->setValue(0);
342  ui->privateSendProgress->setToolTip(tr("No inputs detected"));
343 
344  // when balance is zero just show info from settings
345  strPrivateSendAmount = strPrivateSendAmount.remove(strPrivateSendAmount.indexOf("."), BitcoinUnits::decimals(nDisplayUnit) + 1);
346  strAmountAndRounds = strPrivateSendAmount + " / " + tr("%n Rounds", "", privateSendClient.nPrivateSendRounds);
347 
348  ui->labelAmountRounds->setToolTip(tr("No inputs detected"));
349  ui->labelAmountRounds->setText(strAmountAndRounds);
350  return;
351  }
352 
353  CAmount nAnonymizableBalance = pwalletMain->GetAnonymizableBalance(false, false);
354 
355  CAmount nMaxToAnonymize = nAnonymizableBalance + currentAnonymizedBalance;
356 
357  // If it's more than the anon threshold, limit to that.
358  if(nMaxToAnonymize > privateSendClient.nPrivateSendAmount*COIN) nMaxToAnonymize = privateSendClient.nPrivateSendAmount*COIN;
359 
360  if(nMaxToAnonymize == 0) return;
361 
362  if(nMaxToAnonymize >= privateSendClient.nPrivateSendAmount * COIN) {
363  ui->labelAmountRounds->setToolTip(tr("Found enough compatible inputs to anonymize %1")
364  .arg(strPrivateSendAmount));
365  strPrivateSendAmount = strPrivateSendAmount.remove(strPrivateSendAmount.indexOf("."), BitcoinUnits::decimals(nDisplayUnit) + 1);
366  strAmountAndRounds = strPrivateSendAmount + " / " + tr("%n Rounds", "", privateSendClient.nPrivateSendRounds);
367  } else {
368  QString strMaxToAnonymize = BitcoinUnits::formatHtmlWithUnit(nDisplayUnit, nMaxToAnonymize, false, BitcoinUnits::separatorAlways);
369  ui->labelAmountRounds->setToolTip(tr("Not enough compatible inputs to anonymize <span style='color:red;'>%1</span>,<br>"
370  "will anonymize <span style='color:red;'>%2</span> instead")
371  .arg(strPrivateSendAmount)
372  .arg(strMaxToAnonymize));
373  strMaxToAnonymize = strMaxToAnonymize.remove(strMaxToAnonymize.indexOf("."), BitcoinUnits::decimals(nDisplayUnit) + 1);
374  strAmountAndRounds = "<span style='color:red;'>" +
375  QString(BitcoinUnits::factor(nDisplayUnit) == 1 ? "" : "~") + strMaxToAnonymize +
376  " / " + tr("%n Rounds", "", privateSendClient.nPrivateSendRounds) + "</span>";
377  }
378  ui->labelAmountRounds->setText(strAmountAndRounds);
379 
380  if (!fShowAdvancedPSUI) return;
381 
382  CAmount nDenominatedConfirmedBalance;
383  CAmount nDenominatedUnconfirmedBalance;
384  CAmount nNormalizedAnonymizedBalance;
385  float nAverageAnonymizedRounds;
386 
387  nDenominatedConfirmedBalance = pwalletMain->GetDenominatedBalance();
388  nDenominatedUnconfirmedBalance = pwalletMain->GetDenominatedBalance(true);
389  nNormalizedAnonymizedBalance = pwalletMain->GetNormalizedAnonymizedBalance();
390  nAverageAnonymizedRounds = pwalletMain->GetAverageAnonymizedRounds();
391 
392  // calculate parts of the progress, each of them shouldn't be higher than 1
393  // progress of denominating
394  float denomPart = 0;
395  // mixing progress of denominated balance
396  float anonNormPart = 0;
397  // completeness of full amount anonymization
398  float anonFullPart = 0;
399 
400  CAmount denominatedBalance = nDenominatedConfirmedBalance + nDenominatedUnconfirmedBalance;
401  denomPart = (float)denominatedBalance / nMaxToAnonymize;
402  denomPart = denomPart > 1 ? 1 : denomPart;
403  denomPart *= 100;
404 
405  anonNormPart = (float)nNormalizedAnonymizedBalance / nMaxToAnonymize;
406  anonNormPart = anonNormPart > 1 ? 1 : anonNormPart;
407  anonNormPart *= 100;
408 
409  anonFullPart = (float)currentAnonymizedBalance / nMaxToAnonymize;
410  anonFullPart = anonFullPart > 1 ? 1 : anonFullPart;
411  anonFullPart *= 100;
412 
413  // apply some weights to them ...
414  float denomWeight = 1;
415  float anonNormWeight = privateSendClient.nPrivateSendRounds;
416  float anonFullWeight = 2;
417  float fullWeight = denomWeight + anonNormWeight + anonFullWeight;
418  // ... and calculate the whole progress
419  float denomPartCalc = ceilf((denomPart * denomWeight / fullWeight) * 100) / 100;
420  float anonNormPartCalc = ceilf((anonNormPart * anonNormWeight / fullWeight) * 100) / 100;
421  float anonFullPartCalc = ceilf((anonFullPart * anonFullWeight / fullWeight) * 100) / 100;
422  float progress = denomPartCalc + anonNormPartCalc + anonFullPartCalc;
423  if(progress >= 100) progress = 100;
424 
425  ui->privateSendProgress->setValue(progress);
426 
427  QString strToolPip = ("<b>" + tr("Overall progress") + ": %1%</b><br/>" +
428  tr("Denominated") + ": %2%<br/>" +
429  tr("Mixed") + ": %3%<br/>" +
430  tr("Anonymized") + ": %4%<br/>" +
431  tr("Denominated inputs have %5 of %n rounds on average", "", privateSendClient.nPrivateSendRounds))
432  .arg(progress).arg(denomPart).arg(anonNormPart).arg(anonFullPart)
433  .arg(nAverageAnonymizedRounds);
434  ui->privateSendProgress->setToolTip(strToolPip);
435 }
436 
437 void OverviewPage::updateAdvancedPSUI(bool fShowAdvancedPSUI) {
438  this->fShowAdvancedPSUI = fShowAdvancedPSUI;
439  int nNumItems = (fLiteMode || !fShowAdvancedPSUI) ? NUM_ITEMS : NUM_ITEMS_ADV;
440  SetupTransactionList(nNumItems);
441 
442  if (fLiteMode) return;
443 
444  ui->framePrivateSend->setVisible(true);
449  ui->privateSendAuto->setVisible(fShowAdvancedPSUI);
450  ui->privateSendReset->setVisible(fShowAdvancedPSUI);
451  ui->privateSendInfo->setVisible(true);
453 }
454 
456 {
458 
459  static int64_t nLastDSProgressBlockTime = 0;
460  int nBestHeight = clientModel->getNumBlocks();
461 
462  // We are processing more then 1 block per second, we'll just leave
463  if(((nBestHeight - privateSendClient.nCachedNumBlocks) / (GetTimeMillis() - nLastDSProgressBlockTime + 1) > 1)) return;
464  nLastDSProgressBlockTime = GetTimeMillis();
465 
466  QString strKeysLeftText(tr("keys left: %1").arg(pwalletMain->nKeysLeftSinceAutoBackup));
468  strKeysLeftText = "<span style='color:red;'>" + strKeysLeftText + "</span>";
469  }
470  ui->labelPrivateSendEnabled->setToolTip(strKeysLeftText);
471 
473  if (nBestHeight != privateSendClient.nCachedNumBlocks) {
474  privateSendClient.nCachedNumBlocks = nBestHeight;
476  }
477 
478  ui->labelPrivateSendLastMessage->setText("");
479  ui->togglePrivateSend->setText(tr("Start Mixing"));
480 
481  QString strEnabled = tr("Disabled");
482  // Show how many keys left in advanced PS UI mode only
483  if (fShowAdvancedPSUI) strEnabled += ", " + strKeysLeftText;
484  ui->labelPrivateSendEnabled->setText(strEnabled);
485 
486  return;
487  }
488 
489  // Warn user that wallet is running out of keys
490  // NOTE: we do NOT warn user and do NOT create autobackups if mixing is not running
492  QSettings settings;
493  if(settings.value("fLowKeysWarning").toBool()) {
494  QString strWarn = tr("Very low number of keys left since last automatic backup!") + "<br><br>" +
495  tr("We are about to create a new automatic backup for you, however "
496  "<span style='color:red;'> you should always make sure you have backups "
497  "saved in some safe place</span>!") + "<br><br>" +
498  tr("Note: You turn this message off in options.");
499  ui->labelPrivateSendEnabled->setToolTip(strWarn);
500  LogPrintf("OverviewPage::privateSendStatus -- Very low number of keys left since last automatic backup, warning user and trying to create new backup...\n");
501  QMessageBox::warning(this, tr("PrivateSend"), strWarn, QMessageBox::Ok, QMessageBox::Ok);
502  } else {
503  LogPrintf("OverviewPage::privateSendStatus -- Very low number of keys left since last automatic backup, skipping warning and trying to create new backup...\n");
504  }
505 
506  std::string strBackupWarning;
507  std::string strBackupError;
508  if(!AutoBackupWallet(pwalletMain, "", strBackupWarning, strBackupError)) {
509  if (!strBackupWarning.empty()) {
510  // It's still more or less safe to continue but warn user anyway
511  LogPrintf("OverviewPage::privateSendStatus -- WARNING! Something went wrong on automatic backup: %s\n", strBackupWarning);
512 
513  QMessageBox::warning(this, tr("PrivateSend"),
514  tr("WARNING! Something went wrong on automatic backup") + ":<br><br>" + strBackupWarning.c_str(),
515  QMessageBox::Ok, QMessageBox::Ok);
516  }
517  if (!strBackupError.empty()) {
518  // Things are really broken, warn user and stop mixing immediately
519  LogPrintf("OverviewPage::privateSendStatus -- ERROR! Failed to create automatic backup: %s\n", strBackupError);
520 
521  QMessageBox::warning(this, tr("PrivateSend"),
522  tr("ERROR! Failed to create automatic backup") + ":<br><br>" + strBackupError.c_str() + "<br>" +
523  tr("Mixing is disabled, please close your wallet and fix the issue!"),
524  QMessageBox::Ok, QMessageBox::Ok);
525  }
526  }
527  }
528 
529  QString strEnabled = privateSendClient.fEnablePrivateSend ? tr("Enabled") : tr("Disabled");
530  // Show how many keys left in advanced PS UI mode only
531  if(fShowAdvancedPSUI) strEnabled += ", " + strKeysLeftText;
532  ui->labelPrivateSendEnabled->setText(strEnabled);
533 
534  if(nWalletBackups == -1) {
535  // Automatic backup failed, nothing else we can do until user fixes the issue manually
537 
538  QString strError = tr("ERROR! Failed to create automatic backup") + ", " +
539  tr("see debug.log for details.") + "<br><br>" +
540  tr("Mixing is disabled, please close your wallet and fix the issue!");
541  ui->labelPrivateSendEnabled->setToolTip(strError);
542 
543  return;
544  } else if(nWalletBackups == -2) {
545  // We were able to create automatic backup but keypool was not replenished because wallet is locked.
546  QString strWarning = tr("WARNING! Failed to replenish keypool, please unlock your wallet to do so.");
547  ui->labelPrivateSendEnabled->setToolTip(strWarning);
548  }
549 
550  // check darksend status and unlock if needed
551  if(nBestHeight != privateSendClient.nCachedNumBlocks) {
552  // Balance and number of transactions might have changed
553  privateSendClient.nCachedNumBlocks = nBestHeight;
555  }
556 
557  QString strStatus = QString(privateSendClient.GetStatus().c_str());
558 
559  QString s = tr("Last PrivateSend message:\n") + strStatus;
560 
561  if(s != ui->labelPrivateSendLastMessage->text())
562  LogPrintf("OverviewPage::privateSendStatus -- Last PrivateSend message: %s\n", strStatus.toStdString());
563 
564  ui->labelPrivateSendLastMessage->setText(s);
565 
567  ui->labelSubmittedDenom->setText(tr("N/A"));
568  } else {
570  ui->labelSubmittedDenom->setText(strDenom);
571  }
572 
573 }
574 
577 }
578 
581 
582  QMessageBox::warning(this, tr("PrivateSend"),
583  tr("PrivateSend was successfully reset."),
584  QMessageBox::Ok, QMessageBox::Ok);
585 }
586 
589  dlg.exec();
590 }
591 
593  QSettings settings;
594  // Popup some information on first mixing
595  QString hasMixed = settings.value("hasMixed").toString();
596  if(hasMixed.isEmpty()){
597  QMessageBox::information(this, tr("PrivateSend"),
598  tr("If you don't want to see internal PrivateSend fees/transactions select \"Most Common\" as Type on the \"Transactions\" tab."),
599  QMessageBox::Ok, QMessageBox::Ok);
600  settings.setValue("hasMixed", "hasMixed");
601  }
604  if(currentBalance < nMinAmount){
605  QString strMinAmount(BitcoinUnits::formatWithUnit(nDisplayUnit, nMinAmount));
606  QMessageBox::warning(this, tr("PrivateSend"),
607  tr("PrivateSend requires at least %1 to use.").arg(strMinAmount),
608  QMessageBox::Ok, QMessageBox::Ok);
609  return;
610  }
611 
612  // if wallet is locked, ask for a passphrase
614  {
616  if(!ctx.isValid())
617  {
618  //unlock was cancelled
619  privateSendClient.nCachedNumBlocks = std::numeric_limits<int>::max();
620  QMessageBox::warning(this, tr("PrivateSend"),
621  tr("Wallet is locked and user declined to unlock. Disabling PrivateSend."),
622  QMessageBox::Ok, QMessageBox::Ok);
623  LogPrint("privatesend", "OverviewPage::togglePrivateSend -- Wallet is locked and user declined to unlock. Disabling PrivateSend.\n");
624  return;
625  }
626  }
627 
628  }
629 
631  privateSendClient.nCachedNumBlocks = std::numeric_limits<int>::max();
632 
634  ui->togglePrivateSend->setText(tr("Start Mixing"));
636  } else {
637  ui->togglePrivateSend->setText(tr("Stop Mixing"));
638 
639  /* show darksend configuration if client has defaults set */
640 
642  DarksendConfig dlg(this);
643  dlg.setModel(walletModel);
644  dlg.exec();
645  }
646 
647  }
648 }
649 
651  ui->listTransactions->setMinimumHeight(nNumItems * (DECORATION_SIZE + 2));
652 
654  // Set up transaction list
655  filter.reset(new TransactionFilterProxy());
656  filter->setSourceModel(walletModel->getTransactionTableModel());
657  filter->setLimit(nNumItems);
658  filter->setDynamicSortFilter(true);
659  filter->setSortRole(Qt::EditRole);
660  filter->setShowInactive(false);
661  filter->sort(TransactionTableModel::Status, Qt::DescendingOrder);
662 
663  ui->listTransactions->setModel(filter.get());
665  }
666 }
667 
669  ui->togglePrivateSend->setText("(" + tr("Disabled") + ")");
670  ui->privateSendAuto->setText("(" + tr("Disabled") + ")");
671  ui->privateSendReset->setText("(" + tr("Disabled") + ")");
672  ui->framePrivateSend->setEnabled(false);
673  if (nWalletBackups <= 0) {
674  ui->labelPrivateSendEnabled->setText("<span style='color:red;'>(" + tr("Disabled") + ")</span>");
675  }
677 }
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
static CAmount GetMaxCollateralAmount()
Definition: privatesend.h:350
OverviewPage(const PlatformStyle *platformStyle, QWidget *parent=0)
QLabel * labelSubmittedDenom
void handleTransactionClicked(const QModelIndex &index)
void updateAlerts(const QString &warnings)
static QString floorWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with unit) but floor value up to "digits" settings.
CMasternodeSync masternodeSync
QPushButton * privateSendInfo
int nCompleteTXLocks
Definition: instantx.cpp:28
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
QPushButton * privateSendReset
const PlatformStyle * platformStyle
QLabel * labelWalletStatus
#define DECORATION_SIZE
QFrame * lineWatchBalance
QString getStatusBarWarnings() const
Return warnings to be displayed in status bar.
bool ShutdownRequested()
Definition: init.cpp:168
void setupUi(QWidget *OverviewPage)
bool fShowAdvancedPSUI
Definition: overviewpage.h:62
void setBalance(const CAmount &balance, const CAmount &unconfirmedBalance, const CAmount &immatureBalance, const CAmount &anonymizedBalance, const CAmount &watchOnlyBalance, const CAmount &watchUnconfBalance, const CAmount &watchImmatureBalance)
void updateAdvancedPSUI(bool fShowAdvancedPSUI)
static const CAmount COIN
Definition: amount.h:16
static std::string GetDenominationsToString(int nDenom)
TxViewDelegate(const PlatformStyle *_platformStyle, QObject *parent=nullptr)
static const int PRIVATESEND_KEYS_THRESHOLD_WARNING
void updatePrivateSendProgress()
QIcon SingleColorIcon(const QString &filename) const
void privateSendReset()
CAmount currentWatchUnconfBalance
Definition: overviewpage.h:59
static CAmount GetSmallestDenomination()
Definition: privatesend.h:329
void transactionClicked(const QModelIndex &index)
EncryptionStatus getEncryptionStatus() const
CWallet * pwalletMain
int getNumBlocks() const
Definition: clientmodel.cpp:94
QLabel * labelAmountRounds
void showOutOfSyncWarning(bool fShow)
void DisablePrivateSendCompletely()
void handleOutOfSyncWarningClicks()
std::unique_ptr< TransactionFilterProxy > filter
Definition: overviewpage.h:65
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with unit)
bool haveWatchOnly() const
CAmount currentAnonymizedBalance
Definition: overviewpage.h:57
CAmount GetAnonymizableBalance(bool fSkipDenominated=false, bool fSkipUnconfirmed=true) const
Definition: wallet.cpp:2155
TransactionTableModel * getTransactionTableModel()
QLabel * labelSubmittedDenomText
void privateSendStatus()
dictionary settings
CAmount getWatchImmatureBalance() const
QLabel * labelWatchPending
QLabel * labelTransactionsStatus
QLabel * labelWatchTotal
bool fMasterNode
Definition: util.cpp:108
static QString floorHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
CAmount getAnonymizedBalance() const
Definition: walletmodel.cpp:91
int64_t CAmount
Definition: amount.h:14
QLabel * labelWatchAvailable
void privateSendAuto()
static QString formatHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as HTML string (with unit)
TxViewDelegate * txdelegate
Definition: overviewpage.h:64
bool fLiteMode
Definition: util.cpp:109
void setWalletModel(WalletModel *walletModel)
void updateDisplayUnit()
int nWalletBackups
Definition: util.cpp:117
#define LogPrintf(...)
Definition: util.h:98
QLabel * labelImmature
QLabel * labelPrivateSendSyncStatus
#define NUM_ITEMS
static int LogPrint(const char *category, const char *format)
Definition: util.h:126
QLabel * labelPrivateSendEnabled
void togglePrivateSend()
ClientModel * clientModel
Definition: overviewpage.h:52
QLabel * labelWatchImmature
WalletModel * walletModel
Definition: overviewpage.h:53
static secp256k1_context * ctx
Definition: tests.c:42
bool getShowAdvancedPSUI()
Definition: optionsmodel.h:77
float GetAverageAnonymizedRounds() const
Definition: wallet.cpp:2202
CAmount currentUnconfirmedBalance
Definition: overviewpage.h:55
static qint64 factor(int unit)
Number of Satoshis (1e-8) per unit.
OptionsModel * getOptionsModel()
CAmount getWatchUnconfirmedBalance() const
QLabel * labelAnonymized
#define COLOR_UNCONFIRMED
Definition: guiconstants.h:24
void setClientModel(ClientModel *clientModel)
QLabel * labelWatchonly
QPushButton * privateSendAuto
void outOfSyncWarningClicked()
void SetupTransactionList(int nNumItems)
CPrivateSendClient privateSendClient
void setModel(WalletModel *model)
static int decimals(int unit)
Number of decimals left.
QLabel * labelImmatureText
CAmount GetDenominatedBalance(bool unconfirmed=false) const
Definition: wallet.cpp:2268
int64_t GetTimeMillis()
Definition: utiltime.cpp:34
CAmount currentWatchImmatureBalance
Definition: overviewpage.h:60
QString getThemeName()
Definition: guiutil.cpp:902
QLabel * labelBalance
QLabel * labelCompletitionText
bool IsBlockchainSynced()
QLabel * labelUnconfirmed
#define NUM_ITEMS_ADV
QLabel * labelAlerts
CAmount currentImmatureBalance
Definition: overviewpage.h:56
std::unique_ptr< CConnman > g_connman
Definition: init.cpp:103
QLabel * labelSpendable
void updateWatchOnlyLabels(bool showWatchOnly)
CAmount getUnconfirmedBalance() const
Definition: walletmodel.cpp:96
int getDisplayUnit()
Definition: optionsmodel.h:73
Ui::OverviewPage * ui
Definition: overviewpage.h:51
CAmount getBalance(const CCoinControl *coinControl=NULL) const
Definition: walletmodel.cpp:73
QFrame * framePrivateSend
CAmount getWatchBalance() const
QProgressBar * privateSendProgress
#define ICON_OFFSET
bool DoAutomaticDenominating(CConnman &connman, bool fDryRun=false)
Passively run mixing in the background according to the configuration in settings.
CAmount getImmatureBalance() const
QPushButton * togglePrivateSend
CAmount currentWatchOnlyBalance
Definition: overviewpage.h:58
int64_t nKeysLeftSinceAutoBackup
Definition: wallet.h:755
bool AutoBackupWallet(CWallet *wallet, std::string strWalletFile, std::string &strBackupWarning, std::string &strBackupError)
Definition: walletdb.cpp:946
#define COLOR_NEGATIVE
Definition: guiconstants.h:26
QListView * listTransactions
CAmount GetNormalizedAnonymizedBalance() const
Definition: wallet.cpp:2224
CAmount currentBalance
Definition: overviewpage.h:54
void privateSendInfo()
UnlockContext requestUnlock(bool fForMixingOnly=false)
QTimer * timer
Definition: overviewpage.h:50
QLabel * labelPrivateSendLastMessage
QString dateTimeStr(const QDateTime &date)
Definition: guiutil.cpp:87