diff --git a/src/lib/block_notify.cpp b/src/lib/block_notify.cpp index 0dab659..60b3034 100644 --- a/src/lib/block_notify.cpp +++ b/src/lib/block_notify.cpp @@ -158,7 +158,7 @@ void onWebsocketBlockMessage(esp_websocket_event_data_t *event_data) // return; // } - if (doc.containsKey("block")) + if (doc["block"].is()) { JsonObject block = doc["block"]; @@ -168,7 +168,7 @@ void onWebsocketBlockMessage(esp_websocket_event_data_t *event_data) processNewBlock(block["height"].as()); } - else if (doc.containsKey("mempool-blocks")) + else if (doc["mempool-blocks"].is()) { JsonArray blockInfo = doc["mempool-blocks"].as(); @@ -181,7 +181,7 @@ void onWebsocketBlockMessage(esp_websocket_event_data_t *event_data) } void processNewBlock(uint32_t newBlockHeight) { - if (currentBlockHeight <= newBlockHeight) + if (newBlockHeight <= currentBlockHeight) { return; } diff --git a/src/lib/v2_notify.cpp b/src/lib/v2_notify.cpp index c0007dd..560b39d 100644 --- a/src/lib/v2_notify.cpp +++ b/src/lib/v2_notify.cpp @@ -127,7 +127,7 @@ namespace V2Notify void handleV2Message(JsonDocument doc) { - if (doc.containsKey("blockheight")) + if (doc["blockheight"].is()) { uint newBlockHeight = doc["blockheight"].as(); @@ -138,13 +138,13 @@ namespace V2Notify processNewBlock(newBlockHeight); } - else if (doc.containsKey("blockfee")) + else if (doc["blockfee"].is()) { uint medianFee = doc["blockfee"].as(); processNewBlockFee(medianFee); } - else if (doc.containsKey("price")) + else if (doc["price"].is()) { // Iterate through the key-value pairs of the "price" object diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index 382faa9..1d6a878 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -612,15 +612,15 @@ void onApiSettingsPatch(AsyncWebServerRequest *request, JsonVariant &json) } // Handle DND settings - if (settings.containsKey("dnd")) { + if (settings["dnd"].is()) { JsonObject dndObj = settings["dnd"]; auto& ledHandler = getLedHandler(); - if (dndObj.containsKey("timeBasedEnabled")) { + if (dndObj["timeBasedEnabled"].is()) { ledHandler.setDNDTimeBasedEnabled(dndObj["timeBasedEnabled"].as()); } - if (dndObj.containsKey("startHour") && dndObj.containsKey("startMinute") && - dndObj.containsKey("endHour") && dndObj.containsKey("endMinute")) { + if (dndObj["startHour"].is() && dndObj["startMinute"].is() && + dndObj["endHour"].is() && dndObj["endMinute"].is()) { ledHandler.setDNDTimeRange( dndObj["startHour"].as(), dndObj["startMinute"].as(), @@ -1251,25 +1251,4 @@ void onApiLightsPost(AsyncWebServerRequest *request, uint8_t *data, size_t len, pixels.show(); request->send(200); -} - -void onApiSettings(AsyncWebServerRequest *request, JsonVariant &json) -{ - JsonObject settings = json.as(); - auto& ledHandler = getLedHandler(); - - if (settings.containsKey("dnd")) { - JsonObject dndObj = settings["dnd"]; - if (dndObj.containsKey("timeBasedEnabled")) { - ledHandler.setDNDTimeBasedEnabled(dndObj["timeBasedEnabled"].as()); - } - if (dndObj.containsKey("startHour") && dndObj.containsKey("startMinute") && - dndObj.containsKey("endHour") && dndObj.containsKey("endMinute")) { - ledHandler.setDNDTimeRange( - dndObj["startHour"].as(), - dndObj["startMinute"].as(), - dndObj["endHour"].as(), - dndObj["endMinute"].as()); - } - } } \ No newline at end of file