Browse Source

HUSHPrice

pull/24/head
Duke Leto 3 years ago
parent
commit
bd3a839269
  1. 2
      src/camount.cpp
  2. 18
      src/controller.cpp
  3. 2
      src/controller.h
  4. 6
      src/recurring.cpp
  5. 4
      src/settings.cpp
  6. 6
      src/settings.h
  7. 5
      src/websockets.cpp

2
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);
}

18
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);

2
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();

6
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

4
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;

6
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;

5
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));

Loading…
Cancel
Save