From a2b6f234f128b72518f0c86559f119ba4142ed09 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Sun, 17 Mar 2024 19:49:41 +0100 Subject: [PATCH] Fix WebUI, implement median mempool fee screen --- data | 2 +- src/config.cpp | 22 +++++++++++----------- src/data.cpp | 32 ++++++++++++++++++++++++++++++++ src/data.hpp | 1 + src/main.cpp | 2 +- src/webserver.cpp | 1 + 6 files changed, 47 insertions(+), 13 deletions(-) diff --git a/data b/data index 9df3329..bd12ce4 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 9df3329847f3939dc1242136e19746613fb83c4b +Subproject commit bd12ce4362f0b665a33e1f637136870a667dbdfc diff --git a/src/config.cpp b/src/config.cpp index fd3e90b..5144416 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -265,23 +265,23 @@ void OTAUpdateTask(void *pvParameters) char getCurrencyIcon() { char ret; - const char *currency = preferences.getString(SETTING_CURRENCY).c_str(); - if (strcmp(currency, CURRENCY_USD) == 0) + String currency = preferences.getString(SETTING_CURRENCY); + if (currency.equals(CURRENCY_USD)) { ret = ICON_DOLLAR; } - else if (strcmp(currency, CURRENCY_EUR) == 0) + else if (currency.equals(CURRENCY_EUR)) { ret = ICON_EURO; } - // break; - // case CURRENCY_GBP: - // ret = ICON_POUND; - // break; - // case CURRENCY_JPY: - // ret = ICON_YEN; - // break; - // } + else if (currency.equals(CURRENCY_GBP)) + { + ret = ICON_POUND; + } + else if (currency.equals(CURRENCY_JPY)) + { + ret = ICON_YEN; + } return ret; } \ No newline at end of file diff --git a/src/data.cpp b/src/data.cpp index eb92216..eab3341 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -5,6 +5,7 @@ const String mempoolPriceApi = "/api/v1/prices"; const String mempoolBlockApi = "/api/blocks/tip/height"; const String mempoolFeeApi = "/api/v1/fees/recommended"; +const String mempoolMedianFeeApi = "/api/v1/fees/mempool-blocks"; uint lastPrice; uint lastBlock; @@ -97,6 +98,37 @@ String getMempoolFees() return ""; } +uint getMempoolFeesMedian() +{ + HTTPClient http; + + // Send HTTP request to CoinGecko API + http.begin(preferences.getString(SETTING_MEMPOOL_INSTANCE) + mempoolMedianFeeApi); + + int httpCode = http.GET(); + + if (httpCode == 200) + { + char feeString[20]; + String payload = http.getString(); + JsonDocument doc; + deserializeJson(doc, payload); + + snprintf(feeString, 20, "L: %d M: %d H: %d", doc["hourFee"].as(), doc["halfHourFee"].as(), doc["fastestFee"].as()); + + return round(doc[0]["medianFee"].as()); + + // preferences.putUInt("lastPrice", eurPrice); + } + else + { + Serial.printf("HTTP GET request mempool median fees failed with error: %s\n", http.errorToString(httpCode).c_str()); + } + http.end(); + + return 0; +} + double getSupplyAtBlock(std::uint32_t blockNr) { if (blockNr >= 33 * 210000) diff --git a/src/data.hpp b/src/data.hpp index 176db2a..3c7e94e 100644 --- a/src/data.hpp +++ b/src/data.hpp @@ -10,5 +10,6 @@ uint getPrice(); uint getBlock(); String getMempoolFees(); +uint getMempoolFeesMedian(); double getSupplyAtBlock(std::uint32_t blockNr); String formatNumberWithSuffix(std::uint64_t num, int numCharacters); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index f136a51..bb44a0a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -112,7 +112,7 @@ void loop() break; case LINE_MEMPOOL_FEES_MEDIAN: icon = ICON_PIE; - rowContent = "NOT IMPL"; + rowContent = getMempoolFeesMedian(); break; case LINE_HALVING_COUNTDOWN: { diff --git a/src/webserver.cpp b/src/webserver.cpp index 758d4b7..69b894c 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -25,6 +25,7 @@ void setupWebserver() server.addHandler(settingsPatchHandler); server.serveStatic("/build", LittleFS, "/build"); + server.serveStatic("/fonts", LittleFS, "/fonts"); server.on("/", HTTP_GET, onIndex); server.onNotFound(onNotFound);