Compare commits

...

12 Commits
master ... dev

  1. 2
      README.md
  2. 1
      silentdragon.pro
  3. 1
      silentdragonx.pro
  4. 17
      src/connection.cpp
  5. 35
      src/mainwindow.cpp
  6. 5
      src/mainwindow.h
  7. 268
      src/mainwindow.ui
  8. 257
      src/rpc.cpp
  9. 1
      src/rpc.h
  10. 21
      src/settings.cpp

2
README.md

@ -84,7 +84,7 @@ sudo apt-get -y install libglu1-mesa-dev freeglut3-dev mesa-common-dev
You can install the pre-reqs and build on Ubuntu 18.04 & 20.04 with: You can install the pre-reqs and build on Ubuntu 18.04 & 20.04 with:
```shell script ```shell script
sudo apt-get -y install qt5-default qt5-qmake qtcreator sudo apt-get -y install qt5-default qt5-qmake qtcreator libqt5charts5-dev
git clone https://git.hush.is/hush/SilentDragon git clone https://git.hush.is/hush/SilentDragon
cd SilentDragon cd SilentDragon
./build.sh linguist ./build.sh linguist

1
silentdragon.pro

@ -9,6 +9,7 @@ CONFIG += precompile_header
PRECOMPILED_HEADER = src/precompiled.h PRECOMPILED_HEADER = src/precompiled.h
QT += widgets QT += widgets
QT += charts
TARGET = silentdragon TARGET = silentdragon

1
silentdragonx.pro

@ -8,6 +8,7 @@ CONFIG += precompile_header
PRECOMPILED_HEADER = src/precompiled.h PRECOMPILED_HEADER = src/precompiled.h
QT += widgets QT += widgets
QT += charts
TARGET = silentdragonx TARGET = silentdragonx

17
src/connection.cpp

