Fix WebUI, implement median mempool fee screen
This commit is contained in:
parent
585b50d0ba
commit
a2b6f234f1
6 changed files with 47 additions and 13 deletions
2
data
2
data
|
@ -1 +1 @@
|
|||
Subproject commit 9df3329847f3939dc1242136e19746613fb83c4b
|
||||
Subproject commit bd12ce4362f0b665a33e1f637136870a667dbdfc
|
|
@ -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;
|
||||
}
|
32
src/data.cpp
32
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<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)
|
||||
{
|
||||
if (blockNr >= 33 * 210000)
|
||||
|
|
|
@ -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);
|
|
@ -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:
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue