Browse Source

Merge branch 'market' of https://github.com/myhush/silentdragon into market

deadstrip
Duke Leto 4 years ago
parent
commit
9870005a26
  1. 16
      src/mainwindow.cpp
  2. 2
      src/mainwindow.ui
  3. 27
      src/rpc.cpp
  4. 4
      src/settings.cpp
  5. 55
      src/settings.ui
  6. 2
      src/version.h

16
src/mainwindow.cpp

@ -135,7 +135,7 @@ MainWindow::MainWindow(QWidget *parent) :
if (ads->getAllowInternetConnection())
wormholecode = ads->getWormholeCode(ads->getSecretHex());
qDebug() << "MainWindow: createWebsocket with wormholcode=" << wormholecode;
qDebug() << "MainWindow: createWebsocket with wormholecode=" << wormholecode;
createWebsocket(wormholecode);
}
}
@ -279,7 +279,8 @@ void MainWindow::setupSettingsModal() {
std::string currency_name;
try {
currency_name = Settings::getInstance()->get_currency_name();
} catch (...) {
} catch (const std::exception& e) {
qDebug() << QString("Currency name exception! : ") << e.what();
currency_name = "USD";
}
@ -305,12 +306,13 @@ void MainWindow::setupSettingsModal() {
QMessageBox::information(this, tr("Theme Change"), tr("This change can take a few seconds."), QMessageBox::Ok);
});
// Get Currency Data
// Set local currency
QString ticker = QString::fromStdString( Settings::getInstance()->get_currency_name() );
int currency_index = settings.comboBoxCurrency->findText(ticker, Qt::MatchExactly);
settings.comboBoxCurrency->setCurrentIndex(currency_index);
QObject::connect(settings.comboBoxCurrency, SIGNAL(currentIndexChanged(QString)), this, SLOT(slot_change_currency(QString)));
QObject::connect(settings.comboBoxCurrency, &QComboBox::currentTextChanged, [=] (QString ticker) {
this->slot_change_currency(currency_name);
this->slot_change_currency(ticker.toStdString());
rpc->refresh(true);
QMessageBox::information(this, tr("Currency Change"), tr("This change can take a few seconds."), QMessageBox::Ok);
});
@ -392,6 +394,7 @@ void MainWindow::setupSettingsModal() {
}
if (settingsDialog.exec() == QDialog::Accepted) {
qDebug() << "Setting dialog box accepted";
// Custom fees
bool customFees = settings.chkCustomFees->isChecked();
Settings::getInstance()->setAllowCustomFees(customFees);
@ -610,7 +613,7 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event) {
}
// Pay the Zcash URI by showing a confirmation window. If the URI parameter is empty, the UI
// Pay the Hush URI by showing a confirmation window. If the URI parameter is empty, the UI
// will prompt for one. If the myAddr is empty, then the default from address is used to send
// the transaction.
void MainWindow::payZcashURI(QString uri, QString myAddr) {
@ -1338,7 +1341,10 @@ void MainWindow::updateLabels() {
void MainWindow::slot_change_currency(const std::string& currency_name)
{
qDebug() << "slot_change_currency"; //<< ": " << currency_name;
Settings::getInstance()->set_currency_name(currency_name);
qDebug() << "Refreshing price stats after currency change";
rpc->refreshPrice();
// Include currency
std::string saved_currency_name;

2
src/mainwindow.ui

@ -978,7 +978,7 @@
<item row="13" column="2">
<widget class="QLabel" name="marketcapLocal">
<property name="text">
<string>Loading...</string>
<string></string>
</property>
</widget>
</item>

27
src/rpc.cpp

@ -1,4 +1,4 @@
// Copyright 2019 The Hush Developers
// Copyright 2019-2020 The Hush Developers
// Released under the GPLv3
#include "rpc.h"
@ -1093,7 +1093,7 @@ void RPC::refreshPrice() {
return noConnection();
// TODO: use/render all this data
QString price_feed = "https://api.coingecko.com/api/v3/simple/price?ids=hush&vs_currencies=btc%2Cusd%2Ceur%2Ceth%2Cgbp%2Ccny%2Cjpy%2Crub%2Ccad%2Csgd%2Cchf%2Cinr%2Caud%2Cinr&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true";
QString price_feed = "https://api.coingecko.com/api/v3/simple/price?ids=hush&vs_currencies=btc%2Cusd%2Ceur%2Ceth%2Cgbp%2Ccny%2Cjpy%2Crub%2Ccad%2Csgd%2Cchf%2Cinr%2Caud%2Cinr%2Ckrw%2Cthb%2Cnzd%2Czar%2Cvef%2Cxau%2Chkd&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true";
QUrl cmcURL(price_feed);
QNetworkRequest req;
req.setUrl(cmcURL);
@ -1129,17 +1129,20 @@ void RPC::refreshPrice() {
const json& item = parsed.get<json::object_t>();
const json& hush = item["hush"].get<json::object_t>();
auto ticker = s->get_currency_name();
std::string ticker = s->get_currency_name();
std::for_each(ticker.begin(), ticker.end(), [](char & c){ c = ::tolower(c); });
fprintf(stderr,"ticker=%s\n", ticker.c_str());
//qDebug() << "Ticker = " + ticker;
//TODO: better check for valid json response
if (hush["usd"] >= 0) {
if (hush[ticker] >= 0) {
qDebug() << "Found hush key in price json";
//QString price = QString::fromStdString(hush["usd"].get<json::string_t>());
qDebug() << "HUSH = $" << QString::number((double)hush["usd"]);
qDebug() << "HUSH = $" << QString::number((double)hush["usd"]) << " USD";
qDebug() << "HUSH = " << QString::number((double)hush["eur"]) << " EUR";
qDebug() << "HUSH = " << QString::number((int) 100000000 * (double) hush["btc"]) << " sat ";
s->setZECPrice( hush["usd"] );
s->setZECPrice( hush[ticker] );
s->setBTCPrice( (unsigned int) 100000000 * (double)hush["btc"] );
std::for_each(ticker.begin(), ticker.end(), [](char & c){ c = ::tolower(c); });
@ -1158,16 +1161,18 @@ void RPC::refreshPrice() {
s->set_marketcap(ticker, mcap);
qDebug() << "Volume = " << (double) vol;
ui->volume->setText( QString::number((double) vol) + " HUSH" );
std::for_each(ticker.begin(), ticker.end(), [](char & c){ c = ::toupper(c); });
ui->volume->setText( QString::number((double) vol) + " " + QString::fromStdString(ticker) );
ui->volumeBTC->setText( QString::number((double) btcvol) + " BTC" );
std::for_each(ticker.begin(), ticker.end(), [](char & c){ c = ::toupper(c); });
ui->volumeLocal->setText( QString::number((double) vol * (double) price) + " " + QString::fromStdString(ticker) );
//TODO: we don't get an actual HUSH volume stat
if (price > 0)
ui->volumeLocal->setText( QString::number((double) vol / (double) price) + " HUSH");
qDebug() << "Mcap = " << (double) mcap;
ui->marketcap->setText( QString::number( (double) mcap) + " HUSH" );
ui->marketcap->setText( QString::number( (unsigned int) mcap) + " " + QString::fromStdString(ticker) );
ui->marketcapBTC->setText( QString::number((double) btcmcap) + " BTC" );
std::for_each(ticker.begin(), ticker.end(), [](char & c){ c = ::toupper(c); });
ui->marketcapLocal->setText( QString::number((double) mcap * (double) price) + " " + QString::fromStdString(ticker) );
//ui->marketcapLocal->setText( QString::number((double) mcap * (double) price) + " " + QString::fromStdString(ticker) );
refresh(true);
return;

4
src/settings.cpp

@ -280,7 +280,8 @@ void Settings::saveRestore(QDialog* d) {
}
QString Settings::getUSDFormat(double bal) {
return "$" + QLocale(QLocale::English).toString(bal * Settings::getInstance()->getZECPrice(), 'f', 2);
//TODO: respect current locale!
return QLocale(QLocale::English).toString(bal * Settings::getInstance()->getZECPrice(), 'f', 4) + " " + QString::fromStdString(Settings::getInstance()->get_currency_name());
}
QString Settings::getDecimalString(double amt) {
@ -323,6 +324,7 @@ QString Settings::getDonationAddr() {
if (Settings::getInstance()->isTestnet()) {
return "ztestsaplingXXX";
}
// This is used for user feedback
return "zs1aq4xnrkjlnxx0zesqye7jz3dfrf3rjh7q5z6u8l6mwyqqaam3gx3j2fkqakp33v93yavq46j83q";
}

55
src/settings.ui

@ -200,11 +200,6 @@
<string>AUD</string>
</property>
</item>
<item>
<property name="text">
<string>BTC</string>
</property>
</item>
<item>
<property name="text">
<string>CAD</string>
@ -230,16 +225,66 @@
<string>GBP</string>
</property>
</item>
<item>
<property name="text">
<string>HKD</string>
</property>
</item>
<item>
<property name="text">
<string>INR</string>
</property>
</item>
<item>
<property name="text">
<string>JPY</string>
</property>
</item>
<item>
<property name="text">
<string>KRW</string>
</property>
</item>
<item>
<property name="text">
<string>NZD</string>
</property>
</item>
<item>
<property name="text">
<string>RUB</string>
</property>
</item>
<item>
<property name="text">
<string>SGD</string>
</property>
</item>
<item>
<property name="text">
<string>THB</string>
</property>
</item>
<item>
<property name="text">
<string>USD</string>
</property>
</item>
<item>
<property name="text">
<string>VEF</string>
</property>
</item>
<item>
<property name="text">
<string>XAU</string>
</property>
</item>
<item>
<property name="text">
<string>ZAR</string>
</property>
</item>
</widget>
</item>

2
src/version.h

@ -1 +1 @@
#define APP_VERSION "0.8.3"
#define APP_VERSION "0.9.0"

Loading…
Cancel
Save