wowlet: WOW/USD price feed from neroswap (HTTP poll); fix fiat conversion to use WOW not XMR

This commit is contained in:
jwinterm
2026-06-18 07:45:54 -04:00
parent 6df43ad49b
commit c343ffcc55
4 changed files with 52 additions and 2 deletions
+24 -1
View File
@@ -4,9 +4,14 @@
#include "AppData.h"
#include <QCoreApplication>
#include <QTimer>
#include <QJsonDocument>
#include <QJsonObject>
#include <QNetworkReply>
#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> AppData::m_instance(nullptr);
+3
View File
@@ -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<AppData> m_instance;
};
+24 -1
View File
@@ -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 &currency : 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) {
+1
View File
@@ -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);