@ -378,11 +378,24 @@ bool ConnectionLoader::startEmbeddedHushd() {
// Static because it needs to survive even after this method returns. // Static because it needs to survive even after this method returns.
static QString processStdErrOutput; static QString processStdErrOutput;
// Try to get only the error message
auto friendlyError = processStdErrOutput.split("Error: ");
if (ehushd != nullptr) { if (ehushd != nullptr) {
if (ehushd->state() == QProcess::NotRunning) { if (ehushd->state() == QProcess::NotRunning) {
if (!processStdErrOutput.isEmpty()) { if (!processStdErrOutput.isEmpty()) {
QMessageBox::critical(main, QObject::tr("hushd error"), "hushd said: " + processStdErrOutput, QMessageBox msgBox;
QMessageBox::Ok); msgBox.setIcon(QMessageBox::Critical);
msgBox.setText(friendlyError.last());
msgBox.setDetailedText(processStdErrOutput);
//Add styles and width hack
msgBox.setStyleSheet("background-color:rgb(48, 51, 53);color:rgb(255, 255, 255)");
QSpacerItem* horizontalSpacer = new QSpacerItem(512, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
QGridLayout* layout = (QGridLayout*)msgBox.layout();
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
msgBox.exec();
} }
return false; return false;
} else { } else {

35
src/mainwindow.cpp

@ -25,6 +25,7 @@
#include "requestdialog.h" #include "requestdialog.h"
#include <QLCDNumber> #include <QLCDNumber>
#include <QThread> #include <QThread>
#include <QtCharts>
#include "sd.h" #include "sd.h"
extern bool isdragonx; extern bool isdragonx;
@ -1201,12 +1202,13 @@ void MainWindow::payHushURI(QString uri, QString myAddr) {
// If there was no URI passed, ask the user for one. // If there was no URI passed, ask the user for one.
if (uri.isEmpty()) { if (uri.isEmpty()) {
uri = QInputDialog::getText(this, tr("Paste HUSH URI"),
"HUSH URI" + QString(" ").repeated(180));
if(isdragonx) { if(isdragonx) {
uri = QInputDialog::getText(this, tr("Paste DRGX URI"), uri = QInputDialog::getText(this, tr("Paste DRGX URI"),
"DRGX URI" + QString(" ").repeated(180)); "DRGX URI" + QString(" ").repeated(180));
} } else{
uri = QInputDialog::getText(this, tr("Paste HUSH URI"),
"HUSH URI" + QString(" ").repeated(180));
}
} }
// If there's no URI, just exit // If there's no URI, just exit
@ -2244,9 +2246,29 @@ void MainWindow::setupMarketTab() {
auto s = Settings::getInstance(); auto s = Settings::getInstance();
auto ticker = s->get_currency_name(); auto ticker = s->get_currency_name();
// Hide note to allow fetch prices if already enabled and hide empty chart/data if not enabled
if (s->getAllowFetchPrices() == true) {
ui->marketNote->setHidden(true);
} else {
ui->marketChart->setHidden(true);
ui->volume->setHidden(true);
ui->volumeLabel->setHidden(true);
ui->volumeBTC->setHidden(true);
ui->volumeLocal->setHidden(true);
ui->marketcap->setHidden(true);
ui->marketcapLabel->setHidden(true);
ui->marketcapBTC->setHidden(true);
ui->marketcapLocal->setHidden(true);
ui->chartType->setHidden(true);
}
ui->volume->setText(QString::number((double) s->get_volume("HUSH") ,'f',8) + " HUSH"); ui->volume->setText(QString::number((double) s->get_volume("HUSH") ,'f',8) + " HUSH");
ui->volumeLocal->setText(QString::number((double) s->get_volume(ticker) ,'f',8) + " " + ticker); ui->volumeLocal->setText(QString::number((double) s->get_volume(ticker) ,'f',8) + " " + ticker);
ui->volumeBTC->setText(QString::number((double) s->get_volume("BTC") ,'f',8) + " BTC"); ui->volumeBTC->setText(QString::number((double) s->get_volume("BTC") ,'f',8) + " BTC");
ui->chartType->addItem("Price");
ui->chartType->addItem("Volume");
//ui->chartType->addItem("Marketcap");
} }
void MainWindow::setupTransactionsTab() { void MainWindow::setupTransactionsTab() {
@ -2848,3 +2870,10 @@ MainWindow::~MainWindow()
delete logger; delete logger;
} }
void MainWindow::on_chartType_currentTextChanged(const QString &chartType)
{
qDebug() << "chartType = " << chartType;
rpc->getMarketChart(chartType);
}

5
src/mainwindow.h

@ -81,7 +81,10 @@ protected slots:
// this slot is called by the language menu actions // this slot is called by the language menu actions
void slotLanguageChanged(QString lang); void slotLanguageChanged(QString lang);
private: private slots:
void on_chartType_currentTextChanged(const QString &chartType);
private:
void closeEvent(QCloseEvent* event); void closeEvent(QCloseEvent* event);

268
src/mainwindow.ui

@ -22,7 +22,7 @@
<item row="0" column="0"> <item row="0" column="0">
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>5</number>
</property> </property>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">
<attribute name="title"> <attribute name="title">
@ -388,8 +388,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1447</width> <width>1439</width>
<height>860</height> <height>899</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="sendToLayout"> <layout class="QVBoxLayout" name="sendToLayout">
@ -1053,145 +1053,231 @@
<string>Market</string> <string>Market</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_5"> <layout class="QGridLayout" name="gridLayout_5">
<item row="11" column="0" colspan="3"> <item row="3" column="3">
<widget class="QLabel" name="label_24"> <widget class="QLabel" name="marketcapBTC">
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text"> <property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;center&quot;&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Market Information&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>Loading...</string>
</property>
</widget>
</item>
<item row="12" column="0" colspan="3">
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item row="13" column="0"> <item row="3" column="0">
<widget class="QLabel" name="label_31"> <widget class="QLabel" name="marketcapLabel">
<property name="text"> <property name="text">
<string>Market Cap</string> <string>Market Cap</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="13" column="1"> <item row="4" column="2">
<widget class="QLabel" name="marketcap"> <widget class="QLabel" name="volumeLocal">
<property name="text"> <property name="text">
<string>Loading...</string> <string>Loading...</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="13" column="2"> <item row="3" column="2">
<widget class="QLabel" name="marketcapLocal"> <widget class="QLabel" name="marketcapLocal">
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item row="13" column="3"> <item row="3" column="1">
<widget class="QLabel" name="marketcapBTC"> <widget class="QLabel" name="marketcap">
<property name="text">
<string>Loading...</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="volume">
<property name="text"> <property name="text">
<string>Loading...</string> <string>Loading...</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="14" column="0"> <item row="2" column="0" colspan="4">
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="volumeLabel"> <widget class="QLabel" name="volumeLabel">
<property name="text"> <property name="text">
<string>24H Volume</string> <string>24H Volume</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="14" column="1"> <item row="4" column="3">
<widget class="QLabel" name="volume"> <widget class="QLabel" name="volumeBTC">
<property name="text"> <property name="text">
<string>Loading...</string> <string>Loading...</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="14" column="2"> <item row="1" column="0" colspan="4">
<widget class="QLabel" name="volumeLocal"> <widget class="QChartView" name="marketChart">
<property name="text"> <property name="enabled">
<string>Loading...</string> <bool>true</bool>
</property>
<property name="toolTip">
<string/>
</property>
<property name="toolTipDuration">
<number>5</number>
</property>
<property name="whatsThis">
<string/>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="interactive">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item row="14" column="3"> <item row="0" column="3">
<widget class="QLabel" name="volumeBTC"> <widget class="QComboBox" name="chartType">
<property name="palette">
<palette>
<active>
<colorrole role="PlaceholderText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>192</red>
<green>191</green>
<blue>188</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="PlaceholderText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>192</red>
<green>191</green>
<blue>188</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="PlaceholderText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>192</red>
<green>191</green>
<blue>188</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="currentText">
<string/>
</property>
<property name="placeholderText">
<string>Select chart to display</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLabel" name="marketNote">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text"> <property name="text">
<string>Loading...</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Note: &lt;span style=&quot; font-weight:400;&quot;&gt;Please allow &amp;quot;Connect to the internet to fetch prices&amp;quot; under Edit &amp;gt; Settings &amp;gt; Options &lt;/span&gt;(Ctrl+P)&lt;span style=&quot; font-weight:400;&quot;&gt; to see market data and restart the app.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:400;&quot;&gt;Fetching prices and market data is disabled by default for &lt;/span&gt;Extreme Privacy!&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<property name="margin">
<number>30</number>
</property>
<property name="openExternalLinks">
<bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_debug"> <widget class="QWidget" name="tab_debug">
<attribute name="title"> <attribute name="title">
<string>Debug Log</string> <string>Debug Log</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout"> <item row="0" column="0">
<widget class="QPushButton" name="refreshDebugButton">
<item row="0" column="0"> <property name="enabled">
<widget class="QPushButton" name="refreshDebugButton"> <bool>true</bool>
<property name="enabled"> </property>
<bool>true</bool> <property name="sizePolicy">
</property> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<property name="sizePolicy"> <horstretch>0</horstretch>
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <verstretch>0</verstretch>
<horstretch>0</horstretch> </sizepolicy>
<verstretch>0</verstretch> </property>
</sizepolicy> <property name="minimumSize">
</property> <size>
<property name="minimumSize"> <width>0</width>
<size> <height>0</height>
<width>0</width> </size>
<height>0</height> </property>
</size> <property name="toolTip">
</property> <string/>
<property name="toolTip"> </property>
Click to see the latest debug log data <property name="text">
<string/> <string>Refresh</string>
</property> </property>
<property name="text"> </widget>
<string>Refresh</string> </item>
</property>
</widget>
</item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLabel" name="debugLabel"> <widget class="QLabel" name="debugLabel">
<property name="text"> <property name="text">
<string>Number of lines to show</string> <string>Number of lines to show</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item row="0" column="2">
<widget class="QLineEdit" name="debugLines"> <widget class="QLineEdit" name="debugLines">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="placeholderText"> <property name="placeholderText">
<string>50</string> <string>50</string>
</property> </property>
</widget> </widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="QPlainTextEdit" name="debugLog">
<property name="plainText">
<string/>
</property>
</widget>
</item> </item>
<item row="1" column="0" colspan="4">
<widget class="QPlainTextEdit" name="debugLog">
<property name="plainText">
<string/>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_5"> <widget class="QWidget" name="tab_5">
<attribute name="title"> <attribute name="title">
<string>Node info</string> <string>Node info</string>
@ -1664,14 +1750,13 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QMenuBar" name="menuBar"> <widget class="QMenuBar" name="menuBar">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1487</width> <width>1487</width>
<height>30</height> <height>22</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">
@ -1838,6 +1923,11 @@
<extends>QLabel</extends> <extends>QLabel</extends>
<header>qrcodelabel.h</header> <header>qrcodelabel.h</header>
</customwidget> </customwidget>
<customwidget>
<class>QChartView</class>
<extends>QGraphicsView</extends>
<header location="global">QtCharts</header>
</customwidget>
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>inputsCombo</tabstop> <tabstop>inputsCombo</tabstop>

257
src/rpc.cpp

@ -1573,8 +1573,16 @@ void RPC::refreshPrice() {
if (conn == nullptr) if (conn == nullptr)
return noConnection(); return noConnection();
QString price_feed;
QString history_feed;
// TODO: Make feeds dynamic to support HACs
if (isdragonx) { if (isdragonx) {
return; price_feed = "https://api.coingecko.com/api/v3/simple/price?ids=dragonx-2&vs_currencies=btc%2Cusd%2Ceur%2Ceth%2Cgbp%2Ccny%2Cjpy%2Cidr%2Crub%2Ccad%2Csgd%2Cchf%2Cinr%2Caud%2Cinr%2Ckrw%2Cthb%2Cnzd%2Czar%2Cvef%2Cxau%2Cxag%2Cvnd%2Csar%2Ctwd%2Caed%2Cars%2Cbdt%2Cbhd%2Cbmd%2Cbrl%2Cclp%2Cczk%2Cdkk%2Chuf%2Cils%2Ckwd%2Clkr%2Cpkr%2Cnok%2Ctry%2Csek%2Cmxn%2Cuah%2Chkd&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true";
history_feed = "https://api.coingecko.com/api/v3/coins/dragonx-2/market_chart?vs_currency=usd&days=90&precision=full";
} else {
price_feed = "https://api.coingecko.com/api/v3/simple/price?ids=hush&vs_currencies=btc%2Cusd%2Ceur%2Ceth%2Cgbp%2Ccny%2Cjpy%2Cidr%2Crub%2Ccad%2Csgd%2Cchf%2Cinr%2Caud%2Cinr%2Ckrw%2Cthb%2Cnzd%2Czar%2Cvef%2Cxau%2Cxag%2Cvnd%2Csar%2Ctwd%2Caed%2Cars%2Cbdt%2Cbhd%2Cbmd%2Cbrl%2Cclp%2Cczk%2Cdkk%2Chuf%2Cils%2Ckwd%2Clkr%2Cpkr%2Cnok%2Ctry%2Csek%2Cmxn%2Cuah%2Chkd&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true";
history_feed = "https://api.coingecko.com/api/v3/coins/hush/market_chart?vs_currency=usd&days=90&precision=full";
} }
auto s = Settings::getInstance(); auto s = Settings::getInstance();
@ -1584,7 +1592,6 @@ void RPC::refreshPrice() {
return; return;
} }
QString price_feed = "https://api.coingecko.com/api/v3/simple/price?ids=hush&vs_currencies=btc%2Cusd%2Ceur%2Ceth%2Cgbp%2Ccny%2Cjpy%2Cidr%2Crub%2Ccad%2Csgd%2Cchf%2Cinr%2Caud%2Cinr%2Ckrw%2Cthb%2Cnzd%2Czar%2Cvef%2Cxau%2Cxag%2Cvnd%2Csar%2Ctwd%2Caed%2Cars%2Cbdt%2Cbhd%2Cbmd%2Cbrl%2Cclp%2Cczk%2Cdkk%2Chuf%2Cils%2Ckwd%2Clkr%2Cpkr%2Cnok%2Ctry%2Csek%2Cmxn%2Cuah%2Chkd&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true";
qDebug() << "Requesting price feed data via " << price_feed; qDebug() << "Requesting price feed data via " << price_feed;
QUrl cmcURL(price_feed); QUrl cmcURL(price_feed);
@ -1632,7 +1639,16 @@ void RPC::refreshPrice() {
qDebug() << "Parsed JSON"; qDebug() << "Parsed JSON";
const QJsonValue& item = parsed; const QJsonValue& item = parsed;
const QJsonValue& hush = item["hush"].toObject();
// TODO: Rename hush to be more universal for HACs and avoid confusion
QJsonValue hush;
if (isdragonx) {
hush = item["dragonx-2"].toObject();
} else {
hush = item["hush"].toObject();
}
QString ticker = s->get_currency_name(); QString ticker = s->get_currency_name();
ticker = ticker.toLower(); ticker = ticker.toLower();
fprintf(stderr,"ticker=%s\n", ticker.toLocal8Bit().data()); fprintf(stderr,"ticker=%s\n", ticker.toLocal8Bit().data());
@ -1666,17 +1682,24 @@ void RPC::refreshPrice() {
qDebug() << "Volume = " << (double) vol; qDebug() << "Volume = " << (double) vol;
ticker = ticker.toUpper(); ticker = ticker.toUpper();
ui->volume->setText( QString::number((double) vol, 'f', 2) + " " + ticker ); ui->volume->setText( QString::number((double) vol, 'f', 8) + " " + ticker );
ui->volumeBTC->setText( QString::number((double) btcvol, 'f', 2) + " BTC" ); ui->volumeBTC->setText( QString::number((double) btcvol, 'f', 8) + " BTC" );
ticker = ticker.toUpper(); ticker = ticker.toUpper();
// We don't get an actual HUSH volume stat, so we calculate it // We don't get an actual HUSH volume stat, so we calculate it
if (price > 0) if (price > 0) {
ui->volumeLocal->setText( QString::number((double) vol / (double) price) + " HUSH");
// TODO: Make dynamic to support HACs
if (isdragonx) {
ui->volumeLocal->setText( QString::number((double) vol / (double) price) + " DRGX");
} else {
ui->volumeLocal->setText( QString::number((double) vol / (double) price) + " HUSH");
}
}
qDebug() << "Mcap = " << (double) mcap; qDebug() << "Mcap = " << (double) mcap;
ui->marketcap->setText( QString::number( (double) mcap, 'f', 2) + " " + ticker ); ui->marketcap->setText( QString::number( (double) mcap, 'f', 8) + " " + ticker );
ui->marketcapBTC->setText( QString::number((double) btcmcap, 'f', 2) + " BTC" ); ui->marketcapBTC->setText( QString::number((double) btcmcap, 'f', 8) + " BTC" );
//ui->marketcapLocal->setText( QString::number((double) mcap * (double) price) + " " + ticker ); //ui->marketcapLocal->setText( QString::number((double) mcap * (double) price) + " " + ticker );
refresh(true); refresh(true);
@ -1693,6 +1716,222 @@ void RPC::refreshPrice() {
Settings::getInstance()->setHUSHPrice(0); Settings::getInstance()->setHUSHPrice(0);
Settings::getInstance()->setBTCPrice(0); Settings::getInstance()->setBTCPrice(0);
}); });
getMarketChart("Price");
}
// Get price history chart
void RPC::getMarketChart(QString chartType) {
if (conn == nullptr)
return noConnection();
QString history_feed;
// TODO: Make feeds dynamic to support HACs
if (isdragonx) {
history_feed = "https://api.coingecko.com/api/v3/coins/dragonx-2/market_chart?vs_currency=usd&days=7";
} else {
history_feed = "https://api.coingecko.com/api/v3/coins/hush/market_chart?vs_currency=usd&days=7";
}
auto s = Settings::getInstance();
if (s->getAllowFetchPrices() == false) {
qDebug() << "Price fetching disabled";
return;
}
qDebug() << "Requesting history feed data via " << history_feed;
QUrl histURL(history_feed);
QNetworkRequest req;
req.setUrl(histURL);
QNetworkReply *reply = conn->restclient->get(req);
QObject::connect(reply, &QNetworkReply::finished, [=] {
reply->deleteLater();
try {
QByteArray ba_raw_reply = reply->readAll();
QString raw_reply = QString::fromUtf8(ba_raw_reply);
QByteArray unescaped_raw_reply = raw_reply.toUtf8();
QJsonDocument jd_reply = QJsonDocument::fromJson(unescaped_raw_reply);
QJsonObject parsed = jd_reply.object();
QJsonArray prices = parsed["prices"].toArray();
QJsonArray volumes = parsed["total_volumes"].toArray();
QJsonArray mcaps = parsed["market_caps"].toArray();
if (prices.size()>0 && volumes.size()>0) {
// Create Price Series
QLineSeries *priceSeries = new QLineSeries();
// Loop through price data and add to series
for (int i = 0; i < prices.size(); i++){
// QJson doesn't support long ints so we convert - https://bugreports.qt.io/browse/QTBUG-28560
quint64 timestamp = QString("%1").arg(prices.at(i).toArray().at(0).toDouble(),0,'f',0).toLongLong();
auto price = prices.at(i).toArray().at(1).toDouble();
qDebug() << "Epoch = " << timestamp;
qDebug() << "Price = " << price;
priceSeries->append(timestamp, price);
}
// Set color of price series
priceSeries->setColor(Qt::green);
// Create Price chart
QChart *priceChart = new QChart();
priceChart->setTitleBrush(QBrush(Qt::darkGray));
priceChart->addSeries(priceSeries);
priceChart->setTitle("Price History");
priceChart->setBackgroundVisible(false);
priceChart->legend()->hide();
auto priceaxisX = new QDateTimeAxis;
priceaxisX->setTickCount(7);
priceaxisX->setFormat("yyyy-MM-dd");
priceaxisX->setLabelsColor(Qt::lightGray);
priceaxisX->setGridLineColor(Qt::darkGray);
priceaxisX->setTitleText("Date");
priceChart->addAxis(priceaxisX, Qt::AlignBottom);
priceSeries->attachAxis(priceaxisX);
auto priceaxisY = new QValueAxis;
priceaxisY->setTickCount(10);
priceaxisY->setLabelsColor(Qt::lightGray);
priceaxisY->setGridLineColor(Qt::darkGray);
priceaxisY->setTitleText("USD Price");
priceChart->addAxis(priceaxisY, Qt::AlignLeft);
priceSeries->attachAxis(priceaxisY);
// Create Volume Series
QLineSeries *volumeSeries = new QLineSeries();
// Loop through price data and add to series
for (int i = 0; i < volumes.size(); i++){
// QJson doesn't support long ints so we convert - https://bugreports.qt.io/browse/QTBUG-28560
quint64 timestamp = QString("%1").arg(volumes.at(i).toArray().at(0).toDouble(),0,'f',0).toLongLong();
auto volume = volumes.at(i).toArray().at(1).toDouble();
qDebug() << "Epoch = " << timestamp;
qDebug() << "Volume = " << volume;
volumeSeries->append(timestamp, volume);
}
// Set color of Volume series
volumeSeries->setColor(Qt::green);
// Create Volume chart
QChart *volumeChart = new QChart();
volumeChart->setTitleBrush(QBrush(Qt::darkGray));
volumeChart->addSeries(volumeSeries);
volumeChart->setTitle("Volume History");
volumeChart->setBackgroundVisible(false);
volumeChart->legend()->hide();
auto volumeaxisX = new QDateTimeAxis;
volumeaxisX->setTickCount(7);
volumeaxisX->setFormat("yyyy-MM-dd");
volumeaxisX->setLabelsColor(Qt::lightGray);
volumeaxisX->setGridLineColor(Qt::darkGray);
volumeaxisX->setTitleText("Date");
volumeChart->addAxis(volumeaxisX, Qt::AlignBottom);
volumeSeries->attachAxis(volumeaxisX);
auto volumeaxisY = new QValueAxis;
volumeaxisY->setTickCount(10);
volumeaxisY->setLabelsColor(Qt::lightGray);
volumeaxisY->setGridLineColor(Qt::darkGray);
volumeaxisY->setTitleText("DRGX");
volumeChart->addAxis(volumeaxisY, Qt::AlignLeft);
volumeSeries->attachAxis(volumeaxisY);
// Create Market Cap Series
/*
QLineSeries *mcapSeries = new QLineSeries();
// Loop through price data and add to series
for (int i = 0; i < mcaps.size(); i++){
// QJson doesn't support long ints so we convert - https://bugreports.qt.io/browse/QTBUG-28560
quint64 timestamp = QString("%1").arg(mcaps.at(i).toArray().at(0).toDouble(),0,'f',0).toLongLong();
auto mcap = mcaps.at(i).toArray().at(1).toDouble();
qDebug() << "Epoch = " << timestamp;
qDebug() << "Mcap = " << mcap;
mcapSeries->append(timestamp, mcap);
}
// Set color of Market Cap series
mcapSeries->setColor(Qt::green);
// Create Market Cap chart
QChart *mcapChart = new QChart();
mcapChart->setTitleBrush(QBrush(Qt::darkGray));
mcapChart->addSeries(mcapSeries);
mcapChart->setTitle("Market Cap History");
mcapChart->setBackgroundVisible(false);
mcapChart->legend()->hide();
auto mcapaxisX = new QDateTimeAxis;
mcapaxisX->setTickCount(7);
mcapaxisX->setFormat("yyyy-MM-dd");
mcapaxisX->setLabelsColor(Qt::lightGray);
mcapaxisX->setGridLineColor(Qt::darkGray);
mcapaxisX->setTitleText("Date");
mcapChart->addAxis(mcapaxisX, Qt::AlignBottom);
mcapSeries->attachAxis(mcapaxisX);
auto mcapaxisY = new QValueAxis;
mcapaxisY->setTickCount(10);
mcapaxisY->setLabelsColor(Qt::lightGray);
mcapaxisY->setGridLineColor(Qt::darkGray);
mcapaxisY->setTitleText("DRGX");
mcapChart->addAxis(mcapaxisY, Qt::AlignLeft);
mcapSeries->attachAxis(mcapaxisY);
*/
// Add chart to UI
qDebug() << "chartType = " << chartType;
if(chartType=="Price") {
ui->marketChart->setChart(priceChart);
} else if(chartType=="Volume") {
ui->marketChart->setChart(volumeChart);
/*} else if(chartType=="Marketcap") {
ui->marketChart->setChart(mcapChart);*/
} else{
ui->marketChart->setChart(priceChart);
}
// Set anti-aliasing
ui->marketChart->setRenderHint(QPainter::Antialiasing, true);
return;
} else {
qDebug() << "No market_chart history returned. API might be down or we are rate-limited";
QMessageBox msgBox;
msgBox.setText("No market data returned. API is down or rate limited. Try again after a minute.");
msgBox.exec();
}
} catch (const std::exception& e) {
qDebug() << QString("History feed update failure");
}
});
} }
void RPC::shutdownHushd() { void RPC::shutdownHushd() {

1
src/rpc.h

@ -76,6 +76,7 @@ public:
void checkForUpdate(bool silent = true); void checkForUpdate(bool silent = true);
void refreshPrice(); void refreshPrice();
void getMarketChart(QString chartType);
void executeTransaction(Tx tx, void executeTransaction(Tx tx,
const std::function<void(QString opid)> submitted, const std::function<void(QString opid)> submitted,

21
src/settings.cpp

@ -86,7 +86,7 @@ Config Settings::getSettings() {
auto port = s.value("connection/port").toString(); auto port = s.value("connection/port").toString();
auto username = s.value("connection/rpcuser").toString(); auto username = s.value("connection/rpcuser").toString();
auto password = s.value("connection/rpcpassword").toString(); auto password = s.value("connection/rpcpassword").toString();
return Config{host, port, username, password}; return Config{host, port, username, password};
} }
@ -346,7 +346,7 @@ QString Settings::getTokenName() {
//TODO: this isn't used for donations //TODO: this isn't used for donations
QString Settings::getDonationAddr() { QString Settings::getDonationAddr() {
if (Settings::getInstance()->isTestnet()) { if (Settings::getInstance()->isTestnet()) {
return "ztestsaplingXXX"; return "ztestsaplingXXX";
} }
// This is used for user feedback // This is used for user feedback
return "zs1aq4xnrkjlnxx0zesqye7jz3dfrf3rjh7q5z6u8l6mwyqqaam3gx3j2fkqakp33v93yavq46j83q"; return "zs1aq4xnrkjlnxx0zesqye7jz3dfrf3rjh7q5z6u8l6mwyqqaam3gx3j2fkqakp33v93yavq46j83q";
@ -481,26 +481,23 @@ QString Settings::paymentURIPretty(PaymentURI uri) {
PaymentURI Settings::parseURI(QString uri) { PaymentURI Settings::parseURI(QString uri) {
PaymentURI ans; PaymentURI ans;
auto proto=""; QString proto="";
if (isdragonx) { if (isdragonx) {
proto ="drgx:"; proto ="drgx:";
if (!uri.startsWith(proto % QString(":"))) { if (!uri.startsWith(proto)) {
ans.error = "Not a DRGX payment URI"; ans.error = "Not a DRGX payment URI";
return ans; return ans;
} }
} else { } else {
proto = "hush:"; proto = "hush:";
if (!uri.startsWith(proto % QString(":"))) { if (!uri.startsWith(proto)) {
ans.error = "Not a HUSH payment URI"; ans.error = "Not a HUSH payment URI";
return ans; return ans;
} }
} }
uri = uri.right(uri.size()-proto.size());
uri = uri.right(uri.length() - QString("hush:").length()); //qDebug() << "uri(" << uri << ")";
if(isdragonx) {
uri = uri.right(uri.length() - QString("drgx:").length());
}
QRegExp re("([a-zA-Z0-9]+)"); QRegExp re("([a-zA-Z0-9]+)");
int pos; int pos;
@ -517,14 +514,14 @@ PaymentURI Settings::parseURI(QString uri) {
uri = uri.right(uri.length() - ans.addr.length()-1); // swallow '?' uri = uri.right(uri.length() - ans.addr.length()-1); // swallow '?'
QUrlQuery query(uri); QUrlQuery query(uri);
// parse out amt / amount // parse out amt / amount
if (query.hasQueryItem("amt")) { if (query.hasQueryItem("amt")) {
ans.amt = query.queryItemValue("amt"); ans.amt = query.queryItemValue("amt");
} else if (query.hasQueryItem("amount")) { } else if (query.hasQueryItem("amount")) {
ans.amt = query.queryItemValue("amount"); ans.amt = query.queryItemValue("amount");
} }
// parse out memo / msg / message // parse out memo / msg / message
if (query.hasQueryItem("memo")) { if (query.hasQueryItem("memo")) {
ans.memo = query.queryItemValue("memo"); ans.memo = query.queryItemValue("memo");

Loading…
Cancel
Save