From 41b5fcf1c1938c4bac7e9cea53395c07e39ffaec Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Thu, 5 Dec 2024 04:32:32 +0100 Subject: [PATCH] Bugfix for suffix compact mode --- lib/btclock/data_handler.cpp | 9 +++++---- maintainers.yaml | 20 ++++++++++++++++++++ test/test_datahandler/test_main.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 maintainers.yaml diff --git a/lib/btclock/data_handler.cpp b/lib/btclock/data_handler.cpp index c1f1d1f..80e2328 100644 --- a/lib/btclock/data_handler.cpp +++ b/lib/btclock/data_handler.cpp @@ -90,10 +90,11 @@ std::array parsePriceData(std::uint32_t price, char cu firstIndex = 1; } - if (shareDot) + size_t dotPosition = priceString.find('.'); + + if (shareDot && dotPosition != std::string::npos && dotPosition > 0) { std::vector tempArray; - size_t dotPosition = priceString.find('.'); if (dotPosition != std::string::npos && dotPosition > 0) { for (size_t i = 0; i < priceString.length(); ++i) @@ -322,9 +323,9 @@ emscripten::val parseBlockHeightArray(std::uint32_t blockHeight) return arrayToStringArray(parseBlockHeight(blockHeight)); } -emscripten::val parsePriceDataArray(std::uint32_t price, const std::string ¤cySymbol, bool useSuffixFormat = false) +emscripten::val parsePriceDataArray(std::uint32_t price, const std::string ¤cySymbol, bool useSuffixFormat = false, bool mowMode = false, bool shareDot = false) { - return arrayToStringArray(parsePriceData(price, currencySymbol[0], useSuffixFormat)); + return arrayToStringArray(parsePriceData(price, currencySymbol[0], useSuffixFormat, mowMode, shareDot)); } emscripten::val parseHalvingCountdownArray(std::uint32_t blockHeight, bool asBlocks) diff --git a/maintainers.yaml b/maintainers.yaml new file mode 100644 index 0000000..8176c63 --- /dev/null +++ b/maintainers.yaml @@ -0,0 +1,20 @@ +identifier: BTClock +maintainers: +- npub1k5f85zx0xdskyayqpfpc0zq6n7vwqjuuxugkayk72fgynp34cs3qfcvqg2 +relays: +- wss://relay.noderunners.network/ +- wss://nostr.sathoarder.com/ +- wss://offchain.pub/ +- wss://nostr3.daedaluslabs.io/ +- wss://nostr4.daedaluslabs.io/ +- wss://nostr.dbtc.link/ +- wss://purplepag.es/ +- wss://nos.lol/ +- wss://nostr1.daedaluslabs.io/ +- wss://nostr.noderunners.network/ +- wss://nostr.lnbitcoin.cz/ +- wss://relay.primal.net/ +- wss://relay.damus.io +- wss://nostr-relay.derekross.me/ +- wss://nostr2.azzamo.net/ +- wss://nostr2.daedaluslabs.io/ diff --git a/test/test_datahandler/test_main.cpp b/test/test_datahandler/test_main.cpp index f2ad64c..6314f34 100644 --- a/test/test_datahandler/test_main.cpp +++ b/test/test_datahandler/test_main.cpp @@ -98,6 +98,30 @@ void test_PriceSuffixMode(void) TEST_ASSERT_EQUAL_STRING("K", output[NUM_SCREENS - 1].c_str()); } +void test_PriceSuffixModeCompact1(void) +{ + std::array output = parsePriceData(100000, '$', true, false, true); + TEST_ASSERT_EQUAL_STRING("BTC/USD", output[0].c_str()); + + TEST_ASSERT_EQUAL_STRING("$", output[NUM_SCREENS - 5].c_str()); + TEST_ASSERT_EQUAL_STRING("1", output[NUM_SCREENS - 4].c_str()); + TEST_ASSERT_EQUAL_STRING("0", output[NUM_SCREENS - 3].c_str()); + TEST_ASSERT_EQUAL_STRING("0", output[NUM_SCREENS - 2].c_str()); + TEST_ASSERT_EQUAL_STRING("K", output[NUM_SCREENS - 1].c_str()); +} + +void test_PriceSuffixModeCompact2(void) +{ + std::array output = parsePriceData(1000000, '$', true, false, true); + TEST_ASSERT_EQUAL_STRING("BTC/USD", output[0].c_str()); + + TEST_ASSERT_EQUAL_STRING("$", output[NUM_SCREENS - 5].c_str()); + TEST_ASSERT_EQUAL_STRING("1.", output[NUM_SCREENS - 4].c_str()); + TEST_ASSERT_EQUAL_STRING("0", output[NUM_SCREENS - 3].c_str()); + TEST_ASSERT_EQUAL_STRING("0", output[NUM_SCREENS - 2].c_str()); + TEST_ASSERT_EQUAL_STRING("M", output[NUM_SCREENS - 1].c_str()); +} + void test_PriceSuffixModeMow(void) { std::array output = parsePriceData(93000, '$', true, true); @@ -246,6 +270,8 @@ int runUnityTests(void) RUN_TEST(test_Mcap1TrillionJpy); RUN_TEST(test_Mcap1TrillionJpySmallChars); RUN_TEST(test_PriceSuffixMode); + RUN_TEST(test_PriceSuffixModeCompact1); + RUN_TEST(test_PriceSuffixModeCompact2); RUN_TEST(test_PriceSuffixModeMow); RUN_TEST(test_PriceSuffixModeMowCompact);