PRCYCoin  2.0.0.7rc1
P2P Digital Currency
overviewpage.cpp
Go to the documentation of this file.
1 // Copyright (c) 2011-2014 The Bitcoin developers
2 // Copyright (c) 2014-2015 The Dash developers
3 // Copyright (c) 2015-2018 The PIVX developers
4 // Copyright (c) 2018-2020 The DAPS Project developers
5 // Distributed under the MIT/X11 software license, see the accompanying
6 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
7 
8 #include "overviewpage.h"
9 #include "ui_overviewpage.h"
10 #include "bitcoinunits.h"
11 #include "clientmodel.h"
12 #include "curl_json.h"
13 #include "guiconstants.h"
14 #include "guiutil.h"
15 #include "init.h"
16 #include "optionsmodel.h"
17 #include "transactionfilterproxy.h"
18 #include "transactiontablemodel.h"
19 #include "txentry.h"
20 #include "walletmodel.h"
21 
22 #include <QAbstractItemDelegate>
23 #include <QPainter>
24 #include <QtMath>
25 #include <QJsonObject>
26 #include <QJsonArray>
27 #include <QJsonDocument>
28 
29 #define DECORATION_SIZE 48
30 #define ICON_OFFSET 16
31 #define NUM_ITEMS 5
32 
33 extern CWallet* pwalletMain;
34 
35 class TxViewDelegate : public QAbstractItemDelegate
36 {
37  Q_OBJECT
38 public:
39  TxViewDelegate() : QAbstractItemDelegate(), unit(BitcoinUnits::PRCY)
40  {
41  }
42 
43  inline void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
44  {
45  painter->save();
46 
47  QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
48  QRect mainRect = option.rect;
49  mainRect.moveLeft(ICON_OFFSET);
50  QRect decorationRect(mainRect.topLeft(), QSize(DECORATION_SIZE, DECORATION_SIZE));
51  int xspace = DECORATION_SIZE + 8;
52  int ypad = 6;
53  int halfheight = (mainRect.height() - 2 * ypad) / 2;
54  QRect amountRect(mainRect.left() + xspace, mainRect.top() + ypad, mainRect.width() - xspace - ICON_OFFSET, halfheight);
55  QRect addressRect(mainRect.left() + xspace, mainRect.top() + ypad + halfheight, mainRect.width() - xspace, halfheight);
56  icon.paint(painter, decorationRect);
57 
58  QDateTime date = index.data(TransactionTableModel::DateRole).toDateTime();
59  QString address = index.data(Qt::DisplayRole).toString();
60  qint64 amount = index.data(TransactionTableModel::AmountRole).toLongLong();
61  bool confirmed = index.data(TransactionTableModel::ConfirmedRole).toBool();
62  QVariant value = index.data(Qt::ForegroundRole);
63  QColor foreground = COLOR_BLACK;
64  if (value.canConvert<QBrush>()) {
65  QBrush brush = qvariant_cast<QBrush>(value);
66  foreground = brush.color();
67  }
68 
69  painter->setPen(foreground);
70  QRect boundingRect;
71  painter->drawText(addressRect, Qt::AlignLeft | Qt::AlignVCenter, address, &boundingRect);
72 
73  if (index.data(TransactionTableModel::WatchonlyRole).toBool()) {
74  QIcon iconWatchonly = qvariant_cast<QIcon>(index.data(TransactionTableModel::WatchonlyDecorationRole));
75  QRect watchonlyRect(boundingRect.right() + 5, mainRect.top() + ypad + halfheight, 16, halfheight);
76  iconWatchonly.paint(painter, watchonlyRect);
77  }
78 
79  if (amount < 0)
80  foreground = COLOR_NEGATIVE;
81 
82  painter->setPen(foreground);
83  QString amountText = BitcoinUnits::formatWithUnit(unit, amount, true, BitcoinUnits::separatorAlways);
84  if (!confirmed) {
85  amountText = QString("[") + amountText + QString("]");
86  }
87  painter->drawText(amountRect, Qt::AlignRight | Qt::AlignVCenter, amountText);
88 
89  painter->setPen(COLOR_BLACK);
90  painter->drawText(amountRect, Qt::AlignLeft | Qt::AlignVCenter, GUIUtil::dateTimeStr(date));
91 
92  painter->restore();
93  }
94 
95  inline QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
96  {
97  return QSize(DECORATION_SIZE, DECORATION_SIZE);
98  }
99 
100  int unit;
101 };
102 #include "overviewpage.moc"
103 
104 OverviewPage::OverviewPage(QWidget* parent) : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint),
105  ui(new Ui::OverviewPage),
106  clientModel(0),
107  walletModel(0),
108  currentBalance(-1),
109  currentUnconfirmedBalance(-1),
110  currentImmatureBalance(-1),
111  currentWatchOnlyBalance(-1),
112  currentWatchUnconfBalance(-1),
113  currentWatchImmatureBalance(-1),
114  txdelegate(new TxViewDelegate()),
115  // m_SizeGrip(this),
116  filter(0)
117 {
118  nDisplayUnit = 0; // just make sure it's not unitialized
119  ui->setupUi(this);
120 
121  pingNetworkInterval = new QTimer(this);
122  connect(pingNetworkInterval, SIGNAL(timeout()), this, SLOT(tryNetworkBlockCount()));
123  pingNetworkInterval->setInterval(3000);
124  pingNetworkInterval->start();
125 
126  // Init getCurrencyValueInterval
127  updateJSONtimer = new QTimer(this);
128  updateGUItimer = new QTimer(this);
129  manager = new QNetworkAccessManager(this);
130  reply = nullptr;
131 
132  connect(updateJSONtimer, SIGNAL(timeout()), SLOT(getCurrencyValue()));
133  connect(updateGUItimer, SIGNAL(timeout()), SLOT(setCurrencyValue()));
134 
135  updateJSONtimer->setInterval(300000); //Check every 5 minutes.
136  updateJSONtimer->start();
137 
138  updateGUItimer->setInterval(15000); //Check every 15 seconds.
139  updateGUItimer->start();
140 
142 
143  initSyncCircle(.8);
144 
145  connect(ui->btnLockUnlock, SIGNAL(clicked()), this, SLOT(on_lockUnlock()));
146 }
147 
148 void OverviewPage::handleTransactionClicked(const QModelIndex& index)
149 {
150  if (filter)
151  Q_EMIT transactionClicked(filter->mapToSource(index));
152 }
153 
155 {
156  if (animClock)
157  delete animClock;
158  delete ui;
159 }
160 
161 void OverviewPage::getPercentage(CAmount nUnlockedBalance, QString& sPRCYPercentage)
162 {
163  int nPrecision = 2;
164 
165  double dPercentage = 100.0;
166 
167  sPRCYPercentage = "(" + QLocale(QLocale::system()).toString(dPercentage, 'f', nPrecision) + " %)";
168 }
169 void OverviewPage::setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance,
170  const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance)
171 {
172  int walletStatus = walletModel->getEncryptionStatus();
173  bool stkStatus = pwalletMain->ReadStakingStatus();
174 
175  currentBalance = balance;
176  currentUnconfirmedBalance = unconfirmedBalance;
177  currentImmatureBalance = immatureBalance;
178  currentWatchOnlyBalance = watchOnlyBalance;
179  currentWatchUnconfBalance = watchUnconfBalance;
180  currentWatchImmatureBalance = watchImmatureBalance;
181  CAmount nSpendableBalance = 0;
182  nSpendableBalance = pwalletMain->GetSpendableBalance();
183 
184  CAmount nSpendableDisplayed = nSpendableBalance; //if it is not staking
186  //if staking enabled
187  nSpendableDisplayed = nSpendableDisplayed > nReserveBalance ? nReserveBalance:nSpendableDisplayed;
188  }
189  // PRCY labels
190  //TODO-NOTE: Remove immatureBalance from showing on qt wallet (as requested)
191  if (walletStatus == WalletModel::Locked || walletStatus == WalletModel::UnlockedForStakingOnly) {
192  ui->labelBalance_2->setText("Locked; Hidden");
193  ui->labelBalance->setText("Locked; Hidden");
194  ui->labelUnconfirmed->setText("Locked; Hidden");
195  ui->btnLockUnlock->setStyleSheet("border-image: url(:/images/lock) 0 0 0 0 stretch stretch; width: 20px;");
196  } else if (settings.value("fHideBalance", false).toBool()) {
197  ui->labelBalance_2->setText("Hidden");
198  ui->labelBalance->setText("Hidden");
199  ui->labelUnconfirmed->setText("Hidden");
200  } else {
201  ui->labelBalance_2->setText(BitcoinUnits::formatHtmlWithUnit(0, balance, false, BitcoinUnits::separatorAlways));
202  ui->labelBalance_2->setToolTip("Your current balance");
203  ui->labelBalance->setText(BitcoinUnits::formatHtmlWithUnit(0, nSpendableDisplayed, false, BitcoinUnits::separatorAlways));
204  ui->labelUnconfirmed->setText(BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, unconfirmedBalance, false, BitcoinUnits::separatorAlways));
205  ui->btnLockUnlock->setStyleSheet("border-image: url(:/images/unlock) 0 0 0 0 stretch stretch; width: 30px;");
206  }
207  QFont font = ui->labelBalance_2->font();
208  font.setPointSize(15);
209  font.setBold(true);
210  ui->labelBalance_2->setFont(font);
211 
214 }
215 
216 // show/hide watch-only labels
217 void OverviewPage::updateWatchOnlyLabels(bool showWatchOnly)
218 {
219  ui->labelBalance->setIndent(20);
220  ui->labelUnconfirmed->setIndent(20);
221 }
222 
224 {
225  this->clientModel = model;
226  if (model) {
227  // Show warning if this is a prerelease version
228  connect(model, SIGNAL(alertsChanged(QString)), this, SLOT(updateAlerts(QString)));
230  connect(model, SIGNAL(numBlocksChanged(int)), this, SLOT(showBlockCurrentHeight(int)));
232  }
233 }
234 
235 void OverviewPage::setSpendableBalance(bool isStaking) {
236  TRY_LOCK(cs_main, lockMain);
237  if (!lockMain)
238  return;
239  TRY_LOCK(pwalletMain->cs_wallet, lockWallet);
240  if (!lockWallet)
241  return;
242  {
243  CAmount nSpendableDisplayed = this->walletModel->getSpendableBalance();
244  if (isStaking) {
245  //if staking enabled
246  nSpendableDisplayed = nSpendableDisplayed > nReserveBalance ? nReserveBalance:nSpendableDisplayed;
247  }
248  ui->labelBalance->setText(BitcoinUnits::floorHtmlWithUnit(nDisplayUnit, nSpendableDisplayed, false, BitcoinUnits::separatorAlways));
249  }
250 }
251 
253 {
254  this->walletModel = model;
255  if (model && model->getOptionsModel()) {
256  // Set up transaction list
257  filter = new TransactionFilterProxy(this);
258  filter->setSourceModel(model->getTransactionTableModel());
260  filter->setDynamicSortFilter(true);
261  filter->setSortRole(Qt::EditRole);
262  filter->setShowInactive(false);
263  filter->sort(TransactionTableModel::Date, Qt::DescendingOrder);
264 
265  // Keep up to date with wallet
266  setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(),
268  connect(model, SIGNAL(balanceChanged(CAmount, CAmount, CAmount, CAmount, CAmount, CAmount)), this,
270  connect(model, SIGNAL(stakingStatusChanged(bool)), this,
271  SLOT(setSpendableBalance(bool)));
272  connect(model, SIGNAL(WalletUnlocked()), this,
273  SLOT(updateBalance()));
274  connect(model, SIGNAL(encryptionStatusChanged(int)), this,
275  SLOT(updateLockStatus(int)));
276 
277  connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
278  connect(model->getOptionsModel(), SIGNAL(hideOrphansChanged(bool)), this, SLOT(hideOrphans(bool)));
279 
281  connect(model, SIGNAL(notifyWatchonlyChanged(bool)), this, SLOT(updateWatchOnlyLabels(bool)));
283  }
284  // update the display unit, to not use the default ("PRCY")
286 
287  // Hide orphans
288  hideOrphans(settings.value("fHideOrphans", false).toBool());
289 }
290 
292 {
293  WalletModel* model = this->walletModel;
294  setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(),
296 }
297 
299 {
302  if (currentBalance != -1)
305 
306  // Update txdelegate->unit with the current unit
308  }
309 }
310 
312 {
313  if (filter)
314  filter->setHideOrphans(fHide);
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  ui->labelWalletStatus->setVisible(fShow);
325  ui->labelPendingText->setVisible(true);
326  ui->labelUnconfirmed->setVisible(true);
327  ui->labelBalanceText->setVisible(true);
328  isSyncingBalance = fShow;
329  if (isSyncingBalance){
330  QString tooltip = "The displayed information may be out of date. Your wallet automatically synchronizes with the PRCY network after a connection is established, but this process has not completed yet.";
331  ui->labelUnconfirmed->setToolTip(tooltip);
332  ui->labelBalance->setToolTip(tooltip);
333  } else {
334  ui->labelUnconfirmed->setToolTip("Your pending balance");
335  ui->labelBalance->setToolTip("Your current balance");
336  }
337 }
338 
340 {
341  ui->labelBlockOf->setVisible(fShow);
342  ui->labelBlocksTotal->setVisible(fShow);
343 
344  isSyncingBlocks = fShow;
345 
346  int count = clientModel->getNumBlocks();
347  ui->labelBlockCurrent->setText(QString::number(count));
348 
349  if (isSyncingBlocks){
350  ui->labelBlockStatus->setText("(syncing)");
351  ui->labelBlockStatus->setToolTip("The displayed information may be out of date. Your wallet automatically synchronizes with the PRCY network after a connection is established, but this process has not completed yet.");
352  ui->labelBlockCurrent->setAlignment((Qt::AlignRight|Qt::AlignVCenter));
353  } else {
354  ui->labelBlockStatus->setText("(synced)");
355  ui->labelBlockStatus->setToolTip("Your wallet is fully synchronized with the PRCY network.");
356  ui->labelBlockCurrent->setAlignment((Qt::AlignHCenter|Qt::AlignVCenter));
357  }
358 }
359 
361 {
362  ui->labelBlockCurrent->setText(QString::number(count));
363 }
364 
365 void OverviewPage::initSyncCircle(float ratioToParent)
366 {
367  animTicker = new QTimer(this);
368  animTicker->setInterval(17); //17 mSecs or ~60 fps
369  animClock = new QElapsedTimer();
370  connect(animTicker, SIGNAL(timeout()), this, SLOT(onAnimTick()));
371  animTicker->start();
372  animClock->start();
373 
374  blockAnimSyncCircle = new QWidget(ui->widgetSyncBlocks);
375  blockAnimSyncCircle->setStyleSheet("image:url(':/images/syncb')");//"background-image: ./image.png");
376  blockAnimSyncCircle->setGeometry(getCircleGeometry(ui->widgetSyncBlocks, ratioToParent));
377  blockAnimSyncCircle->show();
378 
379  blockSyncCircle = new QWidget(ui->widgetSyncBlocks);
380  blockSyncCircle->setStyleSheet("image:url(':/images/syncp')");//"background-image: ./image.png");
381  blockSyncCircle->setGeometry(getCircleGeometry(ui->widgetSyncBlocks, ratioToParent));
382  blockSyncCircle->show();
383 
384  balanceAnimSyncCircle = new QWidget(ui->widgetSyncBalance);
385  balanceAnimSyncCircle->setStyleSheet("image:url(':/images/syncb')");//"background-image: ./image.png");
386  balanceAnimSyncCircle->setGeometry(getCircleGeometry(ui->widgetSyncBalance, ratioToParent));
387  balanceAnimSyncCircle->show();
388 
389  balanceSyncCircle = new QWidget(ui->widgetSyncBalance);
390  balanceSyncCircle->setStyleSheet("image:url(':/images/syncp')");//"background-image: ./image.png");
391  balanceSyncCircle->setGeometry(getCircleGeometry(ui->widgetSyncBalance, ratioToParent));
392  balanceSyncCircle->show();
393 }
394 
396 {
397  if (isSyncingBlocks){
399  blockSyncCircle->setStyleSheet("image:url(':/images/syncp')");
400  blockAnimSyncCircle->setVisible(true);
401  } else {
402  blockSyncCircle->setStyleSheet("image:url(':/images/syncb')");
403  blockAnimSyncCircle->setVisible(false);
404  ui->lblHelp->setText(ui->lblHelp->text().remove("It is advised not to send or receive coins until your current sync is complete."));
405  }
406  if (isSyncingBalance){
408  balanceSyncCircle->setStyleSheet("image:url(':/images/syncp')");
409  balanceAnimSyncCircle->setVisible(true);
410  } else {
411  balanceSyncCircle->setStyleSheet("image:url(':/images/syncb')");
412  balanceAnimSyncCircle->setVisible(false);
413  }
415 }
416 
417 void OverviewPage::moveSyncCircle(QWidget* anchor, QWidget* animated, int deltaRadius, float degreesPerSecond, float angleOffset) //deltaRad in px
418 {
419  auto centerX = anchor->parentWidget()->width()/10; //center of anchor
420  auto centerY = anchor->parentWidget()->height()/10;
421  auto angle = float(animClock->elapsed()/*%3600*/)*degreesPerSecond/1000;
422  angle = qDegreesToRadians(angle+angleOffset); //rotation angle from time elapsed
423  auto newX = centerX+deltaRadius*qCos(angle); //delta position plus anchor position
424  auto newY = centerY+deltaRadius*qSin(angle);
425 
426  animated->setGeometry(newX, newY, anchor->width(), anchor->height());
427 }
428 
429 QRect OverviewPage::getCircleGeometry(QWidget* parent, float ratioToParent)
430 {
431  auto width = parent->width()*ratioToParent;
432  auto height = parent->height()*ratioToParent;
433  auto x = (parent->width()-width)/2;
434  auto y = (parent->height()-height)/2;
435  return QRect(x,y,width,height);
436 }
437 
439  ui->labelBlocksTotal->setText(QString::number(networkBlockCount));
440 }
441 
443  try{
444  LOCK(cs_vNodes);
445  if (vNodes.size()>=1){
446  int highestCount = 0;
447  for (CNode* node : vNodes)
448  if (node->nStartingHeight>highestCount)
449  highestCount = node->nStartingHeight;
450  if (highestCount>550){
451  networkBlockCount = highestCount;
453  return highestCount;
454  }
455  }
456  }catch(int err_code)
457  {
458  }
459  return -1;
460 }
461 
463  if (!pwalletMain) return;
464  {
466  QLayoutItem* item;
467 
468  while ( ( item = ui->verticalLayoutRecent->takeAt( 0 ) ) != NULL )
469  {
470  delete item->widget();
471  delete item;
472  }
473  if (pwalletMain) {
474  {
475  std::vector<std::map<QString, QString>> txs;// = WalletUtil::getTXs(pwalletMain);
476 
477  std::map<uint256, CWalletTx> txMap = pwalletMain->mapWallet;
478  std::vector<CWalletTx> latestTxes;
479  for (std::map<uint256, CWalletTx>::iterator tx = txMap.begin(); tx != txMap.end(); ++tx) {
480  if (tx->second.GetDepthInMainChain() > 0) {
481  int64_t txTime = tx->second.GetComputedTxTime();
482  int idx = -1;
483  for (int i = 0; i < (int)latestTxes.size(); i++) {
484  if (txTime >= latestTxes[i].GetComputedTxTime()) {
485  idx = i;
486  break;
487  }
488  }
489  if (idx == -1) {
490  latestTxes.push_back(tx->second);
491  } else {
492  latestTxes.insert(latestTxes.begin() + idx, tx->second);
493  }
494  }
495  }
496 
497  for (int i = 0; i < (int)latestTxes.size(); i++) {
498  txs.push_back(WalletUtil::getTx(pwalletMain, latestTxes[i]));
499  if (txs.size() >= NUM_ITEMS) break;
500  }
501 
502  int length = (txs.size()>NUM_ITEMS)? NUM_ITEMS:txs.size();
503  for (int i = 0; i< length; i++){
504  uint256 txHash;
505  txHash.SetHex(txs[i]["id"].toStdString());
506  TxEntry* entry = new TxEntry(this);
507  ui->verticalLayoutRecent->addWidget(entry);
508  CWalletTx wtx = pwalletMain->mapWallet[txHash];
509  int64_t txTime = wtx.GetComputedTxTime();
510  if (pwalletMain->IsLocked()) {
511  entry->setData(txTime, "Locked; Hidden", "Locked; Hidden", "Locked; Hidden", "Locked; Hidden");
512  } else if (settings.value("fHideBalance", false).toBool()) {
513  entry->setData(txTime, "Hidden", "Hidden", "Hidden", "Hidden");
514  } else {
515  entry->setData(txTime, txs[i]["address"] , txs[i]["amount"], txs[i]["id"], txs[i]["type"]);
516  }
517 
518  if (i % 2 == 0) {
519  entry->setObjectName("secondaryTxEntry");
520  }
521  }
522  if (latestTxes.size() >= 10000) {
523  QString txWarning = "Your wallet has more than 10,000 Transactions. It may run slowly. It's recommended to send your funds to a new wallet.";
524  txWarning.append(" <a href=\"https://prcycoin.com/knowledge-base/wallets/sluggish-large-wallet-dat-solution/\">Need Help?</a>");
525  if (!ui->lblHelp->text().contains(txWarning)) {
526  ui->lblHelp->setText(ui->lblHelp->text() + "<br>" + txWarning);
527  }
528  }
529 
530  ui->lblRecentTransaction->setVisible(true);
531  }
532  } else {
533  LogPrintf("pwalletMain has not been initialized\n");
534  }
535  }
536 }
537 
541  if (ctx.isValid()) {
542  ui->btnLockUnlock->setStyleSheet("border-image: url(:/images/unlock) 0 0 0 0 stretch stretch; width: 30px;");
548  }
549  }
550  else {
551  QMessageBox::StandardButton msgReply;
552  msgReply = QMessageBox::question(this, "Lock Wallet", "Would you like to lock your wallet now?\n\n(Staking will also be stopped)", QMessageBox::Yes|QMessageBox::No);
553  if (msgReply == QMessageBox::Yes) {
555  ui->btnLockUnlock->setStyleSheet("border-image: url(:/images/lock) 0 0 0 0 stretch stretch; width: 20px;");
556  ui->labelBalance_2->setText("Locked; Hidden");
557  ui->labelBalance->setText("Locked; Hidden");
558  ui->labelUnconfirmed->setText("Locked; Hidden");
560  }
561  }
562 }
563 
565  if (!walletModel)
566  return;
567 
568  // update wallet state
569  if (status == WalletModel::Locked || status == WalletModel::UnlockedForStakingOnly)
570  ui->btnLockUnlock->setStyleSheet("border-image: url(:/images/lock) 0 0 0 0 stretch stretch; width: 20px;");
571  else
572  ui->btnLockUnlock->setStyleSheet("border-image: url(:/images/unlock) 0 0 0 0 stretch stretch; width: 30px;");
573 }
574 
576 {
577  // Get Default Currency from Settings
578  bool fDisplayCurrencyValue = settings.value("fDisplayCurrencyValue").toBool();
579  QString defaultCurrency = settings.value("strDefaultCurrency").toString();
580 
581  // Don't check value if wallet is locked, balance is 0, or fDisplayCurrencyValue is set to false
582  if (pwalletMain->IsLocked() || currentBalance == 0 || !fDisplayCurrencyValue) {
583  ui->labelCurrencyValue->setText("");
584  return;
585  }
586  getHttpsJson("https://api.coingecko.com/api/v3/simple/price?ids=prcy-coin&vs_currencies=" + defaultCurrency.toStdString() + "&include_market_cap=false&include_24hr_vol=false&include_24hr_change=false&include_last_updated_at=false");
587 }
588 
590 {
591  // Get Default Currency from Settings
592  QString defaultCurrency = settings.value("strDefaultCurrency").toString();
593  QString defaultCurrencySymbol;
594 
595  // Set the Default Currency symbol to match
596  if (defaultCurrency == "USD" || defaultCurrency == "CAD") {
597  defaultCurrencySymbol = "$";
598  } else if (defaultCurrency == "EUR") {
599  defaultCurrencySymbol = "€";
600  } else if (defaultCurrency == "GBP") {
601  defaultCurrencySymbol = "£";
602  } else if (defaultCurrency == "BTC") {
603  defaultCurrencySymbol = "₿";
604  } else if (defaultCurrency == "ETH") {
605  defaultCurrencySymbol = "Ξ";
606  } else if (defaultCurrency == "XAU") {
607  defaultCurrencySymbol = "XAU";
608  } else if (defaultCurrency == "XAG") {
609  defaultCurrencySymbol = "XAG";
610  }
611 
612  if (downloadedJSON.failed == false && downloadedJSON.complete == true) {
613  try {
614  // Parse data
615  QJsonDocument jsonDocument(QJsonDocument::fromJson(downloadedJSON.response.c_str()));
616  const QJsonObject item = jsonDocument.object();
617  const QJsonObject currency = item["prcy-coin"].toObject();
618  auto currencyValue = currency[defaultCurrency.toLower()].toDouble();
619 
620  // Calculate value
621  double currentValue = (currentBalance / COIN) * currencyValue;
622 
623  // Set value
624  ui->labelCurrencyValue->setText(defaultCurrency + " Value: " + defaultCurrencySymbol + QString::number(currentValue, 'f', 2));
625  } catch (...) {
626  LogPrintf("%s: Error parsing CoinGecko API JSON\n", __func__);
627  }
628  }
629 }
OverviewPage::setSpendableBalance
void setSpendableBalance(bool isStaking)
Definition: overviewpage.cpp:235
OverviewPage::currentWatchImmatureBalance
CAmount currentWatchImmatureBalance
Definition: overviewpage.h:75
TxViewDelegate::TxViewDelegate
TxViewDelegate()
Definition: overviewpage.cpp:39
LOCK2
#define LOCK2(cs1, cs2)
Definition: sync.h:183
JsonDownload::response
std::string response
Definition: curl_json.h:24
OverviewPage::showBlockCurrentHeight
void showBlockCurrentHeight(int count)
Definition: overviewpage.cpp:360
WalletModel::getOptionsModel
OptionsModel * getOptionsModel()
Definition: walletmodel.cpp:358
OverviewPage::blockSyncCircle
QWidget * blockSyncCircle
Definition: overviewpage.h:82
vNodes
std::vector< CNode * > vNodes
Definition: net.cpp:85
transactiontablemodel.h
OverviewPage::OverviewPage
OverviewPage(QWidget *parent=0)
Definition: overviewpage.cpp:104
TxEntry::setData
void setData(int64_t Date, QString Address, QString Amount, QString ID, QString Type)
Definition: txentry.cpp:53
OverviewPage::updateGUItimer
QTimer * updateGUItimer
Definition: overviewpage.h:96
OverviewPage::showBalanceSync
void showBalanceSync(bool fShow)
Definition: overviewpage.cpp:323
OverviewPage::settings
QSettings settings
Definition: overviewpage.h:88
OverviewPage::isSyncingBlocks
bool isSyncingBlocks
Definition: overviewpage.h:84
CWallet::mapWallet
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:344
WalletModel::UnlockContext::isValid
bool isValid() const
Definition: walletmodel.h:195
getHttpsJson
void getHttpsJson(std::string url)
Definition: curl_json.cpp:18
CWallet::ReadStakingStatus
bool ReadStakingStatus()
Definition: wallet.cpp:370
OverviewPage::~OverviewPage
~OverviewPage()
Definition: overviewpage.cpp:154
TransactionTableModel::Date
@ Date
Definition: transactiontablemodel.h:32
OverviewPage::initSyncCircle
void initSyncCircle(float percentOfParent)
Definition: overviewpage.cpp:365
WalletModel
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:102
OverviewPage::showBlockSync
void showBlockSync(bool fShow)
Definition: overviewpage.cpp:339
BitcoinUnits::formatWithUnit
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with unit)
Definition: bitcoinunits.cpp:190
ICON_OFFSET
#define ICON_OFFSET
Definition: overviewpage.cpp:30
TxViewDelegate::unit
int unit
Definition: overviewpage.cpp:100
OverviewPage::on_lockUnlock
void on_lockUnlock()
Definition: overviewpage.cpp:538
walletmodel.h
OverviewPage::getPercentage
void getPercentage(CAmount nTotalBalance, QString &sPRCYPercentage)
Definition: overviewpage.cpp:161
DECORATION_SIZE
#define DECORATION_SIZE
Definition: overviewpage.cpp:29
OverviewPage::updateAlerts
void updateAlerts(const QString &warnings)
Definition: overviewpage.cpp:317
TransactionTableModel::WatchonlyRole
@ WatchonlyRole
Watch-only boolean.
Definition: transactiontablemodel.h:48
OverviewPage::ui
Ui::OverviewPage * ui
Definition: overviewpage.h:66
CNode
Information about a peer.
Definition: net.h:306
CWallet::GetSpendableBalance
CAmount GetSpendableBalance()
Definition: wallet.cpp:2260
OverviewPage
Overview ("home") page widget.
Definition: overviewpage.h:33
OverviewPage::filter
TransactionFilterProxy * filter
Definition: overviewpage.h:80
CWalletTx::GetComputedTxTime
int64_t GetComputedTxTime() const
Definition: wallet.cpp:1439
COLOR_BLACK
#define COLOR_BLACK
Definition: guiconstants.h:36
OverviewPage::balanceSyncCircle
QWidget * balanceSyncCircle
Definition: overviewpage.h:85
WalletModel::getTransactionTableModel
TransactionTableModel * getTransactionTableModel()
Definition: walletmodel.cpp:368
OverviewPage::updateBalance
void updateBalance()
Definition: overviewpage.cpp:291
OverviewPage::txdelegate
TxViewDelegate * txdelegate
Definition: overviewpage.h:79
cs_vNodes
RecursiveMutex cs_vNodes
Definition: net.cpp:86
WalletUtil::getTx
std::map< QString, QString > getTx(CWallet *wallet, uint256 hash)
Definition: walletmodel.cpp:752
TRY_LOCK
#define TRY_LOCK(cs, name)
Definition: sync.h:186
TransactionFilterProxy::setHideOrphans
void setHideOrphans(bool fHide)
Set whether to hide orphan stakes.
Definition: transactionfilterproxy.cpp:71
JsonDownload::complete
bool complete
Definition: curl_json.h:26
ClientModel::getStatusBarWarnings
QString getStatusBarWarnings() const
Return warnings to be displayed in status bar.
Definition: clientmodel.cpp:193
COLOR_NEGATIVE
#define COLOR_NEGATIVE
Definition: guiconstants.h:28
OverviewPage::currentWatchUnconfBalance
CAmount currentWatchUnconfBalance
Definition: overviewpage.h:74
overviewpage.h
curl_json.h
OverviewPage::isSyncingBalance
bool isSyncingBalance
Definition: overviewpage.h:87
OptionsModel::getDisplayUnit
int getDisplayUnit()
Definition: optionsmodel.h:60
TransactionFilterProxy::setShowInactive
void setShowInactive(bool showInactive)
Set whether to show conflicted transactions.
Definition: transactionfilterproxy.cpp:106
OverviewPage::walletModel
WalletModel * walletModel
Definition: overviewpage.h:68
OverviewPage::manager
QNetworkAccessManager * manager
Definition: overviewpage.h:97
cs_main
RecursiveMutex cs_main
Global state.
Definition: main.cpp:65
TxViewDelegate
Definition: overviewpage.cpp:35
TransactionTableModel::AmountRole
@ AmountRole
Net amount of transaction.
Definition: transactiontablemodel.h:58
OverviewPage::blockAnimSyncCircle
QWidget * blockAnimSyncCircle
Definition: overviewpage.h:83
TxViewDelegate::sizeHint
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: overviewpage.cpp:95
OverviewPage::updateRecentTransactions
void updateRecentTransactions()
Definition: overviewpage.cpp:462
OverviewPage::pingNetworkInterval
QTimer * pingNetworkInterval
Definition: overviewpage.h:65
nReserveBalance
int64_t nReserveBalance
Definition: wallet.cpp:59
OverviewPage::updateJSONtimer
QTimer * updateJSONtimer
Definition: overviewpage.h:95
init.h
OverviewPage::getCircleGeometry
QRect getCircleGeometry(QWidget *parent, float ratioToParent)
Definition: overviewpage.cpp:429
OverviewPage::currentBalance
CAmount currentBalance
Definition: overviewpage.h:70
OverviewPage::updateWatchOnlyLabels
void updateWatchOnlyLabels(bool showWatchOnly)
Definition: overviewpage.cpp:217
OverviewPage::balanceAnimSyncCircle
QWidget * balanceAnimSyncCircle
Definition: overviewpage.h:86
OverviewPage::setClientModel
void setClientModel(ClientModel *clientModel)
Definition: overviewpage.cpp:223
transactionfilterproxy.h
AskPassphraseDialog::Context::Unlock_Full
@ Unlock_Full
Unlock wallet from menu
WalletModel::getEncryptionStatus
EncryptionStatus getEncryptionStatus() const
Definition: walletmodel.cpp:373
TxViewDelegate::paint
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: overviewpage.cpp:43
OverviewPage::currentUnconfirmedBalance
CAmount currentUnconfirmedBalance
Definition: overviewpage.h:71
BitcoinUnits
PRCY unit definitions.
Definition: bitcoinunits.h:50
WalletModel::getWatchImmatureBalance
CAmount getWatchImmatureBalance() const
Definition: walletmodel.cpp:124
LogPrintf
#define LogPrintf(...)
Definition: logging.h:147
CAmount
int64_t CAmount
Amount in PRCY (Can be negative)
Definition: amount.h:17
TransactionFilterProxy::setLimit
void setLimit(int limit)
Set maximum number of rows returned, -1 if unlimited.
Definition: transactionfilterproxy.cpp:101
downloadedJSON
JsonDownload downloadedJSON
Definition: curl_json.cpp:10
guiutil.h
OverviewPage::animClock
QElapsedTimer * animClock
Definition: overviewpage.h:47
TxEntry
Definition: txentry.h:19
OverviewPage::reply
QNetworkReply * reply
Definition: overviewpage.h:98
WalletModel::getSpendableBalance
CAmount getSpendableBalance() const
Definition: walletmodel.cpp:94
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
base_uint::SetHex
void SetHex(const char *psz)
Definition: arith_uint256.cpp:164
OverviewPage::hideOrphans
void hideOrphans(bool fHide)
Definition: overviewpage.cpp:311
WalletModel::Locked
@ Locked
Definition: walletmodel.h:126
OverviewPage::animTicker
QTimer * animTicker
Definition: overviewpage.h:46
OverviewPage::updateDisplayUnit
void updateDisplayUnit()
Definition: overviewpage.cpp:298
OverviewPage::clientModel
ClientModel * clientModel
Definition: overviewpage.h:67
OverviewPage::getCurrencyValue
void getCurrencyValue()
Definition: overviewpage.cpp:575
txentry.h
OverviewPage::transactionClicked
void transactionClicked(const QModelIndex &index)
nLastCoinStakeSearchInterval
int64_t nLastCoinStakeSearchInterval
Definition: miner.cpp:67
OverviewPage::updateTotalBlocksLabel
void updateTotalBlocksLabel()
Definition: overviewpage.cpp:438
ClientModel
Model for PRCY network client.
Definition: clientmodel.h:44
Ui
Definition: 2faconfirmdialog.h:7
OverviewPage::updateLockStatus
void updateLockStatus(int status)
Definition: overviewpage.cpp:564
guiconstants.h
WalletModel::UnlockContext
Definition: walletmodel.h:189
ON
@ ON
Definition: wallet.h:236
BitcoinUnits::separatorAlways
@ separatorAlways
Definition: bitcoinunits.h:69
ClientModel::getNumBlocks
int getNumBlocks()
Definition: clientmodel.cpp:84
LOCK
#define LOCK(cs)
Definition: sync.h:182
OverviewPage::moveSyncCircle
void moveSyncCircle(QWidget *anchor, QWidget *animated, int deltaRadius, float degreesPerSecond, float angleOffset=0)
Definition: overviewpage.cpp:417
TransactionTableModel::WatchonlyDecorationRole
@ WatchonlyDecorationRole
Watch-only icon.
Definition: transactiontablemodel.h:50
CWallet
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
Definition: wallet.h:243
OverviewPage::tryNetworkBlockCount
int tryNetworkBlockCount()
Definition: overviewpage.cpp:442
CWalletTx
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:792
OverviewPage::nDisplayUnit
int nDisplayUnit
Definition: overviewpage.h:76
OverviewPage::onAnimTick
void onAnimTick()
Definition: overviewpage.cpp:395
OverviewPage::currentWatchOnlyBalance
CAmount currentWatchOnlyBalance
Definition: overviewpage.h:73
OverviewPage::handleTransactionClicked
void handleTransactionClicked(const QModelIndex &index)
Definition: overviewpage.cpp:148
bitcoinunits.h
WalletModel::setWalletLocked
bool setWalletLocked(bool locked, const SecureString &passPhrase=SecureString(), bool stakingOnly=false)
Definition: walletmodel.cpp:397
CWallet::cs_wallet
RecursiveMutex cs_wallet
Definition: wallet.h:301
WalletModel::getWatchBalance
CAmount getWatchBalance() const
Definition: walletmodel.cpp:114
OverviewPage::setCurrencyValue
void setCurrencyValue()
Definition: overviewpage.cpp:589
OverviewPage::setWalletModel
void setWalletModel(WalletModel *walletModel)
Definition: overviewpage.cpp:252
BitcoinUnits::formatHtmlWithUnit
static QString formatHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Definition: bitcoinunits.cpp:195
CWallet::combineMode
CombineMode combineMode
Definition: wallet.h:365
OverviewPage::setBalance
void setBalance(const CAmount &balance, const CAmount &unconfirmedBalance, const CAmount &immatureBalance, const CAmount &watchOnlyBalance, const CAmount &watchUnconfBalance, const CAmount &watchImmatureBalance)
Definition: overviewpage.cpp:169
GUIUtil::dateTimeStr
QString dateTimeStr(const QDateTime &date)
Definition: guiutil.cpp:70
TransactionTableModel::DateRole
@ DateRole
Date and time this transaction was created.
Definition: transactiontablemodel.h:46
WalletModel::UnlockedForStakingOnly
@ UnlockedForStakingOnly
Definition: walletmodel.h:128
JsonDownload::failed
bool failed
Definition: curl_json.h:25
WalletModel::getWatchUnconfirmedBalance
CAmount getWatchUnconfirmedBalance() const
Definition: walletmodel.cpp:119
BitcoinUnits::floorHtmlWithUnit
static QString floorHtmlWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Definition: bitcoinunits.cpp:213
WalletModel::haveWatchOnly
bool haveWatchOnly() const
Definition: walletmodel.cpp:109
optionsmodel.h
OverviewPage::currentImmatureBalance
CAmount currentImmatureBalance
Definition: overviewpage.h:72
WalletModel::getUnconfirmedBalance
CAmount getUnconfirmedBalance() const
Definition: walletmodel.cpp:89
pwalletMain
CWallet * pwalletMain
Definition: wallet.cpp:49
WalletModel::getImmatureBalance
CAmount getImmatureBalance() const
Definition: walletmodel.cpp:99
WalletModel::requestUnlock
UnlockContext requestUnlock(AskPassphraseDialog::Context context, bool relock=false)
Definition: walletmodel.cpp:546
NUM_ITEMS
#define NUM_ITEMS
Definition: overviewpage.cpp:31
WalletModel::getBalance
CAmount getBalance(const CCoinControl *coinControl=NULL) const
Definition: walletmodel.cpp:77
clientmodel.h
CCryptoKeyStore::IsLocked
bool IsLocked() const
Definition: crypter.h:159
OverviewPage::networkBlockCount
int networkBlockCount
Definition: overviewpage.h:69
TransactionTableModel::ConfirmedRole
@ ConfirmedRole
Is transaction confirmed?
Definition: transactiontablemodel.h:64
TransactionFilterProxy
Filter the transaction list according to pre-specified rules.
Definition: transactionfilterproxy.h:14