Compare commits
3 commits
feature/ln
...
main
Author | SHA1 | Date | |
---|---|---|---|
2ac2a62c61 | |||
064fe8fe6c | |||
d648551835 |
15 changed files with 246 additions and 725 deletions
2
data
2
data
|
@ -1 +1 @@
|
||||||
Subproject commit 0e278d1be4160ab382213e80ec0716f8aad14a65
|
Subproject commit 8389ed8e36a9a1a7a39ca31f53324a0949aedb1d
|
|
@ -4,22 +4,24 @@
|
||||||
#include <emscripten/bind.h>
|
#include <emscripten/bind.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
char getCurrencySymbol(char input)
|
char getCurrencySymbol(char input)
|
||||||
{
|
{
|
||||||
switch (input)
|
switch (input)
|
||||||
{
|
{
|
||||||
case CURRENCY_EUR:
|
case CURRENCY_EUR:
|
||||||
return '[';
|
return '[';
|
||||||
|
break;
|
||||||
case CURRENCY_GBP:
|
case CURRENCY_GBP:
|
||||||
return ']';
|
return ']';
|
||||||
|
break;
|
||||||
case CURRENCY_JPY:
|
case CURRENCY_JPY:
|
||||||
return '^';
|
return '^';
|
||||||
// Dollar symbol currencies
|
break;
|
||||||
case CURRENCY_AUD:
|
case CURRENCY_AUD:
|
||||||
case CURRENCY_CAD:
|
case CURRENCY_CAD:
|
||||||
case CURRENCY_USD:
|
case CURRENCY_USD:
|
||||||
return '$';
|
return '$';
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
@ -31,18 +33,21 @@ std::string getCurrencyCode(char input)
|
||||||
{
|
{
|
||||||
case CURRENCY_EUR:
|
case CURRENCY_EUR:
|
||||||
return CURRENCY_CODE_EUR;
|
return CURRENCY_CODE_EUR;
|
||||||
|
break;
|
||||||
case CURRENCY_GBP:
|
case CURRENCY_GBP:
|
||||||
return CURRENCY_CODE_GBP;
|
return CURRENCY_CODE_GBP;
|
||||||
|
break;
|
||||||
case CURRENCY_JPY:
|
case CURRENCY_JPY:
|
||||||
return CURRENCY_CODE_JPY;
|
return CURRENCY_CODE_JPY;
|
||||||
|
break;
|
||||||
case CURRENCY_AUD:
|
case CURRENCY_AUD:
|
||||||
return CURRENCY_CODE_AUD;
|
return CURRENCY_CODE_AUD;
|
||||||
|
break;
|
||||||
case CURRENCY_CAD:
|
case CURRENCY_CAD:
|
||||||
return CURRENCY_CODE_CAD;
|
return CURRENCY_CODE_CAD;
|
||||||
case CURRENCY_USD:
|
break;
|
||||||
return CURRENCY_CODE_USD;
|
|
||||||
default:
|
default:
|
||||||
return CURRENCY_CODE_UNKNOWN;
|
return CURRENCY_CODE_USD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,72 +63,22 @@ char getCurrencyChar(const std::string& input)
|
||||||
return CURRENCY_AUD;
|
return CURRENCY_AUD;
|
||||||
else if (input == "CAD")
|
else if (input == "CAD")
|
||||||
return CURRENCY_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
|
else
|
||||||
return ' ';
|
return CURRENCY_USD; // Assuming USD is the default for unknown inputs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private helper methods
|
std::array<std::string, NUM_SCREENS> parsePriceData(std::uint32_t price, char currencySymbol, bool useSuffixFormat, bool mowMode, bool shareDot)
|
||||||
namespace {
|
{
|
||||||
std::array<std::string, NUM_SCREENS> formatPriceData(std::uint32_t price, char currencySymbol, const std::string& currencyCode, bool useSuffixFormat, bool mowMode, bool shareDot, bool useSymbol)
|
|
||||||
{
|
|
||||||
std::array<std::string, NUM_SCREENS> ret;
|
std::array<std::string, NUM_SCREENS> ret;
|
||||||
std::string priceString;
|
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)
|
if (std::to_string(price).length() >= NUM_SCREENS || useSuffixFormat)
|
||||||
{
|
{
|
||||||
int numScreens = shareDot || mowMode ? NUM_SCREENS - 1 : NUM_SCREENS - 2;
|
int numScreens = shareDot || mowMode ? NUM_SCREENS - 1 : NUM_SCREENS - 2;
|
||||||
if (shouldUseSymbol) {
|
|
||||||
priceString = getCurrencySymbol(currencySymbol) + formatNumberWithSuffix(price, numScreens, mowMode);
|
priceString = getCurrencySymbol(currencySymbol) + formatNumberWithSuffix(price, numScreens, mowMode);
|
||||||
} else {
|
|
||||||
priceString = formatNumberWithSuffix(price, numScreens, mowMode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (shouldUseSymbol) {
|
|
||||||
priceString = getCurrencySymbol(currencySymbol) + std::to_string(price);
|
priceString = getCurrencySymbol(currencySymbol) + std::to_string(price);
|
||||||
} else {
|
|
||||||
priceString = std::to_string(price);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
std::uint32_t firstIndex = 0;
|
std::uint32_t firstIndex = 0;
|
||||||
if ((shareDot && priceString.length() <= (NUM_SCREENS)) || priceString.length() < (NUM_SCREENS))
|
if ((shareDot && priceString.length() <= (NUM_SCREENS)) || priceString.length() < (NUM_SCREENS))
|
||||||
|
@ -136,7 +91,7 @@ namespace {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret[0] = "BTC/" + currencyCode;
|
ret[0] = "BTC/" + getCurrencyCode(currencySymbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -178,45 +133,40 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<std::string, NUM_SCREENS> formatSatsPerCurrency(std::uint32_t price, char currencySymbol, const std::string& currencyCode, bool withSatsSymbol, bool alwaysShowSats)
|
std::array<std::string, NUM_SCREENS> parseSatsPerCurrency(std::uint32_t price,char currencySymbol, bool withSatsSymbol)
|
||||||
{
|
{
|
||||||
std::array<std::string, NUM_SCREENS> ret;
|
std::array<std::string, NUM_SCREENS> ret;
|
||||||
double satsPerCurrency = (1.0 / static_cast<double>(price)) * 1e8;
|
std::string priceString = std::to_string(int(round(1 / float(price) * 10e7)));
|
||||||
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<int>(round(satsPerCurrency)));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::uint32_t firstIndex = 0;
|
std::uint32_t firstIndex = 0;
|
||||||
std::uint8_t insertSatSymbol = NUM_SCREENS - priceString.length() - 1;
|
std::uint8_t insertSatSymbol = NUM_SCREENS - priceString.length() - 1;
|
||||||
|
|
||||||
if (priceString.length() < (NUM_SCREENS))
|
if (priceString.length() < (NUM_SCREENS))
|
||||||
{
|
{
|
||||||
|
// Check if price is greater than 1 billion
|
||||||
|
if (price >= 100000000)
|
||||||
|
{
|
||||||
|
double satsPerCurrency = (1.0 / static_cast<double>(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<int>(round(1.0 / static_cast<double>(price) * 1e8))); // Default formatting
|
||||||
|
}
|
||||||
|
|
||||||
// Pad the string with spaces if necessary
|
// Pad the string with spaces if necessary
|
||||||
if (priceString.length() < NUM_SCREENS)
|
if (priceString.length() < NUM_SCREENS)
|
||||||
{
|
{
|
||||||
priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' ');
|
priceString.insert(priceString.begin(), NUM_SCREENS - priceString.length(), ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alwaysShowSats || currencySymbol != CURRENCY_USD || price >= 100000000) // no time anymore when earlier than 1
|
if (currencySymbol != CURRENCY_USD || price >= 100000000) // no time anymore when earlier than 1
|
||||||
ret[0] = "SATS/" + currencyCode;
|
ret[0] = "SATS/" + getCurrencyCode(currencySymbol);
|
||||||
else
|
else
|
||||||
ret[0] = "MSCW/TIME";
|
ret[0] = "MSCW/TIME";
|
||||||
|
|
||||||
|
@ -233,80 +183,6 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
std::array<std::string, NUM_SCREENS> formatMarketCap(std::uint32_t blockHeight, std::uint32_t price, char currencySymbol, const std::string& currencyCode, bool bigChars)
|
|
||||||
{
|
|
||||||
std::array<std::string, NUM_SCREENS> ret;
|
|
||||||
std::uint32_t firstIndex = 0;
|
|
||||||
double supply = getSupplyAtBlock(blockHeight);
|
|
||||||
uint64_t marketCap = static_cast<std::uint64_t>(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<std::string, NUM_SCREENS> 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<std::string, NUM_SCREENS> parsePriceData(std::uint32_t price, const std::string& currencyCode, bool useSuffixFormat, bool mowMode, bool shareDot)
|
|
||||||
{
|
|
||||||
// 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<std::string, NUM_SCREENS> parseSatsPerCurrency(std::uint32_t price, char currencySymbol, bool withSatsSymbol)
|
|
||||||
{
|
|
||||||
return formatSatsPerCurrency(price, currencySymbol, getCurrencyCode(currencySymbol), withSatsSymbol, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::array<std::string, NUM_SCREENS> parseSatsPerCurrency(std::uint32_t price, const std::string& currencyCode, bool withSatsSymbol)
|
|
||||||
{
|
|
||||||
return formatSatsPerCurrency(price, getCurrencyChar(currencyCode), currencyCode, withSatsSymbol, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<std::string, NUM_SCREENS> parseBlockHeight(std::uint32_t blockHeight)
|
std::array<std::string, NUM_SCREENS> parseBlockHeight(std::uint32_t blockHeight)
|
||||||
|
@ -397,13 +273,53 @@ std::array<std::string, NUM_SCREENS> parseHalvingCountdown(std::uint32_t blockHe
|
||||||
|
|
||||||
std::array<std::string, NUM_SCREENS> parseMarketCap(std::uint32_t blockHeight, std::uint32_t price, char currencySymbol, bool bigChars)
|
std::array<std::string, NUM_SCREENS> parseMarketCap(std::uint32_t blockHeight, std::uint32_t price, char currencySymbol, bool bigChars)
|
||||||
{
|
{
|
||||||
return formatMarketCap(blockHeight, price, currencySymbol, getCurrencyCode(currencySymbol), bigChars);
|
std::array<std::string, NUM_SCREENS> ret;
|
||||||
}
|
std::uint32_t firstIndex = 0;
|
||||||
|
double supply = getSupplyAtBlock(blockHeight);
|
||||||
|
uint64_t marketCap = static_cast<std::uint64_t>(supply * double(price));
|
||||||
|
|
||||||
std::array<std::string, NUM_SCREENS> parseMarketCap(std::uint32_t blockHeight, std::uint32_t price, const std::string& currencyCode, bool bigChars)
|
ret[0] = getCurrencyCode(currencySymbol) + "/MCAP";
|
||||||
{
|
|
||||||
char currencyChar = getCurrencyChar(currencyCode);
|
if (bigChars)
|
||||||
return formatMarketCap(blockHeight, price, currencyChar, currencyCode, 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__
|
#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)
|
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));
|
return arrayToStringArray(parsePriceData(price, currencySymbol[0], useSuffixFormat, mowMode, shareDot));
|
||||||
} else {
|
|
||||||
return arrayToStringArray(parsePriceData(price, currencySymbol, useSuffixFormat, mowMode, shareDot));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emscripten::val parseHalvingCountdownArray(std::uint32_t blockHeight, bool asBlocks)
|
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)
|
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));
|
return arrayToStringArray(parseMarketCap(blockHeight, price, currencySymbol[0], bigChars));
|
||||||
} else {
|
|
||||||
return arrayToStringArray(parseMarketCap(blockHeight, price, currencySymbol, bigChars));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emscripten::val parseBlockFeesArray(std::uint16_t blockFees)
|
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)
|
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));
|
return arrayToStringArray(parseSatsPerCurrency(price, currencySymbol[0], withSatsSymbol));
|
||||||
} else {
|
|
||||||
return arrayToStringArray(parseSatsPerCurrency(price, currencySymbol, withSatsSymbol));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EMSCRIPTEN_BINDINGS(my_module)
|
EMSCRIPTEN_BINDINGS(my_module)
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <sstream>
|
|
||||||
#include <iomanip>
|
|
||||||
|
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
|
||||||
|
@ -14,41 +12,6 @@ const char CURRENCY_GBP = ']';
|
||||||
const char CURRENCY_JPY = '^';
|
const char CURRENCY_JPY = '^';
|
||||||
const char CURRENCY_AUD = '_';
|
const char CURRENCY_AUD = '_';
|
||||||
const char CURRENCY_CAD = '`';
|
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_USD = "USD";
|
||||||
const std::string CURRENCY_CODE_EUR = "EUR";
|
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_JPY = "JPY";
|
||||||
const std::string CURRENCY_CODE_AUD = "AUD";
|
const std::string CURRENCY_CODE_AUD = "AUD";
|
||||||
const std::string CURRENCY_CODE_CAD = "CAD";
|
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<std::string, NUM_SCREENS> parsePriceData(std::uint32_t price, char currency, bool useSuffixFormat = false, bool mowMode = false, bool shareDot = false);
|
std::array<std::string, NUM_SCREENS> parsePriceData(std::uint32_t price, char currency, bool useSuffixFormat = false, bool mowMode = false, bool shareDot = false);
|
||||||
std::array<std::string, NUM_SCREENS> parsePriceData(std::uint32_t price, const std::string& currencyCode, bool useSuffixFormat = false, bool mowMode = false, bool shareDot = false);
|
|
||||||
std::array<std::string, NUM_SCREENS> parseSatsPerCurrency(std::uint32_t price, char currencySymbol, bool withSatsSymbol);
|
std::array<std::string, NUM_SCREENS> parseSatsPerCurrency(std::uint32_t price, char currencySymbol, bool withSatsSymbol);
|
||||||
std::array<std::string, NUM_SCREENS> parseSatsPerCurrency(std::uint32_t price, const std::string& currencyCode, bool withSatsSymbol);
|
|
||||||
std::array<std::string, NUM_SCREENS> parseBlockHeight(std::uint32_t blockHeight);
|
std::array<std::string, NUM_SCREENS> parseBlockHeight(std::uint32_t blockHeight);
|
||||||
std::array<std::string, NUM_SCREENS> parseHalvingCountdown(std::uint32_t blockHeight, bool asBlocks);
|
std::array<std::string, NUM_SCREENS> parseHalvingCountdown(std::uint32_t blockHeight, bool asBlocks);
|
||||||
std::array<std::string, NUM_SCREENS> parseMarketCap(std::uint32_t blockHeight, std::uint32_t price, char currencySymbol, bool bigChars);
|
std::array<std::string, NUM_SCREENS> parseMarketCap(std::uint32_t blockHeight, std::uint32_t price, char currencySymbol, bool bigChars);
|
||||||
std::array<std::string, NUM_SCREENS> parseMarketCap(std::uint32_t blockHeight, std::uint32_t price, const std::string& currencyCode, bool bigChars);
|
|
||||||
std::array<std::string, NUM_SCREENS> parseBlockFees(std::uint16_t blockFees);
|
std::array<std::string, NUM_SCREENS> parseBlockFees(std::uint16_t blockFees);
|
||||||
|
|
||||||
char getCurrencySymbol(char input);
|
char getCurrencySymbol(char input);
|
||||||
std::string getCurrencyCode(char input);
|
std::string getCurrencyCode(char input);
|
||||||
char getCurrencyChar(const std::string& input);
|
char getCurrencyChar(const std::string& input);
|
||||||
|
|
||||||
// Private helper methods
|
|
||||||
namespace {
|
|
||||||
std::array<std::string, NUM_SCREENS> formatPriceData(std::uint32_t price, char currencySymbol, const std::string& currencyCode, bool useSuffixFormat, bool mowMode, bool shareDot, bool useSymbol = true);
|
|
||||||
std::array<std::string, NUM_SCREENS> formatSatsPerCurrency(std::uint32_t price, char currencySymbol, const std::string& currencyCode, bool withSatsSymbol, bool alwaysShowSats = false);
|
|
||||||
std::array<std::string, NUM_SCREENS> formatMarketCap(std::uint32_t blockHeight, std::uint32_t price, char currencySymbol, const std::string& currencyCode, bool bigChars);
|
|
||||||
}
|
|
|
@ -37,8 +37,8 @@ build_unflags =
|
||||||
-fno-exceptions
|
-fno-exceptions
|
||||||
lib_deps =
|
lib_deps =
|
||||||
https://github.com/joltwallet/esp_littlefs.git#v1.16.4
|
https://github.com/joltwallet/esp_littlefs.git#v1.16.4
|
||||||
bblanchon/ArduinoJson@^7.3.1
|
bblanchon/ArduinoJson@^7.4.1
|
||||||
esp32async/ESPAsyncWebServer @ 3.7.4
|
esp32async/ESPAsyncWebServer @ 3.7.7
|
||||||
robtillaart/MCP23017@^0.9.1
|
robtillaart/MCP23017@^0.9.1
|
||||||
adafruit/Adafruit NeoPixel@^1.12.5
|
adafruit/Adafruit NeoPixel@^1.12.5
|
||||||
https://github.com/dsbaars/universal_pin#feature/mcp23017_rt
|
https://github.com/dsbaars/universal_pin#feature/mcp23017_rt
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "led_handler.hpp"
|
#include "led_handler.hpp"
|
||||||
#include "lnbits.hpp"
|
|
||||||
|
|
||||||
#define MAX_ATTEMPTS_WIFI_CONNECTION 20
|
#define MAX_ATTEMPTS_WIFI_CONNECTION 20
|
||||||
|
|
||||||
|
@ -394,10 +393,6 @@ void setupWebsocketClients(void *pvParameters)
|
||||||
{
|
{
|
||||||
DataSourceType dataSource = getDataSource();
|
DataSourceType dataSource = getDataSource();
|
||||||
|
|
||||||
if (preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED)) {
|
|
||||||
setupLnbits();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dataSource == BTCLOCK_SOURCE || dataSource == CUSTOM_SOURCE)
|
if (dataSource == BTCLOCK_SOURCE || dataSource == CUSTOM_SOURCE)
|
||||||
{
|
{
|
||||||
V2Notify::setupV2Notify();
|
V2Notify::setupV2Notify();
|
||||||
|
|
|
@ -100,7 +100,3 @@ enum DataSourceType {
|
||||||
#ifndef DEFAULT_BOOT_TEXT
|
#ifndef DEFAULT_BOOT_TEXT
|
||||||
#define DEFAULT_BOOT_TEXT "BTCLOCK"
|
#define DEFAULT_BOOT_TEXT "BTCLOCK"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DEFAULT_LNBITS_INSTANCE "demo.lnbits.com"
|
|
||||||
#define DEFAULT_LNBITS_HTTPS true
|
|
||||||
#define DEFAULT_LNBITS_ENABLED false
|
|
||||||
|
|
|
@ -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<std::string> 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<uint>();
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include <ArduinoJson.h>
|
|
||||||
#include <HTTPClient.h>
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#include "lib/screen_handler.hpp"
|
|
||||||
|
|
||||||
class LNBitsFetch {
|
|
||||||
private:
|
|
||||||
LNBitsFetch();
|
|
||||||
static LNBitsFetch* instance;
|
|
||||||
|
|
||||||
bool initialized;
|
|
||||||
TaskHandle_t taskHandle;
|
|
||||||
std::map<std::string, uint> priceMap;
|
|
||||||
std::map<std::string, unsigned long int> 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);
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "price_notify.hpp"
|
#include "price_notify.hpp"
|
||||||
|
|
||||||
const char *wsServerPrice = "wss://ws.coincap.io/prices?assets=bitcoin";
|
const char *wsServerPrice = "wss://ws.kraken.com/v2";
|
||||||
|
|
||||||
WebSocketsClient webSocket;
|
WebSocketsClient webSocket;
|
||||||
uint currentPrice = 90000;
|
uint currentPrice = 90000;
|
||||||
|
@ -14,7 +14,7 @@ void onWebsocketPriceEvent(WStype_t type, uint8_t * payload, size_t length);
|
||||||
|
|
||||||
void setupPriceNotify()
|
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) {
|
webSocket.onEvent([](WStype_t type, uint8_t * payload, size_t length) {
|
||||||
onWebsocketPriceEvent(type, payload, length);
|
onWebsocketPriceEvent(type, payload, length);
|
||||||
});
|
});
|
||||||
|
@ -32,7 +32,14 @@ void onWebsocketPriceEvent(WStype_t type, uint8_t * payload, size_t length) {
|
||||||
case WStype_CONNECTED:
|
case WStype_CONNECTED:
|
||||||
{
|
{
|
||||||
Serial.println("Connected to " + String(wsServerPrice));
|
Serial.println("Connected to " + String(wsServerPrice));
|
||||||
priceNotifyInit = true;
|
|
||||||
|
JsonDocument doc;
|
||||||
|
doc["method"] = "subscribe";
|
||||||
|
JsonObject params = doc["params"].to<JsonObject>();
|
||||||
|
params["channel"] = "ticker";
|
||||||
|
params["symbol"][0] = "BTC/USD";
|
||||||
|
|
||||||
|
webSocket.sendTXT(doc.as<String>().c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WStype_TEXT:
|
case WStype_TEXT:
|
||||||
|
@ -40,11 +47,13 @@ void onWebsocketPriceEvent(WStype_t type, uint8_t * payload, size_t length) {
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
deserializeJson(doc, (char *)payload);
|
deserializeJson(doc, (char *)payload);
|
||||||
|
|
||||||
if (doc["bitcoin"].is<JsonObject>())
|
if (doc["data"][0].is<JsonObject>())
|
||||||
{
|
{
|
||||||
if (currentPrice != doc["bitcoin"].as<long>())
|
float price = doc["data"][0]["last"].as<float>();
|
||||||
|
uint roundedPrice = round(price);
|
||||||
|
if (currentPrice != roundedPrice)
|
||||||
{
|
{
|
||||||
processNewPrice(doc["bitcoin"].as<long>(), CURRENCY_USD);
|
processNewPrice(roundedPrice, CURRENCY_USD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -89,28 +89,6 @@ bool ScreenHandler::handleCurrencyRotation(bool forward) {
|
||||||
std::vector<std::string> ac = getActiveCurrencies();
|
std::vector<std::string> ac = getActiveCurrencies();
|
||||||
if (ac.empty()) return false;
|
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());
|
std::string curCode = getCurrencyCode(getCurrentCurrency());
|
||||||
auto it = std::find(ac.begin(), ac.end(), curCode);
|
auto it = std::find(ac.begin(), ac.end(), curCode);
|
||||||
|
|
||||||
|
@ -130,7 +108,6 @@ bool ScreenHandler::handleCurrencyRotation(bool forward) {
|
||||||
setCurrentScreen(getCurrentScreen());
|
setCurrentScreen(getCurrentScreen());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// If we're at the last/first currency of current screen, let nextScreen/previousScreen handle it
|
// If we're at the last/first currency of current screen, let nextScreen/previousScreen handle it
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -264,40 +241,19 @@ void workerTask(void *pvParameters) {
|
||||||
|
|
||||||
case TASK_PRICE_UPDATE: {
|
case TASK_PRICE_UPDATE: {
|
||||||
uint currency = ScreenHandler::getCurrentCurrency();
|
uint currency = ScreenHandler::getCurrentCurrency();
|
||||||
|
uint price = getPrice(currency);
|
||||||
uint price;
|
|
||||||
if (preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED)) {
|
|
||||||
price = LNBitsFetch::getInstance().getPrice(LNBitsFetch::getInstance().getCurrentCurrency());
|
|
||||||
} else {
|
|
||||||
price = getPrice(currency);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentScreenValue == SCREEN_BTC_TICKER) {
|
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),
|
taskEpdContent = parsePriceData(price, currency, preferences.getBool("suffixPrice", DEFAULT_SUFFIX_PRICE),
|
||||||
preferences.getBool("mowMode", DEFAULT_MOW_MODE),
|
preferences.getBool("mowMode", DEFAULT_MOW_MODE),
|
||||||
preferences.getBool("suffixShareDot", DEFAULT_SUFFIX_SHARE_DOT)
|
preferences.getBool("suffixShareDot", DEFAULT_SUFFIX_SHARE_DOT)
|
||||||
);
|
);
|
||||||
}
|
|
||||||
} else if (currentScreenValue == SCREEN_SATS_PER_CURRENCY) {
|
} 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 {
|
} else {
|
||||||
auto& blockNotify = BlockNotify::getInstance();
|
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);
|
EPDManager::getInstance().setContent(taskEpdContent);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#include "timers.hpp"
|
#include "timers.hpp"
|
||||||
#include "led_handler.hpp"
|
#include "led_handler.hpp"
|
||||||
#include "lnbits.hpp"
|
|
||||||
|
|
||||||
esp_timer_handle_t screenRotateTimer;
|
esp_timer_handle_t screenRotateTimer;
|
||||||
esp_timer_handle_t minuteTimer;
|
esp_timer_handle_t minuteTimer;
|
||||||
|
@ -80,11 +79,6 @@ void IRAM_ATTR minuteTimerISR(void *arg) {
|
||||||
vTaskNotifyGiveFromISR(miningPoolHandle, &xHigherPriorityTaskWoken);
|
vTaskNotifyGiveFromISR(miningPoolHandle, &xHigherPriorityTaskWoken);
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskHandle_t lnbitsHandle = LNBitsFetch::getInstance().getTaskHandle();
|
|
||||||
if (lnbitsHandle != NULL) {
|
|
||||||
vTaskNotifyGiveFromISR(lnbitsHandle, &xHigherPriorityTaskWoken);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xHigherPriorityTaskWoken == pdTRUE) {
|
if (xHigherPriorityTaskWoken == pdTRUE) {
|
||||||
portYIELD_FROM_ISR();
|
portYIELD_FROM_ISR();
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,6 @@ namespace V2Notify
|
||||||
|
|
||||||
buffer = new uint8_t[responseLength];
|
buffer = new uint8_t[responseLength];
|
||||||
|
|
||||||
if (!preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED)) {
|
|
||||||
response["type"] = "subscribe";
|
response["type"] = "subscribe";
|
||||||
response["eventType"] = "price";
|
response["eventType"] = "price";
|
||||||
|
|
||||||
|
@ -88,11 +87,11 @@ namespace V2Notify
|
||||||
currenciesArray.add(str);
|
currenciesArray.add(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// response["currencies"] = currenciesArray;
|
||||||
responseLength = measureMsgPack(response);
|
responseLength = measureMsgPack(response);
|
||||||
buffer = new uint8_t[responseLength];
|
buffer = new uint8_t[responseLength];
|
||||||
serializeMsgPack(response, buffer, responseLength);
|
serializeMsgPack(response, buffer, responseLength);
|
||||||
webSocket.sendBIN(buffer, responseLength);
|
webSocket.sendBIN(buffer, responseLength);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WStype_TEXT:
|
case WStype_TEXT:
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
static const char* JSON_CONTENT = "application/json";
|
static const char* JSON_CONTENT = "application/json";
|
||||||
|
|
||||||
static const char *const PROGMEM strSettings[] = {
|
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"};
|
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",
|
"mempoolSecure", "bitaxeEnabled",
|
||||||
"miningPoolStats", "verticalDesc",
|
"miningPoolStats", "verticalDesc",
|
||||||
"nostrZapNotify", "httpAuthEnabled",
|
"nostrZapNotify", "httpAuthEnabled",
|
||||||
"enableDebugLog", "ceDisableSSL", "dndEnabled", "dndTimeBasedEnabled", "lnbitsEnabled", "lnbitsHttps"};
|
"enableDebugLog", "ceDisableSSL", "dndEnabled", "dndTimeBasedEnabled"};
|
||||||
|
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
AsyncEventSource events("/events");
|
AsyncEventSource events("/events");
|
||||||
|
@ -252,15 +252,9 @@ JsonDocument getStatusObject()
|
||||||
conStatus["blocks"] = blockNotify.isConnected();
|
conStatus["blocks"] = blockNotify.isConnected();
|
||||||
conStatus["V2"] = V2Notify::isV2NotifyConnected();
|
conStatus["V2"] = V2Notify::isV2NotifyConnected();
|
||||||
conStatus["nostr"] = nostrConnected();
|
conStatus["nostr"] = nostrConnected();
|
||||||
conStatus["lnbits"] = LNBitsFetch::getInstance().isInitialized();
|
|
||||||
|
|
||||||
root["rssi"] = WiFi.RSSI();
|
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
|
#ifdef HAS_FRONTLIGHT
|
||||||
std::vector<uint16_t> statuses = ledHandler.frontlightGetStatus();
|
std::vector<uint16_t> statuses = ledHandler.frontlightGetStatus();
|
||||||
|
@ -304,7 +298,13 @@ JsonDocument getLedStatusObject()
|
||||||
uint blue = pixColor & 0xFF;
|
uint blue = pixColor & 0xFF;
|
||||||
char hexColor[8];
|
char hexColor[8];
|
||||||
snprintf(hexColor, sizeof(hexColor), "#%02X%02X%02X", red, green, blue);
|
snprintf(hexColor, sizeof(hexColor), "#%02X%02X%02X", red, green, blue);
|
||||||
colors.add(hexColor);
|
// colors.add(hexColor);
|
||||||
|
|
||||||
|
JsonObject object = colors.add<JsonObject>();
|
||||||
|
object["red"] = red;
|
||||||
|
object["green"] = green;
|
||||||
|
object["blue"] = blue;
|
||||||
|
object["hex"] = hexColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
|
@ -719,12 +719,6 @@ void onApiSettingsGet(AsyncWebServerRequest *request)
|
||||||
root["ledFlashOnZap"] = preferences.getBool("ledFlashOnZap", DEFAULT_LED_FLASH_ON_ZAP);
|
root["ledFlashOnZap"] = preferences.getBool("ledFlashOnZap", DEFAULT_LED_FLASH_ON_ZAP);
|
||||||
root["fontName"] = preferences.getString("fontName", DEFAULT_FONT_NAME);
|
root["fontName"] = preferences.getString("fontName", DEFAULT_FONT_NAME);
|
||||||
root["availableFonts"] = FontNames::getAvailableFonts();
|
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)
|
// Custom endpoint settings (only used for CUSTOM_SOURCE)
|
||||||
root["customEndpoint"] = preferences.getString("customEndpoint", DEFAULT_CUSTOM_ENDPOINT);
|
root["customEndpoint"] = preferences.getString("customEndpoint", DEFAULT_CUSTOM_ENDPOINT);
|
||||||
root["customEndpointDisableSSL"] = preferences.getBool("customEndpointDisableSSL", DEFAULT_CUSTOM_ENDPOINT_DISABLE_SSL);
|
root["customEndpointDisableSSL"] = preferences.getBool("customEndpointDisableSSL", DEFAULT_CUSTOM_ENDPOINT_DISABLE_SSL);
|
||||||
|
@ -929,7 +923,6 @@ void onApiStopDataSources(AsyncWebServerRequest *request)
|
||||||
|
|
||||||
stopPriceNotify();
|
stopPriceNotify();
|
||||||
BlockNotify::getInstance().stop();
|
BlockNotify::getInstance().stop();
|
||||||
LNBitsFetch::getInstance().stop();
|
|
||||||
|
|
||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
|
@ -941,9 +934,6 @@ void onApiRestartDataSources(AsyncWebServerRequest *request)
|
||||||
|
|
||||||
restartPriceNotify();
|
restartPriceNotify();
|
||||||
BlockNotify::getInstance().restart();
|
BlockNotify::getInstance().restart();
|
||||||
if (preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED)) {
|
|
||||||
LNBitsFetch::getInstance().restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
|
@ -1093,17 +1083,10 @@ void onApiShowCurrency(AsyncWebServerRequest *request)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// LNbits: set currency using a string
|
|
||||||
if (preferences.getBool("lnbitsEnabled", DEFAULT_LNBITS_ENABLED)) {
|
|
||||||
LNBitsFetch::getInstance().setCurrentCurrency(currency);
|
|
||||||
ScreenHandler::setCurrentScreen(ScreenHandler::getCurrentScreen());
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Normal situation: set currency using a char
|
|
||||||
char curChar = getCurrencyChar(currency);
|
char curChar = getCurrencyChar(currency);
|
||||||
|
|
||||||
ScreenHandler::setCurrentCurrency(curChar);
|
ScreenHandler::setCurrentCurrency(curChar);
|
||||||
ScreenHandler::setCurrentScreen(ScreenHandler::getCurrentScreen());
|
ScreenHandler::setCurrentScreen(ScreenHandler::getCurrentScreen());
|
||||||
}
|
|
||||||
|
|
||||||
request->send(HTTP_OK);
|
request->send(HTTP_OK);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -8,11 +8,6 @@
|
||||||
#include <ESPmDNS.h>
|
#include <ESPmDNS.h>
|
||||||
#include "AsyncJson.h"
|
#include "AsyncJson.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <AsyncTCP.h>
|
|
||||||
#include <ESPmDNS.h>
|
|
||||||
#include <Update.h>
|
|
||||||
#include <WiFi.h>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "lib/block_notify.hpp"
|
#include "lib/block_notify.hpp"
|
||||||
#include "lib/led_handler.hpp"
|
#include "lib/led_handler.hpp"
|
||||||
|
@ -20,11 +15,6 @@
|
||||||
#include "lib/screen_handler.hpp"
|
#include "lib/screen_handler.hpp"
|
||||||
#include "webserver/OneParamRewrite.hpp"
|
#include "webserver/OneParamRewrite.hpp"
|
||||||
#include "lib/mining_pool/pool_factory.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;
|
extern TaskHandle_t eventSourceTaskHandle;
|
||||||
|
|
||||||
|
|
|
@ -36,15 +36,12 @@ void test_CorrectSatsPerDollarConversion(void)
|
||||||
void test_SatsPerDollarAfter1B(void)
|
void test_SatsPerDollarAfter1B(void)
|
||||||
{
|
{
|
||||||
std::array<std::string, NUM_SCREENS> output = parseSatsPerCurrency(120000000, CURRENCY_USD, false);
|
std::array<std::string, NUM_SCREENS> output = parseSatsPerCurrency(120000000, CURRENCY_USD, false);
|
||||||
|
TEST_ASSERT_EQUAL_STRING("SATS/USD", output[0].c_str());
|
||||||
std::string joined = joinArrayWithBrackets(output);
|
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_MESSAGE("SATS/USD", output[0].c_str(), joined.c_str());
|
TEST_ASSERT_EQUAL_STRING("8", output[NUM_SCREENS - 3].c_str());
|
||||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("0", output[NUM_SCREENS - 5].c_str(), joined.c_str());
|
TEST_ASSERT_EQUAL_STRING("3", output[NUM_SCREENS - 2].c_str());
|
||||||
TEST_ASSERT_EQUAL_STRING_MESSAGE(".", output[NUM_SCREENS - 4].c_str(), joined.c_str());
|
TEST_ASSERT_EQUAL_STRING("3", output[NUM_SCREENS - 1].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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_CorrectSatsPerPoundConversion(void)
|
void test_CorrectSatsPerPoundConversion(void)
|
||||||
|
@ -275,24 +272,6 @@ void test_Mcap1TrillionJpySmallChars(void)
|
||||||
TEST_ASSERT_EQUAL_STRING("000", output[NUM_SCREENS - 1].c_str());
|
TEST_ASSERT_EQUAL_STRING("000", output[NUM_SCREENS - 1].c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_PriceDataWithCurrencyCode(void)
|
|
||||||
{
|
|
||||||
std::array<std::string, NUM_SCREENS> output = parsePriceData(10000, "PYG", false, false, false);
|
|
||||||
TEST_ASSERT_EQUAL_STRING("BTC/PYG", output[0].c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_SatsPerCurrencyWithCurrencyCode(void)
|
|
||||||
{
|
|
||||||
std::array<std::string, NUM_SCREENS> output = parseSatsPerCurrency(100000, "ZAR", false);
|
|
||||||
TEST_ASSERT_EQUAL_STRING("SATS/ZAR", output[0].c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_McapWithCurrencyCode(void)
|
|
||||||
{
|
|
||||||
std::array<std::string, NUM_SCREENS> output = parseMarketCap(100000, 10000, "PYG", true);
|
|
||||||
TEST_ASSERT_EQUAL_STRING("PYG/MCAP", output[0].c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// not needed when using generate_test_runner.rb
|
// not needed when using generate_test_runner.rb
|
||||||
int runUnityTests(void)
|
int runUnityTests(void)
|
||||||
{
|
{
|
||||||
|
@ -316,9 +295,6 @@ int runUnityTests(void)
|
||||||
RUN_TEST(test_PriceSuffixModeCompact2);
|
RUN_TEST(test_PriceSuffixModeCompact2);
|
||||||
RUN_TEST(test_PriceSuffixModeMow);
|
RUN_TEST(test_PriceSuffixModeMow);
|
||||||
RUN_TEST(test_PriceSuffixModeMowCompact);
|
RUN_TEST(test_PriceSuffixModeMowCompact);
|
||||||
RUN_TEST(test_PriceDataWithCurrencyCode);
|
|
||||||
RUN_TEST(test_SatsPerCurrencyWithCurrencyCode);
|
|
||||||
RUN_TEST(test_McapWithCurrencyCode);
|
|
||||||
|
|
||||||
return UNITY_END();
|
return UNITY_END();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue