From bd3a839269048e316c78e03ad3b7e6d5161f9c79 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 29 May 2021 12:11:13 -0400 Subject: [PATCH] HUSHPrice --- src/camount.cpp | 2 +- src/controller.cpp | 18 +++++++++--------- src/controller.h | 2 +- src/recurring.cpp | 6 +++--- src/settings.cpp | 4 ++-- src/settings.h | 6 +++--- src/websockets.cpp | 5 ++++- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/camount.cpp b/src/camount.cpp index 116973d..9e67dcc 100644 --- a/src/camount.cpp +++ b/src/camount.cpp @@ -43,7 +43,7 @@ double CAmount::getDblAmount() const QString CAmount::toDecimalUSDString() const { - double price = Settings::getInstance()->getZECPrice(); + double price = Settings::getInstance()->getHUSHPrice(); return "$ " + QLocale(QLocale::English).toString(this->getDblAmount() * price, 'f', 2); } diff --git a/src/controller.cpp b/src/controller.cpp index e415084..6f03fdd 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -42,7 +42,7 @@ Controller::Controller(MainWindow* main) priceTimer = new QTimer(main); QObject::connect(priceTimer, &QTimer::timeout, [=]() { if (Settings::getInstance()->getAllowFetchPrices()) - refreshZECPrice(); + refreshHUSHPrice(); }); priceTimer->start(Settings::priceRefreshSpeed); // Every 5 Min @@ -89,7 +89,7 @@ void Controller::setConnection(Connection* c) // If we're allowed to get the Hush Price, get the prices if (Settings::getInstance()->getAllowFetchPrices()) { - refreshZECPrice(); + refreshHUSHPrice(); supplyUpdate(); } @@ -369,7 +369,7 @@ void Controller::getInfoThenRefresh(bool force) if (Settings::getInstance()->get_currency_name() == "USD") { - double price = Settings::getInstance()->getZECPrice(); + double price = Settings::getInstance()->getHUSHPrice(); double volume = Settings::getInstance()->getUSDVolume(); double cap = Settings::getInstance()->getUSDCAP(); main->statusLabel->setText( @@ -546,7 +546,7 @@ void Controller::getInfoThenRefresh(bool force) else { main->statusLabel->setText( - " HUSH/USD=$" + QString::number(Settings::getInstance()->getZECPrice(),'f',2 ) + " HUSH/USD=$" + QString::number(Settings::getInstance()->getHUSHPrice(),'f',2 ) ); ui->volumeExchange->setText( " $ " + QString::number((double) Settings::getInstance()->getUSDVolume() ,'f',2) @@ -1626,7 +1626,7 @@ void Controller::checkForUpdate(bool silent) } // Get the hush->USD price from coinmarketcap using their API -void Controller::refreshZECPrice() +void Controller::refreshHUSHPrice() { if (!zrpc->haveConnection()) return noConnection(); @@ -1652,7 +1652,7 @@ void Controller::refreshZECPrice() else qDebug() << reply->errorString(); - Settings::getInstance()->setZECPrice(0); + Settings::getInstance()->setHUSHPrice(0); Settings::getInstance()->setEURPrice(0); Settings::getInstance()->setBTCPrice(0); Settings::getInstance()->setCNYPrice(0); @@ -1693,7 +1693,7 @@ void Controller::refreshZECPrice() auto parsed = json::parse(all, nullptr, false); if (parsed.is_discarded()) { - Settings::getInstance()->setZECPrice(0); + Settings::getInstance()->setHUSHPrice(0); Settings::getInstance()->setEURPrice(0); Settings::getInstance()->setBTCPrice(0); Settings::getInstance()->setCNYPrice(0); @@ -1736,7 +1736,7 @@ void Controller::refreshZECPrice() { qDebug() << "Found hush key in price json"; qDebug() << "HUSH = $" << QString::number((double)hush["usd"]); - Settings::getInstance()->setZECPrice( hush["usd"] ); + Settings::getInstance()->setHUSHPrice( hush["usd"] ); } if (hush["eur"] >= 0) @@ -1940,7 +1940,7 @@ void Controller::refreshZECPrice() } // If nothing, then set the price to 0; - Settings::getInstance()->setZECPrice(0); + Settings::getInstance()->setHUSHPrice(0); Settings::getInstance()->setEURPrice(0); Settings::getInstance()->setBTCPrice(0); Settings::getInstance()->setCNYPrice(0); diff --git a/src/controller.h b/src/controller.h index c216b4e..a079bec 100644 --- a/src/controller.h +++ b/src/controller.h @@ -46,7 +46,7 @@ public: int _lag; void checkForUpdate(bool silent = true); - void refreshZECPrice(); + void refreshHUSHPrice(); void refreshEURPrice(); void refreshBTCPrice(); void refreshCNYPrice(); diff --git a/src/recurring.cpp b/src/recurring.cpp index a961c14..a5f9a57 100644 --- a/src/recurring.cpp +++ b/src/recurring.cpp @@ -279,7 +279,7 @@ void Recurring::updateInfoWithTx(RecurringPaymentInfo* r, Tx tx) { r->fromAddr = tx.fromAddr; if (r->currency.isEmpty() || r->currency == "USD") { r->currency = "USD"; - r->amt = tx.toAddrs[0].amount.toqint64() * Settings::getInstance()->getZECPrice(); + r->amt = tx.toAddrs[0].amount.toqint64() * Settings::getInstance()->getHUSHPrice(); } else { r->currency = Settings::getTokenName(); @@ -547,7 +547,7 @@ void Recurring::executeRecurringPayment(MainWindow* main, RecurringPaymentInfo r double amount = rpi.amt; if (rpi.currency == "USD") { // If there is no price, then fail the payment - if (Settings::getInstance()->getZECPrice() == 0) { + if (Settings::getInstance()->getHUSHPrice() == 0) { for (auto paymentNumber: paymentNumbers) { updatePaymentItem(rpi.getHash(), paymentNumber, "", QObject::tr("No hush price was available to convert from USD"), @@ -559,7 +559,7 @@ void Recurring::executeRecurringPayment(MainWindow* main, RecurringPaymentInfo r } // Translate it into hush - amount = rpi.amt / Settings::getInstance()->getZECPrice(); + amount = rpi.amt / Settings::getInstance()->getHUSHPrice(); } // Build a Tx diff --git a/src/settings.cpp b/src/settings.cpp index e5bed3d..5b3d18b 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -144,8 +144,8 @@ bool Settings::isSaplingActive() { return (isTestnet() && getBlockNumber() > 0) || (!isTestnet() && getBlockNumber() > 0); } -double Settings::getZECPrice() { - return ZECPrice; +double Settings::getHUSHPrice() { + return HUSHPrice; } double Settings::getEURPrice() { return EURPrice; diff --git a/src/settings.h b/src/settings.h index d8b5d4b..8343424 100644 --- a/src/settings.h +++ b/src/settings.h @@ -76,7 +76,7 @@ public: bool isSaplingActive(); - void setZECPrice(double p) { ZECPrice = p; } + void setHUSHPrice(double p) { HUSHPrice = p; } void setEURPrice(double p) { EURPrice = p; } void setBTCPrice(double p) { BTCPrice = p; } void setCNYPrice(double p) { CNYPrice = p; } @@ -109,7 +109,7 @@ public: void setINRCAP(double p) { INRCAP = p; } void setGBPCAP(double p) { GBPCAP = p; } void setAUDCAP(double p) { AUDCAP = p; } - double getZECPrice(); + double getHUSHPrice(); double getEURPrice(); double getBTCPrice(); double getCNYPrice(); @@ -195,7 +195,7 @@ private: bool _useEmbedded = false; bool _headless = false; - double ZECPrice = 0.0; + double HUSHPrice = 0.0; double BTCPrice = 0.0; double EURPrice = 0.0; double CNYPrice = 0.0; diff --git a/src/websockets.cpp b/src/websockets.cpp index ec8542f..d65c6de 100644 --- a/src/websockets.cpp +++ b/src/websockets.cpp @@ -904,7 +904,10 @@ void AppDataServer::processGetInfo(QJsonObject jobj, MainWindow* mainWindow, std {"maxspendable", maxSpendable.toDecimalDouble()}, {"maxzspendable", maxZSpendable.toDecimalDouble()}, {"tokenName", Settings::getTokenName()}, - {"zecprice", Settings::getInstance()->getZECPrice()}, + // changing this to hushprice is a backward incompatible change that requires + // changing SDL, litewalletd and SDA in unison, and would break older clients + // so we just leave it for now + {"zecprice", Settings::getInstance()->getHUSHPrice()}, {"serverversion", QString(APP_VERSION)} }).toJson(); pClient->sendTextMessage(encryptOutgoing(r));