diff --git a/data b/data index 0e278d1..8389ed8 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 0e278d1be4160ab382213e80ec0716f8aad14a65 +Subproject commit 8389ed8e36a9a1a7a39ca31f53324a0949aedb1d diff --git a/lib/btclock/data_handler.cpp b/lib/btclock/data_handler.cpp index bcb14d1..eaf4538 100644 --- a/lib/btclock/data_handler.cpp +++ b/lib/btclock/data_handler.cpp @@ -4,22 +4,24 @@ #include #endif - char getCurrencySymbol(char input) { switch (input) { case CURRENCY_EUR: return '['; + break; case CURRENCY_GBP: return ']'; + break; case CURRENCY_JPY: return '^'; - // Dollar symbol currencies + break; case CURRENCY_AUD: case CURRENCY_CAD: case CURRENCY_USD: return '$'; + break; default: return input; } @@ -31,18 +33,21 @@ std::string getCurrencyCode(char input) { case CURRENCY_EUR: return CURRENCY_CODE_EUR; + break; case CURRENCY_GBP: return CURRENCY_CODE_GBP; + break; case CURRENCY_JPY: return CURRENCY_CODE_JPY; + break; case CURRENCY_AUD: return CURRENCY_CODE_AUD; + break; case CURRENCY_CAD: return CURRENCY_CODE_CAD; - case CURRENCY_USD: - return CURRENCY_CODE_USD; + break; default: - return CURRENCY_CODE_UNKNOWN; + return CURRENCY_CODE_USD; } } @@ -58,255 +63,126 @@ char getCurrencyChar(const std::string& input) return CURRENCY_AUD; else if (input == "CAD") return CURRENCY_CAD; - else if (input == "USD") - return CURRENCY_USD; - else if (input == "ALL") - return CURRENCY_ALL; - else if (input == "BWP") - return CURRENCY_BWP; - else if (input == "HNL") - return CURRENCY_HNL; - else if (input == "HTG") - return CURRENCY_HTG; - else if (input == "MWK") - return CURRENCY_MWK; - else if (input == "MZN") - return CURRENCY_MZN; - else if (input == "NAD") - return CURRENCY_NAD; - else if (input == "PYG") - return CURRENCY_PYG; - else if (input == "RON") - return CURRENCY_RON; - else if (input == "SZL") - return CURRENCY_SZL; - else if (input == "ZAR") - return CURRENCY_ZAR; - else if (input == "ZMW") - return CURRENCY_ZMW; - // Map dollar-symbol currencies to USD character code - else if (input == "NZD" || input == "SGD" || input == "HKD" || - input == "BND" || input == "FJD" || input == "SBD" || - input == "TTD" || input == "XCD" || input == "KYD" || - input == "GYD" || input == "BBD" || input == "BSD" || - input == "BMD" || input == "LRD" || input == "ZWL" || - input == "ARS" || input == "CLP" || input == "COP" || - input == "MXN" || input == "UYU" || input == "DOP" || - input == "SVC" || input == "SRD") - return CURRENCY_USD; else - return ' '; + return CURRENCY_USD; // Assuming USD is the default for unknown inputs } -// Private helper methods -namespace { - std::array formatPriceData(std::uint32_t price, char currencySymbol, const std::string& currencyCode, bool useSuffixFormat, bool mowMode, bool shareDot, bool useSymbol) - { - std::array ret; - std::string priceString; - // If useSymbol is true, we're using the char version - use symbol as requested - // If useSymbol is false, we're using the string version - only use symbol if it's a recognized currency - bool shouldUseSymbol = useSymbol || (!useSymbol && currencySymbol != ' '); - - if (std::to_string(price).length() >= NUM_SCREENS || useSuffixFormat) - { - int numScreens = shareDot || mowMode ? NUM_SCREENS - 1 : NUM_SCREENS - 2; - if (shouldUseSymbol) { - priceString = getCurrencySymbol(currencySymbol) + formatNumberWithSuffix(price, numScreens, mowMode); - } else { - priceString = formatNumberWithSuffix(price, numScreens, mowMode); - } - } - else - { - if (shouldUseSymbol) { - priceString = getCurrencySymbol(currencySymbol) + std::to_string(price); - } else { - priceString = std::to_string(price); - } - } - std::uint32_t firstIndex = 0; - if ((shareDot && priceString.length() <= (NUM_SCREENS)) || priceString.length() < (NUM_SCREENS)) - { - priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' '); - - if (mowMode) - { - ret[0] = "MOW/UNITS"; - } - else - { - ret[0] = "BTC/" + currencyCode; - } - - - firstIndex = 1; - } - - size_t dotPosition = priceString.find('.'); - - if (shareDot && dotPosition != std::string::npos && dotPosition > 0) - { - std::vector tempArray; - if (dotPosition != std::string::npos && dotPosition > 0) - { - for (size_t i = 0; i < priceString.length(); ++i) - { - if (i == dotPosition - 1) - { - tempArray.push_back(std::string(1, priceString[i]) + "."); - ++i; // Skip the dot in the next iteration - } - else - { - tempArray.push_back(std::string(1, priceString[i])); - } - } - - // Copy from tempArray to ret - for (std::uint32_t i = firstIndex; i < NUM_SCREENS && i - firstIndex < tempArray.size(); ++i) - { - ret[i] = tempArray[i - firstIndex]; - } - } - } - else - { - for (std::uint32_t i = firstIndex; i < NUM_SCREENS; i++) - { - ret[i] = std::string(1, priceString[i]); - } - } - - return ret; - } - - std::array formatSatsPerCurrency(std::uint32_t price, char currencySymbol, const std::string& currencyCode, bool withSatsSymbol, bool alwaysShowSats) - { - std::array ret; - double satsPerCurrency = (1.0 / static_cast(price)) * 1e8; - std::string priceString; - - // Handle values below 1 sat per currency with 3 decimal places - if (satsPerCurrency < 1.0) { - std::ostringstream oss; - oss << std::fixed << std::setprecision(3) << satsPerCurrency; - priceString = oss.str(); - } - // // Check if price is greater than 1 billion (for displaying with 3 decimal places) - // else if (price >= 100000000) { - // std::ostringstream oss; - // oss << std::fixed << std::setprecision(3) << satsPerCurrency; - // priceString = oss.str(); - // } - else { - // Default formatting for integer values - priceString = std::to_string(static_cast(round(satsPerCurrency))); - } - - std::uint32_t firstIndex = 0; - std::uint8_t insertSatSymbol = NUM_SCREENS - priceString.length() - 1; - - if (priceString.length() < (NUM_SCREENS)) - { - // Pad the string with spaces if necessary - if (priceString.length() < NUM_SCREENS) - { - priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' '); - } - - if (alwaysShowSats || currencySymbol != CURRENCY_USD || price >= 100000000) // no time anymore when earlier than 1 - ret[0] = "SATS/" + currencyCode; - else - ret[0] = "MSCW/TIME"; - - firstIndex = 1; - - for (std::uint32_t i = firstIndex; i < NUM_SCREENS; i++) - { - ret[i] = priceString[i]; - } - - if (withSatsSymbol) - { - ret[insertSatSymbol] = "STS"; - } - } - return ret; - } - - std::array formatMarketCap(std::uint32_t blockHeight, std::uint32_t price, char currencySymbol, const std::string& currencyCode, bool bigChars) - { - std::array ret; - std::uint32_t firstIndex = 0; - double supply = getSupplyAtBlock(blockHeight); - uint64_t marketCap = static_cast(supply * double(price)); - - ret[0] = currencyCode + "/MCAP"; - - if (bigChars) - { - firstIndex = 1; - std::string priceString = getCurrencySymbol(currencySymbol) + formatNumberWithSuffix(marketCap, (NUM_SCREENS - 2)); - priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' '); - - for (std::uint32_t i = firstIndex; i < NUM_SCREENS; i++) - { - ret[i] = priceString[i]; - } - } - else - { - std::string stringValue = std::to_string(marketCap); - size_t mcLength = stringValue.length(); - size_t leadingSpaces = (3 - mcLength % 3) % 3; - stringValue = std::string(leadingSpaces, ' ') + stringValue; - - std::uint32_t groups = (mcLength + leadingSpaces) / 3; - - if (groups < NUM_SCREENS) - { - firstIndex = 1; - } - - for (int i = firstIndex; i < NUM_SCREENS - groups - 1; i++) - { - ret[i] = ""; - } - - ret[NUM_SCREENS - groups - 1] = std::string(" ") + getCurrencySymbol(currencySymbol) + " "; - for (std::uint32_t i = 0; i < groups; i++) - { - ret[(NUM_SCREENS - groups + i)] = stringValue.substr(i * 3, 3).c_str(); - } - } - - return ret; - } -} - -// Updated public methods to use the helper methods std::array parsePriceData(std::uint32_t price, char currencySymbol, bool useSuffixFormat, bool mowMode, bool shareDot) { - // For char version, always use the currency symbol - return formatPriceData(price, currencySymbol, getCurrencyCode(currencySymbol), useSuffixFormat, mowMode, shareDot, true); + std::array ret; + std::string priceString; + if (std::to_string(price).length() >= NUM_SCREENS || useSuffixFormat) + { + int numScreens = shareDot || mowMode ? NUM_SCREENS - 1 : NUM_SCREENS - 2; + priceString = getCurrencySymbol(currencySymbol) + formatNumberWithSuffix(price, numScreens, mowMode); + } + else + { + priceString = getCurrencySymbol(currencySymbol) + std::to_string(price); + } + std::uint32_t firstIndex = 0; + if ((shareDot && priceString.length() <= (NUM_SCREENS)) || priceString.length() < (NUM_SCREENS)) + { + priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' '); + + if (mowMode) + { + ret[0] = "MOW/UNITS"; + } + else + { + ret[0] = "BTC/" + getCurrencyCode(currencySymbol); + } + + + firstIndex = 1; + } + + size_t dotPosition = priceString.find('.'); + + if (shareDot && dotPosition != std::string::npos && dotPosition > 0) + { + std::vector tempArray; + if (dotPosition != std::string::npos && dotPosition > 0) + { + for (size_t i = 0; i < priceString.length(); ++i) + { + if (i == dotPosition - 1) + { + tempArray.push_back(std::string(1, priceString[i]) + "."); + ++i; // Skip the dot in the next iteration + } + else + { + tempArray.push_back(std::string(1, priceString[i])); + } + } + + // Copy from tempArray to ret + for (std::uint32_t i = firstIndex; i < NUM_SCREENS && i - firstIndex < tempArray.size(); ++i) + { + ret[i] = tempArray[i - firstIndex]; + } + } + } + else + { + for (std::uint32_t i = firstIndex; i < NUM_SCREENS; i++) + { + ret[i] = std::string(1, priceString[i]); + } + } + + + return ret; } -std::array parsePriceData(std::uint32_t price, const std::string& currencyCode, bool useSuffixFormat, bool mowMode, bool shareDot) +std::array parseSatsPerCurrency(std::uint32_t price,char currencySymbol, bool withSatsSymbol) { - // For string version, let formatPriceData decide whether to use symbol based on if it's a recognized currency - char currencyChar = getCurrencyChar(currencyCode); - return formatPriceData(price, currencyChar, currencyCode, useSuffixFormat, mowMode, shareDot, false); -} + std::array ret; + std::string priceString = std::to_string(int(round(1 / float(price) * 10e7))); + std::uint32_t firstIndex = 0; + std::uint8_t insertSatSymbol = NUM_SCREENS - priceString.length() - 1; -std::array parseSatsPerCurrency(std::uint32_t price, char currencySymbol, bool withSatsSymbol) -{ - return formatSatsPerCurrency(price, currencySymbol, getCurrencyCode(currencySymbol), withSatsSymbol, false); -} + if (priceString.length() < (NUM_SCREENS)) + { + // Check if price is greater than 1 billion + if (price >= 100000000) + { + double satsPerCurrency = (1.0 / static_cast(price)) * 1e8; // Calculate satoshis + std::ostringstream oss; + oss << std::fixed << std::setprecision(3) << satsPerCurrency; // Format with 3 decimal places + priceString = oss.str(); + } + else + { + priceString = std::to_string(static_cast(round(1.0 / static_cast(price) * 1e8))); // Default formatting + } -std::array parseSatsPerCurrency(std::uint32_t price, const std::string& currencyCode, bool withSatsSymbol) -{ - return formatSatsPerCurrency(price, getCurrencyChar(currencyCode), currencyCode, withSatsSymbol, true); + // Pad the string with spaces if necessary + if (priceString.length() < NUM_SCREENS) + { + priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' '); + } + + if (currencySymbol != CURRENCY_USD || price >= 100000000) // no time anymore when earlier than 1 + ret[0] = "SATS/" + getCurrencyCode(currencySymbol); + else + ret[0] = "MSCW/TIME"; + + firstIndex = 1; + + for (std::uint32_t i = firstIndex; i < NUM_SCREENS; i++) + { + ret[i] = priceString[i]; + } + + if (withSatsSymbol) + { + ret[insertSatSymbol] = "STS"; + } + } + return ret; } std::array parseBlockHeight(std::uint32_t blockHeight) @@ -397,13 +273,53 @@ std::array parseHalvingCountdown(std::uint32_t blockHe std::array parseMarketCap(std::uint32_t blockHeight, std::uint32_t price, char currencySymbol, bool bigChars) { - return formatMarketCap(blockHeight, price, currencySymbol, getCurrencyCode(currencySymbol), bigChars); -} + std::array ret; + std::uint32_t firstIndex = 0; + double supply = getSupplyAtBlock(blockHeight); + uint64_t marketCap = static_cast(supply * double(price)); -std::array parseMarketCap(std::uint32_t blockHeight, std::uint32_t price, const std::string& currencyCode, bool bigChars) -{ - char currencyChar = getCurrencyChar(currencyCode); - return formatMarketCap(blockHeight, price, currencyChar, currencyCode, bigChars); + ret[0] = getCurrencyCode(currencySymbol) + "/MCAP"; + + if (bigChars) + { + firstIndex = 1; + // Serial.print("Market cap: "); + // Serial.println(marketCap); + std::string priceString = currencySymbol + formatNumberWithSuffix(marketCap, (NUM_SCREENS - 2)); + priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' '); + + for (std::uint32_t i = firstIndex; i < NUM_SCREENS; i++) + { + ret[i] = priceString[i]; + } + } + else + { + std::string stringValue = std::to_string(marketCap); + size_t mcLength = stringValue.length(); + size_t leadingSpaces = (3 - mcLength % 3) % 3; + stringValue = std::string(leadingSpaces, ' ') + stringValue; + + std::uint32_t groups = (mcLength + leadingSpaces) / 3; + + if (groups < NUM_SCREENS) + { + firstIndex = 1; + } + + for (int i = firstIndex; i < NUM_SCREENS - groups - 1; i++) + { + ret[i] = ""; + } + + ret[NUM_SCREENS - groups - 1] = std::string(" ") + currencySymbol + " "; + for (std::uint32_t i = 0; i < groups; i++) + { + ret[(NUM_SCREENS - groups + i)] = stringValue.substr(i * 3, 3).c_str(); + } + } + + return ret; } #ifdef __EMSCRIPTEN__ @@ -434,12 +350,7 @@ emscripten::val parseBlockHeightArray(std::uint32_t blockHeight) emscripten::val parsePriceDataArray(std::uint32_t price, const std::string ¤cySymbol, bool useSuffixFormat = false, bool mowMode = false, bool shareDot = false) { - // Handle both single character and three-character currency codes - if (currencySymbol.length() == 1) { - return arrayToStringArray(parsePriceData(price, currencySymbol[0], useSuffixFormat, mowMode, shareDot)); - } else { - return arrayToStringArray(parsePriceData(price, currencySymbol, useSuffixFormat, mowMode, shareDot)); - } + return arrayToStringArray(parsePriceData(price, currencySymbol[0], useSuffixFormat, mowMode, shareDot)); } emscripten::val parseHalvingCountdownArray(std::uint32_t blockHeight, bool asBlocks) @@ -449,12 +360,7 @@ emscripten::val parseHalvingCountdownArray(std::uint32_t blockHeight, bool asBlo emscripten::val parseMarketCapArray(std::uint32_t blockHeight, std::uint32_t price, const std::string ¤cySymbol, bool bigChars) { - // Handle both single character and three-character currency codes - if (currencySymbol.length() == 1) { - return arrayToStringArray(parseMarketCap(blockHeight, price, currencySymbol[0], bigChars)); - } else { - return arrayToStringArray(parseMarketCap(blockHeight, price, currencySymbol, bigChars)); - } + return arrayToStringArray(parseMarketCap(blockHeight, price, currencySymbol[0], bigChars)); } emscripten::val parseBlockFeesArray(std::uint16_t blockFees) @@ -464,12 +370,7 @@ emscripten::val parseBlockFeesArray(std::uint16_t blockFees) emscripten::val parseSatsPerCurrencyArray(std::uint32_t price, const std::string ¤cySymbol, bool withSatsSymbol) { - // Handle both single character and three-character currency codes - if (currencySymbol.length() == 1) { - return arrayToStringArray(parseSatsPerCurrency(price, currencySymbol[0], withSatsSymbol)); - } else { - return arrayToStringArray(parseSatsPerCurrency(price, currencySymbol, withSatsSymbol)); - } + return arrayToStringArray(parseSatsPerCurrency(price, currencySymbol[0], withSatsSymbol)); } EMSCRIPTEN_BINDINGS(my_module) diff --git a/lib/btclock/data_handler.hpp b/lib/btclock/data_handler.hpp index dc68e17..4dda86b 100644 --- a/lib/btclock/data_handler.hpp +++ b/lib/btclock/data_handler.hpp @@ -3,8 +3,6 @@ #include #include #include -#include -#include #include "utils.hpp" @@ -14,41 +12,6 @@ const char CURRENCY_GBP = ']'; const char CURRENCY_JPY = '^'; const char CURRENCY_AUD = '_'; const char CURRENCY_CAD = '`'; -const char CURRENCY_ALL = 'L'; -const char CURRENCY_BWP = 'P'; -const char CURRENCY_HNL = 'L'; -const char CURRENCY_HTG = 'G'; -const char CURRENCY_MWK = 'K'; -const char CURRENCY_MZN = 'M'; -const char CURRENCY_NAD = 'N'; -const char CURRENCY_PYG = 'G'; -const char CURRENCY_RON = 'L'; -const char CURRENCY_SZL = 'E'; -const char CURRENCY_ZAR = 'R'; -const char CURRENCY_ZMW = 'K'; -// const char CURRENCY_NZD = '$'; -// const char CURRENCY_SGD = '$'; -// const char CURRENCY_HKD = '$'; -// const char CURRENCY_BND = '$'; -// const char CURRENCY_FJD = '$'; -// const char CURRENCY_SBD = '$'; -// const char CURRENCY_TTD = '$'; -// const char CURRENCY_XCD = '$'; -// const char CURRENCY_KYD = '$'; -// const char CURRENCY_GYD = '$'; -// const char CURRENCY_BBD = '$'; -// const char CURRENCY_BSD = '$'; -// const char CURRENCY_BMD = '$'; -// const char CURRENCY_LRD = '$'; -// const char CURRENCY_ZWL = '$'; -// const char CURRENCY_ARS = '$'; -// const char CURRENCY_CLP = '$'; -// const char CURRENCY_COP = '$'; -// const char CURRENCY_MXN = '$'; -// const char CURRENCY_UYU = '$'; -// const char CURRENCY_DOP = '$'; -// const char CURRENCY_SVC = '$'; -// const char CURRENCY_SRD = '$'; const std::string CURRENCY_CODE_USD = "USD"; const std::string CURRENCY_CODE_EUR = "EUR"; @@ -56,61 +19,14 @@ const std::string CURRENCY_CODE_GBP = "GBP"; const std::string CURRENCY_CODE_JPY = "JPY"; const std::string CURRENCY_CODE_AUD = "AUD"; const std::string CURRENCY_CODE_CAD = "CAD"; -// const std::string CURRENCY_CODE_ALL = "ALL"; -// const std::string CURRENCY_CODE_BWP = "BWP"; -// const std::string CURRENCY_CODE_HNL = "HNL"; -// const std::string CURRENCY_CODE_HTG = "HTG"; -// const std::string CURRENCY_CODE_MWK = "MWK"; -// const std::string CURRENCY_CODE_MZN = "MZN"; -// const std::string CURRENCY_CODE_NAD = "NAD"; -// const std::string CURRENCY_CODE_PYG = "PYG"; -// const std::string CURRENCY_CODE_RON = "RON"; -// const std::string CURRENCY_CODE_SZL = "SZL"; -// const std::string CURRENCY_CODE_ZAR = "ZAR"; -// const std::string CURRENCY_CODE_ZMW = "ZMW"; -// const std::string CURRENCY_CODE_NZD = "NZD"; -// const std::string CURRENCY_CODE_SGD = "SGD"; -// const std::string CURRENCY_CODE_HKD = "HKD"; -// const std::string CURRENCY_CODE_BND = "BND"; -// const std::string CURRENCY_CODE_FJD = "FJD"; -// const std::string CURRENCY_CODE_SBD = "SBD"; -// const std::string CURRENCY_CODE_TTD = "TTD"; -// const std::string CURRENCY_CODE_XCD = "XCD"; -// const std::string CURRENCY_CODE_KYD = "KYD"; -// const std::string CURRENCY_CODE_GYD = "GYD"; -// const std::string CURRENCY_CODE_BBD = "BBD"; -// const std::string CURRENCY_CODE_BSD = "BSD"; -// const std::string CURRENCY_CODE_BMD = "BMD"; -// const std::string CURRENCY_CODE_LRD = "LRD"; -// const std::string CURRENCY_CODE_ZWL = "ZWL"; -// const std::string CURRENCY_CODE_ARS = "ARS"; -// const std::string CURRENCY_CODE_CLP = "CLP"; -// const std::string CURRENCY_CODE_COP = "COP"; -// const std::string CURRENCY_CODE_MXN = "MXN"; -// const std::string CURRENCY_CODE_UYU = "UYU"; -// const std::string CURRENCY_CODE_DOP = "DOP"; -// const std::string CURRENCY_CODE_SVC = "SVC"; -// const std::string CURRENCY_CODE_SRD = "SRD"; -const std::string CURRENCY_CODE_UNKNOWN = " "; -// Public methods std::array parsePriceData(std::uint32_t price, char currency, bool useSuffixFormat = false, bool mowMode = false, bool shareDot = false); -std::array parsePriceData(std::uint32_t price, const std::string& currencyCode, bool useSuffixFormat = false, bool mowMode = false, bool shareDot = false); std::array parseSatsPerCurrency(std::uint32_t price, char currencySymbol, bool withSatsSymbol); -std::array parseSatsPerCurrency(std::uint32_t price, const std::string& currencyCode, bool withSatsSymbol); std::array parseBlockHeight(std::uint32_t blockHeight); std::array parseHalvingCountdown(std::uint32_t blockHeight, bool asBlocks); std::array parseMarketCap(std::uint32_t blockHeight, std::uint32_t price, char currencySymbol, bool bigChars); -std::array parseMarketCap(std::uint32_t blockHeight, std::uint32_t price, const std::string& currencyCode, bool bigChars); std::array parseBlockFees(std::uint16_t blockFees); char getCurrencySymbol(char input); std::string getCurrencyCode(char input); -char getCurrencyChar(const std::string& input); - -// Private helper methods -namespace { - std::array formatPriceData(std::uint32_t price, char currencySymbol, const std::string& currencyCode, bool useSuffixFormat, bool mowMode, bool shareDot, bool useSymbol = true); - std::array formatSatsPerCurrency(std::uint32_t price, char currencySymbol, const std::string& currencyCode, bool withSatsSymbol, bool alwaysShowSats = false); - std::array formatMarketCap(std::uint32_t blockHeight, std::uint32_t price, char currencySymbol, const std::string& currencyCode, bool bigChars); -} \ No newline at end of file +char getCurrencyChar(const std::string& input); \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 140946d..98192fe 100644 --- a/platformio.ini +++ b/platformio.ini @@ -37,8 +37,8 @@ build_unflags = -fno-exceptions lib_deps = https://github.com/joltwallet/esp_littlefs.git#v1.16.4 - bblanchon/ArduinoJson@^7.3.1 - esp32async/ESPAsyncWebServer @ 3.7.4 + bblanchon/ArduinoJson@^7.4.1 + esp32async/ESPAsyncWebServer @ 3.7.7 robtillaart/MCP23017@^0.9.1 adafruit/Adafruit NeoPixel@^1.12.5 https://github.com/dsbaars/universal_pin#feature/mcp23017_rt diff --git a/src/lib/config.cpp b/src/lib/config.cpp index c0f9305..908a5a6 100644 --- a/src/lib/config.cpp +++ b/src/lib/config.cpp @@ -1,6 +1,5 @@ #include "config.hpp" #include "led_handler.hpp" -#include "lnbits.hpp" #define MAX_ATTEMPTS_WIFI_CONNECTION 20 @@ -393,10 +392,6 @@ String replaceAmbiguousChars(String input) void setupWebsocketClients(void *pvParameters) { DataSourceType dataSource = getDataSource(); - - if (preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED)) { - setupLnbits(); - } if (dataSource == BTCLOCK_SOURCE || dataSource == CUSTOM_SOURCE) { diff --git a/src/lib/defaults.hpp b/src/lib/defaults.hpp index f7d8b51..00d8bc0 100644 --- a/src/lib/defaults.hpp +++ b/src/lib/defaults.hpp @@ -99,8 +99,4 @@ enum DataSourceType { #ifndef DEFAULT_BOOT_TEXT #define DEFAULT_BOOT_TEXT "BTCLOCK" -#endif - -#define DEFAULT_LNBITS_INSTANCE "demo.lnbits.com" -#define DEFAULT_LNBITS_HTTPS true -#define DEFAULT_LNBITS_ENABLED false +#endif \ No newline at end of file diff --git a/src/lib/lnbits.cpp b/src/lib/lnbits.cpp deleted file mode 100644 index a170744..0000000 --- a/src/lib/lnbits.cpp +++ /dev/null @@ -1,151 +0,0 @@ -#include "lnbits.hpp" -#include "lib/shared.hpp" - -LNBitsFetch* LNBitsFetch::instance = nullptr; - -LNBitsFetch::LNBitsFetch() : initialized(false), taskHandle(nullptr) {} - -LNBitsFetch& LNBitsFetch::getInstance() { - if (instance == nullptr) { - instance = new LNBitsFetch(); - } - return *instance; -} - -void LNBitsFetch::setup() { - if (initialized) return; - - currentCurrency = getActiveCurrencies().front(); - - xTaskCreate(taskLNBits, "lnbitsTask", 6 * 1024, NULL, tskIDLE_PRIORITY, &taskHandle); - initialized = true; - - // Fetch rates immediately when setup - fetchRates(); -} - -String LNBitsFetch::buildApiUrl(const std::string& currency) { - String instance = preferences.getString("lnbitsInstance", DEFAULT_LNBITS_INSTANCE); - bool useHttps = preferences.getBool("lnbitsHttps", DEFAULT_LNBITS_HTTPS); - - String protocol = useHttps ? "https" : "http"; - return protocol + "://" + instance + "/api/v1/rate/" + String(currency.c_str()); -} - -void LNBitsFetch::fetchRates() { - if (!initialized) return; - - std::vector currencies = getActiveCurrencies(); - HTTPClient http; - - for (const std::string& currency : currencies) { - String apiUrl = buildApiUrl(currency); - - if (debugLogEnabled()) { - Serial.printf("Fetching LNBits rate for %s from %s\n", currency.c_str(), apiUrl.c_str()); - } - - http.begin(apiUrl); - int httpCode = http.GET(); - - if (httpCode == HTTP_CODE_OK) { - String payload = http.getString(); - JsonDocument doc; - DeserializationError error = deserializeJson(doc, payload); - - if (!error) { - if (doc.containsKey("price")) { - uint price = doc["price"].as(); - - if (price > 0) { - priceMap[currency] = price; - unsigned long int currentTime = esp_timer_get_time() / 1000000; - lastUpdateMap[currency] = currentTime; - - if (debugLogEnabled()) { - Serial.printf("Updated LNBits price for %s: %d\n", currency.c_str(), price); - } - - // Update the screen if it's currently displaying price-related information - if (workQueue != nullptr && ( - ScreenHandler::getCurrentScreen() == SCREEN_BTC_TICKER || - ScreenHandler::getCurrentScreen() == SCREEN_SATS_PER_CURRENCY || - ScreenHandler::getCurrentScreen() == SCREEN_MARKET_CAP)) { - WorkItem rateUpdate = {TASK_PRICE_UPDATE, currency[0]}; - xQueueSend(workQueue, &rateUpdate, portMAX_DELAY); - } - } - } - } else if (debugLogEnabled()) { - Serial.printf("JSON parse error for %s: %s\n", currency.c_str(), error.c_str()); - } - } else if (debugLogEnabled()) { - Serial.printf("HTTP error for %s: %d\n", currency.c_str(), httpCode); - } - - http.end(); - } -} - -void LNBitsFetch::stop() { - if (taskHandle != nullptr) { - vTaskDelete(taskHandle); - taskHandle = nullptr; - } - initialized = false; -} - -void LNBitsFetch::restart() { - stop(); - setup(); -} - -bool LNBitsFetch::isInitialized() const { - return initialized; -} - -TaskHandle_t LNBitsFetch::getTaskHandle() const { - return taskHandle; -} - -uint LNBitsFetch::getPrice(const std::string& currencyCode) { - if (priceMap.find(currencyCode) == priceMap.end()) { - return 0; - } - return priceMap[currencyCode]; -} - -void LNBitsFetch::setPrice(uint newPrice, const std::string& currencyCode) { - priceMap[currencyCode] = newPrice; -} - -unsigned long int LNBitsFetch::getLastPriceUpdate(const std::string& currencyCode) { - if (lastUpdateMap.find(currencyCode) == lastUpdateMap.end()) { - return 0; - } - return lastUpdateMap[currencyCode]; -} - -void setupLnbits() { - if (preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED)) { - LNBitsFetch::getInstance().setup(); - } -} - -void taskLNBits(void* pvParameters) { - for (;;) { - // Wait for notification from timer - ulTaskNotifyTake(pdTRUE, portMAX_DELAY); - - // Fetch rates - LNBitsFetch::getInstance().fetchRates(); - } -} - -void LNBitsFetch::setCurrentCurrency(const std::string& currency) { - currentCurrency = currency; -} - -std::string LNBitsFetch::getCurrentCurrency() const { - return currentCurrency; -} \ No newline at end of file diff --git a/src/lib/lnbits.hpp b/src/lib/lnbits.hpp deleted file mode 100644 index 3f74acc..0000000 --- a/src/lib/lnbits.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -#include "lib/screen_handler.hpp" - -class LNBitsFetch { -private: - LNBitsFetch(); - static LNBitsFetch* instance; - - bool initialized; - TaskHandle_t taskHandle; - std::map priceMap; - std::map lastUpdateMap; - std::string currentCurrency; - String buildApiUrl(const std::string& currency); - -public: - static LNBitsFetch& getInstance(); - - void setup(); - void fetchRates(); - void stop(); - void restart(); - void setCurrentCurrency(const std::string& currency); - std::string getCurrentCurrency() const; - - bool isInitialized() const; - TaskHandle_t getTaskHandle() const; - - uint getPrice(const std::string& currencyCode); - void setPrice(uint newPrice, const std::string& currencyCode); - unsigned long int getLastPriceUpdate(const std::string& currencyCode); -}; - -void setupLnbits(); -void taskLNBits(void* pvParameters); \ No newline at end of file diff --git a/src/lib/price_notify.cpp b/src/lib/price_notify.cpp index 6ac2f3b..c851e85 100644 --- a/src/lib/price_notify.cpp +++ b/src/lib/price_notify.cpp @@ -1,6 +1,6 @@ #include "price_notify.hpp" -const char *wsServerPrice = "wss://ws.coincap.io/prices?assets=bitcoin"; +const char *wsServerPrice = "wss://ws.kraken.com/v2"; WebSocketsClient webSocket; uint currentPrice = 90000; @@ -14,7 +14,7 @@ void onWebsocketPriceEvent(WStype_t type, uint8_t * payload, size_t length); void setupPriceNotify() { - webSocket.beginSSL("ws.coincap.io", 443, "/prices?assets=bitcoin"); + webSocket.beginSSL("ws.kraken.com", 443, "/v2"); webSocket.onEvent([](WStype_t type, uint8_t * payload, size_t length) { onWebsocketPriceEvent(type, payload, length); }); @@ -32,7 +32,14 @@ void onWebsocketPriceEvent(WStype_t type, uint8_t * payload, size_t length) { case WStype_CONNECTED: { Serial.println("Connected to " + String(wsServerPrice)); - priceNotifyInit = true; + + JsonDocument doc; + doc["method"] = "subscribe"; + JsonObject params = doc["params"].to(); + params["channel"] = "ticker"; + params["symbol"][0] = "BTC/USD"; + + webSocket.sendTXT(doc.as().c_str()); break; } case WStype_TEXT: @@ -40,13 +47,15 @@ void onWebsocketPriceEvent(WStype_t type, uint8_t * payload, size_t length) { JsonDocument doc; deserializeJson(doc, (char *)payload); - if (doc["bitcoin"].is()) + if (doc["data"][0].is()) { - if (currentPrice != doc["bitcoin"].as()) + float price = doc["data"][0]["last"].as(); + uint roundedPrice = round(price); + if (currentPrice != roundedPrice) { - processNewPrice(doc["bitcoin"].as(), CURRENCY_USD); + processNewPrice(roundedPrice, CURRENCY_USD); } - } + } break; } case WStype_BIN: diff --git a/src/lib/screen_handler.cpp b/src/lib/screen_handler.cpp index 160dbb2..75e59aa 100644 --- a/src/lib/screen_handler.cpp +++ b/src/lib/screen_handler.cpp @@ -89,47 +89,24 @@ bool ScreenHandler::handleCurrencyRotation(bool forward) { std::vector ac = getActiveCurrencies(); if (ac.empty()) return false; - if (preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED)) { - std::string curCode = LNBitsFetch::getInstance().getCurrentCurrency(); - auto it = std::find(ac.begin(), ac.end(), curCode); - - if (it == ac.end()) { - // Current currency not found in active currencies - initialize based on direction - LNBitsFetch::getInstance().setCurrentCurrency(forward ? ac.front() : ac.back()); - setCurrentScreen(getCurrentScreen()); - return true; - } else if (forward && curCode != ac.back()) { - // Moving forward and not at last currency - LNBitsFetch::getInstance().setCurrentCurrency(ac.at(std::distance(ac.begin(), it) + 1)); - setCurrentScreen(getCurrentScreen()); - return true; - } else if (!forward && curCode != ac.front()) { - // Moving backward and not at first currency - LNBitsFetch::getInstance().setCurrentCurrency(ac.at(std::distance(ac.begin(), it) - 1)); - setCurrentScreen(getCurrentScreen()); - return true; - } - } else { - - std::string curCode = getCurrencyCode(getCurrentCurrency()); - auto it = std::find(ac.begin(), ac.end(), curCode); - - if (it == ac.end()) { - // Current currency not found in active currencies - initialize based on direction - setCurrentCurrency(getCurrencyChar(forward ? ac.front() : ac.back())); - setCurrentScreen(getCurrentScreen()); - return true; - } else if (forward && curCode != ac.back()) { - // Moving forward and not at last currency - setCurrentCurrency(getCurrencyChar(ac.at(std::distance(ac.begin(), it) + 1))); - setCurrentScreen(getCurrentScreen()); - return true; - } else if (!forward && curCode != ac.front()) { - // Moving backward and not at first currency - setCurrentCurrency(getCurrencyChar(ac.at(std::distance(ac.begin(), it) - 1))); - setCurrentScreen(getCurrentScreen()); - return true; - } + std::string curCode = getCurrencyCode(getCurrentCurrency()); + auto it = std::find(ac.begin(), ac.end(), curCode); + + if (it == ac.end()) { + // Current currency not found in active currencies - initialize based on direction + setCurrentCurrency(getCurrencyChar(forward ? ac.front() : ac.back())); + setCurrentScreen(getCurrentScreen()); + return true; + } else if (forward && curCode != ac.back()) { + // Moving forward and not at last currency + setCurrentCurrency(getCurrencyChar(ac.at(std::distance(ac.begin(), it) + 1))); + setCurrentScreen(getCurrentScreen()); + return true; + } else if (!forward && curCode != ac.front()) { + // Moving backward and not at first currency + setCurrentCurrency(getCurrencyChar(ac.at(std::distance(ac.begin(), it) - 1))); + setCurrentScreen(getCurrentScreen()); + return true; } // If we're at the last/first currency of current screen, let nextScreen/previousScreen handle it return false; @@ -264,39 +241,18 @@ void workerTask(void *pvParameters) { case TASK_PRICE_UPDATE: { uint currency = ScreenHandler::getCurrentCurrency(); - - uint price; - if (preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED)) { - price = LNBitsFetch::getInstance().getPrice(LNBitsFetch::getInstance().getCurrentCurrency()); - } else { - price = getPrice(currency); - } + uint price = getPrice(currency); if (currentScreenValue == SCREEN_BTC_TICKER) { - if (preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED)) { - taskEpdContent = parsePriceData(price, LNBitsFetch::getInstance().getCurrentCurrency(), preferences.getBool("suffixPrice", DEFAULT_SUFFIX_PRICE), - preferences.getBool("mowMode", DEFAULT_MOW_MODE), - preferences.getBool("suffixShareDot", DEFAULT_SUFFIX_SHARE_DOT) - ); - } else { - taskEpdContent = parsePriceData(price, currency, preferences.getBool("suffixPrice", DEFAULT_SUFFIX_PRICE), - preferences.getBool("mowMode", DEFAULT_MOW_MODE), - preferences.getBool("suffixShareDot", DEFAULT_SUFFIX_SHARE_DOT) - ); - } + taskEpdContent = parsePriceData(price, currency, preferences.getBool("suffixPrice", DEFAULT_SUFFIX_PRICE), + preferences.getBool("mowMode", DEFAULT_MOW_MODE), + preferences.getBool("suffixShareDot", DEFAULT_SUFFIX_SHARE_DOT) + ); } else if (currentScreenValue == SCREEN_SATS_PER_CURRENCY) { - if (preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED)) { - taskEpdContent = parseSatsPerCurrency(price, LNBitsFetch::getInstance().getCurrentCurrency(), preferences.getBool("useSatsSymbol", DEFAULT_USE_SATS_SYMBOL)); - } else { - taskEpdContent = parseSatsPerCurrency(price, currency, preferences.getBool("useSatsSymbol", DEFAULT_USE_SATS_SYMBOL)); - } + taskEpdContent = parseSatsPerCurrency(price, currency, preferences.getBool("useSatsSymbol", DEFAULT_USE_SATS_SYMBOL)); } else { auto& blockNotify = BlockNotify::getInstance(); - if (preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED)) { - taskEpdContent = parseMarketCap(blockNotify.getBlockHeight(), price, LNBitsFetch::getInstance().getCurrentCurrency(), preferences.getBool("mcapBigChar", DEFAULT_MCAP_BIG_CHAR)); - } else { - taskEpdContent = parseMarketCap(blockNotify.getBlockHeight(), price, currency, preferences.getBool("mcapBigChar", DEFAULT_MCAP_BIG_CHAR)); - } + taskEpdContent = parseMarketCap(blockNotify.getBlockHeight(), price, currency, preferences.getBool("mcapBigChar", DEFAULT_MCAP_BIG_CHAR)); } EPDManager::getInstance().setContent(taskEpdContent); diff --git a/src/lib/timers.cpp b/src/lib/timers.cpp index a8b7e49..850ead3 100644 --- a/src/lib/timers.cpp +++ b/src/lib/timers.cpp @@ -1,6 +1,5 @@ #include "timers.hpp" #include "led_handler.hpp" -#include "lnbits.hpp" esp_timer_handle_t screenRotateTimer; esp_timer_handle_t minuteTimer; @@ -79,11 +78,6 @@ void IRAM_ATTR minuteTimerISR(void *arg) { if (miningPoolHandle != NULL) { vTaskNotifyGiveFromISR(miningPoolHandle, &xHigherPriorityTaskWoken); } - - TaskHandle_t lnbitsHandle = LNBitsFetch::getInstance().getTaskHandle(); - if (lnbitsHandle != NULL) { - vTaskNotifyGiveFromISR(lnbitsHandle, &xHigherPriorityTaskWoken); - } if (xHigherPriorityTaskWoken == pdTRUE) { portYIELD_FROM_ISR(); diff --git a/src/lib/v2_notify.cpp b/src/lib/v2_notify.cpp index fa01165..b915518 100644 --- a/src/lib/v2_notify.cpp +++ b/src/lib/v2_notify.cpp @@ -77,22 +77,21 @@ namespace V2Notify buffer = new uint8_t[responseLength]; - if (!preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED)) { - response["type"] = "subscribe"; - response["eventType"] = "price"; + response["type"] = "subscribe"; + response["eventType"] = "price"; - JsonArray currenciesArray = response["currencies"].to(); + JsonArray currenciesArray = response["currencies"].to(); - for (const auto &str : getActiveCurrencies()) - { - currenciesArray.add(str); - } - - responseLength = measureMsgPack(response); - buffer = new uint8_t[responseLength]; - serializeMsgPack(response, buffer, responseLength); - webSocket.sendBIN(buffer, responseLength); + for (const auto &str : getActiveCurrencies()) + { + currenciesArray.add(str); } + + // response["currencies"] = currenciesArray; + responseLength = measureMsgPack(response); + buffer = new uint8_t[responseLength]; + serializeMsgPack(response, buffer, responseLength); + webSocket.sendBIN(buffer, responseLength); break; } case WStype_TEXT: diff --git a/src/lib/webserver.cpp b/src/lib/webserver.cpp index a25d4d7..6ee62f9 100644 --- a/src/lib/webserver.cpp +++ b/src/lib/webserver.cpp @@ -5,7 +5,7 @@ static const char* JSON_CONTENT = "application/json"; static const char *const PROGMEM strSettings[] = { - "hostnamePrefix", "mempoolInstance", "nostrPubKey", "nostrRelay", "bitaxeHostname", "miningPoolName", "miningPoolUser", "nostrZapPubkey", "httpAuthUser", "httpAuthPass", "gitReleaseUrl", "poolLogosUrl", "ceEndpoint", "fontName", "localPoolEndpoint", "tzString", "lnbitsInstance"}; + "hostnamePrefix", "mempoolInstance", "nostrPubKey", "nostrRelay", "bitaxeHostname", "miningPoolName", "miningPoolUser", "nostrZapPubkey", "httpAuthUser", "httpAuthPass", "gitReleaseUrl", "poolLogosUrl", "ceEndpoint", "fontName", "localPoolEndpoint", "tzString"}; static const char *const PROGMEM uintSettings[] = {"minSecPriceUpd", "fullRefreshMin", "ledBrightness", "flMaxBrightness", "flEffectDelay", "luxLightToggle", "wpTimeout"}; @@ -18,7 +18,7 @@ static const char *const PROGMEM boolSettings[] = {"ledTestOnPower", "ledFlashOn "mempoolSecure", "bitaxeEnabled", "miningPoolStats", "verticalDesc", "nostrZapNotify", "httpAuthEnabled", - "enableDebugLog", "ceDisableSSL", "dndEnabled", "dndTimeBasedEnabled", "lnbitsEnabled", "lnbitsHttps"}; + "enableDebugLog", "ceDisableSSL", "dndEnabled", "dndTimeBasedEnabled"}; AsyncWebServer server(80); AsyncEventSource events("/events"); @@ -252,15 +252,9 @@ JsonDocument getStatusObject() conStatus["blocks"] = blockNotify.isConnected(); conStatus["V2"] = V2Notify::isV2NotifyConnected(); conStatus["nostr"] = nostrConnected(); - conStatus["lnbits"] = LNBitsFetch::getInstance().isInitialized(); root["rssi"] = WiFi.RSSI(); - - if (preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED)) { - root["currency"] = LNBitsFetch::getInstance().getCurrentCurrency(); - } else { - root["currency"] = getCurrencyCode(ScreenHandler::getCurrentCurrency()); - } + root["currency"] = getCurrencyCode(ScreenHandler::getCurrentCurrency()); #ifdef HAS_FRONTLIGHT std::vector statuses = ledHandler.frontlightGetStatus(); @@ -304,7 +298,13 @@ JsonDocument getLedStatusObject() uint blue = pixColor & 0xFF; char hexColor[8]; snprintf(hexColor, sizeof(hexColor), "#%02X%02X%02X", red, green, blue); - colors.add(hexColor); + // colors.add(hexColor); + + JsonObject object = colors.add(); + object["red"] = red; + object["green"] = green; + object["blue"] = blue; + object["hex"] = hexColor; } return root; @@ -719,12 +719,6 @@ void onApiSettingsGet(AsyncWebServerRequest *request) root["ledFlashOnZap"] = preferences.getBool("ledFlashOnZap", DEFAULT_LED_FLASH_ON_ZAP); root["fontName"] = preferences.getString("fontName", DEFAULT_FONT_NAME); root["availableFonts"] = FontNames::getAvailableFonts(); - - // LNBits settings - root["lnbitsEnabled"] = preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED); - root["lnbitsInstance"] = preferences.getString("lnbitsInstance", DEFAULT_LNBITS_INSTANCE); - root["lnbitsHttps"] = preferences.getBool("lnbitsHttps", DEFAULT_LNBITS_HTTPS); - // Custom endpoint settings (only used for CUSTOM_SOURCE) root["customEndpoint"] = preferences.getString("customEndpoint", DEFAULT_CUSTOM_ENDPOINT); root["customEndpointDisableSSL"] = preferences.getBool("customEndpointDisableSSL", DEFAULT_CUSTOM_ENDPOINT_DISABLE_SSL); @@ -929,7 +923,6 @@ void onApiStopDataSources(AsyncWebServerRequest *request) stopPriceNotify(); BlockNotify::getInstance().stop(); - LNBitsFetch::getInstance().stop(); request->send(response); } @@ -941,9 +934,6 @@ void onApiRestartDataSources(AsyncWebServerRequest *request) restartPriceNotify(); BlockNotify::getInstance().restart(); - if (preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED)) { - LNBitsFetch::getInstance().restart(); - } request->send(response); } @@ -1093,17 +1083,10 @@ void onApiShowCurrency(AsyncWebServerRequest *request) return; } - // LNbits: set currency using a string - if (preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED)) { - LNBitsFetch::getInstance().setCurrentCurrency(currency); - ScreenHandler::setCurrentScreen(ScreenHandler::getCurrentScreen()); + char curChar = getCurrencyChar(currency); - } else { - // Normal situation: set currency using a char - char curChar = getCurrencyChar(currency); - ScreenHandler::setCurrentCurrency(curChar); - ScreenHandler::setCurrentScreen(ScreenHandler::getCurrentScreen()); - } + ScreenHandler::setCurrentCurrency(curChar); + ScreenHandler::setCurrentScreen(ScreenHandler::getCurrentScreen()); request->send(HTTP_OK); return; diff --git a/src/lib/webserver.hpp b/src/lib/webserver.hpp index fb4a348..ddd6b73 100644 --- a/src/lib/webserver.hpp +++ b/src/lib/webserver.hpp @@ -8,11 +8,6 @@ #include #include "AsyncJson.h" #include -#include -#include -#include -#include -#include #include "lib/block_notify.hpp" #include "lib/led_handler.hpp" @@ -20,11 +15,6 @@ #include "lib/screen_handler.hpp" #include "webserver/OneParamRewrite.hpp" #include "lib/mining_pool/pool_factory.hpp" -#include "lib/lnbits.hpp" -#include "lib/v2_notify.hpp" -#include "lib/ota.hpp" -#include "lib/shared.hpp" - extern TaskHandle_t eventSourceTaskHandle; diff --git a/test/test_datahandler/test_main.cpp b/test/test_datahandler/test_main.cpp index 1a9757c..24118e4 100644 --- a/test/test_datahandler/test_main.cpp +++ b/test/test_datahandler/test_main.cpp @@ -36,15 +36,12 @@ void test_CorrectSatsPerDollarConversion(void) void test_SatsPerDollarAfter1B(void) { std::array output = parseSatsPerCurrency(120000000, CURRENCY_USD, false); - - std::string joined = joinArrayWithBrackets(output); - - TEST_ASSERT_EQUAL_STRING_MESSAGE("SATS/USD", output[0].c_str(), joined.c_str()); - TEST_ASSERT_EQUAL_STRING_MESSAGE("0", output[NUM_SCREENS - 5].c_str(), joined.c_str()); - TEST_ASSERT_EQUAL_STRING_MESSAGE(".", output[NUM_SCREENS - 4].c_str(), joined.c_str()); - TEST_ASSERT_EQUAL_STRING_MESSAGE("8", output[NUM_SCREENS - 3].c_str(), joined.c_str()); - TEST_ASSERT_EQUAL_STRING_MESSAGE("3", output[NUM_SCREENS - 2].c_str(), joined.c_str()); - TEST_ASSERT_EQUAL_STRING_MESSAGE("3", output[NUM_SCREENS - 1].c_str(), joined.c_str()); + TEST_ASSERT_EQUAL_STRING("SATS/USD", output[0].c_str()); + TEST_ASSERT_EQUAL_STRING("0", output[NUM_SCREENS - 5].c_str()); + TEST_ASSERT_EQUAL_STRING(".", output[NUM_SCREENS - 4].c_str()); + TEST_ASSERT_EQUAL_STRING("8", output[NUM_SCREENS - 3].c_str()); + TEST_ASSERT_EQUAL_STRING("3", output[NUM_SCREENS - 2].c_str()); + TEST_ASSERT_EQUAL_STRING("3", output[NUM_SCREENS - 1].c_str()); } void test_CorrectSatsPerPoundConversion(void) @@ -275,24 +272,6 @@ void test_Mcap1TrillionJpySmallChars(void) TEST_ASSERT_EQUAL_STRING("000", output[NUM_SCREENS - 1].c_str()); } -void test_PriceDataWithCurrencyCode(void) -{ - std::array output = parsePriceData(10000, "PYG", false, false, false); - TEST_ASSERT_EQUAL_STRING("BTC/PYG", output[0].c_str()); -} - -void test_SatsPerCurrencyWithCurrencyCode(void) -{ - std::array output = parseSatsPerCurrency(100000, "ZAR", false); - TEST_ASSERT_EQUAL_STRING("SATS/ZAR", output[0].c_str()); -} - -void test_McapWithCurrencyCode(void) -{ - std::array output = parseMarketCap(100000, 10000, "PYG", true); - TEST_ASSERT_EQUAL_STRING("PYG/MCAP", output[0].c_str()); -} - // not needed when using generate_test_runner.rb int runUnityTests(void) { @@ -316,9 +295,6 @@ int runUnityTests(void) RUN_TEST(test_PriceSuffixModeCompact2); RUN_TEST(test_PriceSuffixModeMow); RUN_TEST(test_PriceSuffixModeMowCompact); - RUN_TEST(test_PriceDataWithCurrencyCode); - RUN_TEST(test_SatsPerCurrencyWithCurrencyCode); - RUN_TEST(test_McapWithCurrencyCode); return UNITY_END(); }