fix price api

This commit is contained in:
DenioD
2019-10-26 01:56:24 +02:00
parent 55babd102e
commit 9808e65293
3 changed files with 15 additions and 15 deletions

Binary file not shown.

View File

@@ -337,7 +337,7 @@ void Controller::refreshTransactions() {
for (auto o: it["outgoing_metadata"].get<json::array_t>()) {
QString address = QString::fromStdString(o["address"]);
double amount = -1 * o["value"].get<json::number_float_t>() /10000000;// Sent items are -ve
double amount = it["value"].get<json::number_float_t>(); // Sent items are -ve
QString memo;
if (!o["memo"].is_null()) {
@@ -515,7 +515,7 @@ void Controller::refreshhushPrice() {
return noConnection();
// TODO: use/render all this data
QUrl cmcURL("ncies=btc%2Cusd%2Ceur&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true");
QUrl cmcURL("https://api.coingecko.com/api/v3/simple/price?ids=hush&vs_currencies=btc%2Cusd%2Ceur&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true");
QNetworkRequest req;
req.setUrl(cmcURL);
@@ -540,6 +540,7 @@ void Controller::refreshhushPrice() {
}
qDebug() << "No network errors";
auto all = reply->readAll();
auto parsed = json::parse(all, nullptr, false);
if (parsed.is_discarded()) {
@@ -550,20 +551,17 @@ void Controller::refreshhushPrice() {
qDebug() << "Parsed JSON";
const json& item = parsed.get<json::object_t>();
const json& hush = item["Hush"].get<json::object_t>();
const json& hush = item["hush"].get<json::object_t>();
if (hush["usd"] >= 0) {
if (hush["usd"] >= 0) {
qDebug() << "Found hush key in price json";
// TODO: support BTC/EUR prices as well
QString price = QString::fromStdString(hush["usd"].get<json::string_t>());
//QString price = QString::fromStdString(hush["usd"].get<json::string_t>());
qDebug() << "HUSH = $" << QString::number((double)hush["usd"]);
Settings::getInstance()->sethushPrice( hush["usd"] );
return;
} else {
qDebug() << "No hush key found in JSON! API might be down or we are rate-limited\n";
}
} catch (const std::exception& e) {
} catch (const std::exception& e) {
// If anything at all goes wrong, just set the price to 0 and move on.
qDebug() << QString("Caught something nasty: ") << e.what();
}
@@ -571,6 +569,7 @@ void Controller::refreshhushPrice() {
// If nothing, then set the price to 0;
Settings::getInstance()->sethushPrice(0);
});
}
void Controller::shutdownhushd() {

View File

@@ -214,15 +214,15 @@ void Settings::openTxInExplorer(QString txid) {
QDesktopServices::openUrl(QUrl(url));
}
QString Settings::getUSDFormat(double bal) {
return "$" + QLocale(QLocale::English).toString(bal, 'f', 2);
}
QString Settings::getUSDFromhushAmount(double bal) {
return getUSDFormat(bal * Settings::getInstance()->gethushPrice());
}
QString Settings::getUSDFormat(double bal) {
return "$" + QLocale(QLocale::English).toString(bal * Settings::getInstance()->gethushPrice(), 'f', 2);
}
QString Settings::getDecimalString(double amt) {
QString f = QString::number(amt, 'f', 8);
@@ -242,13 +242,14 @@ QString Settings::gethushDisplayFormat(double bal) {
}
QString Settings::gethushUSDDisplayFormat(double bal) {
auto usdFormat = getUSDFromhushAmount(bal);
auto usdFormat = getUSDFormat(bal);
if (!usdFormat.isEmpty())
return gethushDisplayFormat(bal) % " (" % usdFormat % ")";
return gethushDisplayFormat(bal) % " (" % getUSDFormat(bal) % ")";
else
return gethushDisplayFormat(bal);
}
const QString Settings::txidStatusMessage = QString(QObject::tr("Tx submitted (right click to copy) txid:"));
QString Settings::getTokenName() {