Fix WebUI, implement median mempool fee screen

This commit is contained in:
Djuri Baars 2024-03-17 19:49:41 +01:00
parent 585b50d0ba
commit a2b6f234f1
6 changed files with 47 additions and 13 deletions

2
data

@ -1 +1 @@
Subproject commit 9df3329847f3939dc1242136e19746613fb83c4b Subproject commit bd12ce4362f0b665a33e1f637136870a667dbdfc

View file

@ -265,23 +265,23 @@ void OTAUpdateTask(void *pvParameters)
char getCurrencyIcon() char getCurrencyIcon()
{ {
char ret; char ret;
const char *currency = preferences.getString(SETTING_CURRENCY).c_str(); String currency = preferences.getString(SETTING_CURRENCY);
if (strcmp(currency, CURRENCY_USD) == 0) if (currency.equals(CURRENCY_USD))
{ {
ret = ICON_DOLLAR; ret = ICON_DOLLAR;
} }
else if (strcmp(currency, CURRENCY_EUR) == 0) else if (currency.equals(CURRENCY_EUR))
{ {
ret = ICON_EURO; ret = ICON_EURO;
} }
// break; else if (currency.equals(CURRENCY_GBP))
// case CURRENCY_GBP: {
// ret = ICON_POUND; ret = ICON_POUND;
// break; }
// case CURRENCY_JPY: else if (currency.equals(CURRENCY_JPY))
// ret = ICON_YEN; {
// break; ret = ICON_YEN;
// } }
return ret; return ret;
} }

View file

@ -5,6 +5,7 @@
const String mempoolPriceApi = "/api/v1/prices"; const String mempoolPriceApi = "/api/v1/prices";
const String mempoolBlockApi = "/api/blocks/tip/height"; const String mempoolBlockApi = "/api/blocks/tip/height";
const String mempoolFeeApi = "/api/v1/fees/recommended"; const String mempoolFeeApi = "/api/v1/fees/recommended";
const String mempoolMedianFeeApi = "/api/v1/fees/mempool-blocks";
uint lastPrice; uint lastPrice;
uint lastBlock; uint lastBlock;
@ -97,6 +98,37 @@ String getMempoolFees()
return ""; 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<uint>(), doc["halfHourFee"].as<uint>(), doc["fastestFee"].as<uint>());
return round(doc[0]["medianFee"].as<double>());
// 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) double getSupplyAtBlock(std::uint32_t blockNr)
{ {
if (blockNr >= 33 * 210000) if (blockNr >= 33 * 210000)

View file

@ -10,5 +10,6 @@
uint getPrice(); uint getPrice();
uint getBlock(); uint getBlock();
String getMempoolFees(); String getMempoolFees();
uint getMempoolFeesMedian();
double getSupplyAtBlock(std::uint32_t blockNr); double getSupplyAtBlock(std::uint32_t blockNr);
String formatNumberWithSuffix(std::uint64_t num, int numCharacters); String formatNumberWithSuffix(std::uint64_t num, int numCharacters);

View file

@ -112,7 +112,7 @@ void loop()
break; break;
case LINE_MEMPOOL_FEES_MEDIAN: case LINE_MEMPOOL_FEES_MEDIAN:
icon = ICON_PIE; icon = ICON_PIE;
rowContent = "NOT IMPL"; rowContent = getMempoolFeesMedian();
break; break;
case LINE_HALVING_COUNTDOWN: case LINE_HALVING_COUNTDOWN:
{ {

View file

@ -25,6 +25,7 @@ void setupWebserver()
server.addHandler(settingsPatchHandler); server.addHandler(settingsPatchHandler);
server.serveStatic("/build", LittleFS, "/build"); server.serveStatic("/build", LittleFS, "/build");
server.serveStatic("/fonts", LittleFS, "/fonts");
server.on("/", HTTP_GET, onIndex); server.on("/", HTTP_GET, onIndex);
server.onNotFound(onNotFound); server.onNotFound(onNotFound);