From c343ffcc5581afdcce25c2afdc1d598632a06e80 Mon Sep 17 00:00:00 2001 From: jwinterm Date: Thu, 18 Jun 2026 07:45:54 -0400 Subject: [PATCH] wowlet: WOW/USD price feed from neroswap (HTTP poll); fix fiat conversion to use WOW not XMR --- src/utils/AppData.cpp | 25 ++++++++++++++++++++++++- src/utils/AppData.h | 3 +++ src/utils/prices.cpp | 25 ++++++++++++++++++++++++- src/utils/prices.h | 1 + 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/utils/AppData.cpp b/src/utils/AppData.cpp index a1b7d937..346daf3f 100644 --- a/src/utils/AppData.cpp +++ b/src/utils/AppData.cpp @@ -4,9 +4,14 @@ #include "AppData.h" #include +#include +#include +#include +#include #include "config.h" #include "WebsocketNotifier.h" +#include "Networking.h" AppData::AppData(QObject *parent) : QObject(parent) @@ -22,10 +27,28 @@ AppData::AppData(QObject *parent) websocketNotifier()->websocketClient->sendMsg(data); }); - connect(websocketNotifier(), &WebsocketNotifier::CryptoRatesReceived, &this->prices, &Prices::cryptoPricesReceived); + // wownero: crypto prices come from neroswap (HTTP poll below), not feather's websocket (no WOW). + // connect(websocketNotifier(), &WebsocketNotifier::CryptoRatesReceived, &this->prices, &Prices::cryptoPricesReceived); connect(websocketNotifier(), &WebsocketNotifier::FiatRatesReceived, &this->prices, &Prices::fiatPricesReceived); connect(websocketNotifier(), &WebsocketNotifier::TxFiatHistoryReceived, this->txFiatHistory, &TxFiatHistory::onWSData); connect(websocketNotifier(), &WebsocketNotifier::BlockHeightsReceived, this, &AppData::onBlockHeightsReceived); + + // wownero: poll WOW (+ BTC/XMR/etc.) USD prices from neroswap every 2 minutes. + m_network = new Networking(this); + auto fetchNeroswapPrices = [this] { + QNetworkReply *reply = m_network->getJson(this, "https://prices.neroswap.com/v1/prices"); + connect(reply, &QNetworkReply::finished, this, [this, reply] { + reply->deleteLater(); + if (reply->error() != QNetworkReply::NoError) + return; + QJsonObject obj = QJsonDocument::fromJson(reply->readAll()).object(); + this->prices.neroswapPricesReceived(obj); + }); + }; + fetchNeroswapPrices(); + auto *priceTimer = new QTimer(this); + connect(priceTimer, &QTimer::timeout, this, fetchNeroswapPrices); + priceTimer->start(120 * 1000); } QPointer AppData::m_instance(nullptr); diff --git a/src/utils/AppData.h b/src/utils/AppData.h index e320a7ce..f859593a 100644 --- a/src/utils/AppData.h +++ b/src/utils/AppData.h @@ -11,6 +11,8 @@ #include "TxFiatHistory.h" #include "RestoreHeightLookup.h" +class Networking; + class AppData : public QObject { Q_OBJECT @@ -29,6 +31,7 @@ private slots: private: void initRestoreHeights(); + Networking *m_network = nullptr; static QPointer m_instance; }; diff --git a/src/utils/prices.cpp b/src/utils/prices.cpp index 10ac77f1..573d7ae2 100644 --- a/src/utils/prices.cpp +++ b/src/utils/prices.cpp @@ -34,6 +34,29 @@ void Prices::cryptoPricesReceived(const QJsonArray &data) { emit cryptoPricesUpdated(); } +void Prices::neroswapPricesReceived(const QJsonObject &data) { + // neroswap returns {"rates": {"WOW": usd, "XMR": usd, ...}}. It is wowlet's sole crypto-price + // source (feather's websocket server does not carry WOW), so repopulate markets from it. + QJsonObject ratesData = data.value("rates").toObject(); + if (ratesData.isEmpty()) + return; + + this->markets.clear(); + for (const QString &sym : ratesData.keys()) { + double usd = ratesData.value(sym).toDouble(); + if (usd <= 0) + continue; + marketStruct ms; + ms.symbol = sym.toUpper(); + ms.name = sym; + ms.price_usd = usd; + ms.price_usd_change_pct_24h = 0.0; // neroswap does not provide 24h change + this->markets.insert(sym.toUpper(), ms); + } + + emit cryptoPricesUpdated(); +} + void Prices::fiatPricesReceived(const QJsonObject &data) { QJsonObject ratesData = data.value("rates").toObject(); for (const auto ¤cy : ratesData.keys()) { @@ -79,7 +102,7 @@ double Prices::convert(QString symbolFrom, QString symbolTo, double amount) { QString Prices::atomicUnitsToPreferredFiatString(quint64 amount, bool wrapInParens) { QString fiatCurrency = conf()->get(Config::preferredFiatCurrency).toString(); - double fiatAmount = convert("XMR", fiatCurrency, amount / constants::cdiv); + double fiatAmount = convert("WOW", fiatCurrency, amount / constants::cdiv); QString currencyString = Utils::amountToCurrencyString(fiatAmount, fiatCurrency); if (wrapInParens) { diff --git a/src/utils/prices.h b/src/utils/prices.h index 8972c0e9..3df46b56 100644 --- a/src/utils/prices.h +++ b/src/utils/prices.h @@ -27,6 +27,7 @@ public: public slots: void cryptoPricesReceived(const QJsonArray &data); + void neroswapPricesReceived(const QJsonObject &data); // wownero: WOW (+ others) USD prices from neroswap void fiatPricesReceived(const QJsonObject &data); double convert(QString symbolFrom, QString symbolTo, double amount);