From f3f018741ce65d8b68787249ca2e0299ed0b628b Mon Sep 17 00:00:00 2001 From: Terry Yiu Date: Wed, 9 Sep 2026 08:57:19 +0300 Subject: [PATCH] Hide currency flags shared by more than 3 countries XCD, XOF, and XAF each have 6-8 issuing countries, which is too many flags to cram side by side next to a currency code. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01FXcrACM5sok3M1KQJ8kByy --- .../kotlin/xyz/tyiu/satsprice/CurrencyFlag.kt | 11 ++++++++--- .../kotlin/xyz/tyiu/satsprice/CurrencyFlagTest.kt | 14 ++++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/shared/src/commonMain/kotlin/xyz/tyiu/satsprice/CurrencyFlag.kt b/shared/src/commonMain/kotlin/xyz/tyiu/satsprice/CurrencyFlag.kt index bb322b2..9836323 100644 --- a/shared/src/commonMain/kotlin/xyz/tyiu/satsprice/CurrencyFlag.kt +++ b/shared/src/commonMain/kotlin/xyz/tyiu/satsprice/CurrencyFlag.kt @@ -12,17 +12,22 @@ private val MULTI_COUNTRY_CURRENCY_REGION_CODES: Map> = map "XPF" to listOf("NC", "PF", "WF"), ) +/** Above this many issuing countries, showing every flag side by side is too visually noisy. */ +private const val MAX_FLAGS_PER_CURRENCY = 3 + /** * A country flag emoji for [code], derived from the first two letters of the ISO 4217 code — * which double as the issuing country's ISO 3166-1 alpha-2 code for ordinary national * currencies — or null when there's no flag to show. [MULTI_COUNTRY_CURRENCY_REGION_CODES] * lists every country sharing a currency with no single issuer, so those show all their flags - * side by side; the remaining "X"-prefixed codes are precious metals, testing codes, and other - * non-national codes (XAU, XTS, XXX, ...), none of which has a country to show. EUR is a special - * case handled separately, using the EU's own flag. + * side by side, unless there are more than [MAX_FLAGS_PER_CURRENCY] of them; the remaining + * "X"-prefixed codes are precious metals, testing codes, and other non-national codes (XAU, XTS, + * XXX, ...), none of which has a country to show. EUR is a special case handled separately, using + * the EU's own flag. */ fun currencyFlagEmoji(code: String): String? { MULTI_COUNTRY_CURRENCY_REGION_CODES[code]?.let { regionCodes -> + if (regionCodes.size > MAX_FLAGS_PER_CURRENCY) return null return regionCodes.joinToString(" ") { regionFlagEmoji(it) } } if (code.startsWith("X")) return null diff --git a/shared/src/commonTest/kotlin/xyz/tyiu/satsprice/CurrencyFlagTest.kt b/shared/src/commonTest/kotlin/xyz/tyiu/satsprice/CurrencyFlagTest.kt index e1898c0..b089fc7 100644 --- a/shared/src/commonTest/kotlin/xyz/tyiu/satsprice/CurrencyFlagTest.kt +++ b/shared/src/commonTest/kotlin/xyz/tyiu/satsprice/CurrencyFlagTest.kt @@ -19,13 +19,19 @@ class CurrencyFlagTest { } @Test - fun currencyFlagEmoji_showsAllFlagsForCurrenciesSharedByMultipleCountries() { - assertEquals("🇦🇬 🇦🇮 🇩🇲 🇬🇩 🇰🇳 🇱🇨 🇲🇸 🇻🇨", currencyFlagEmoji("XCD")) - assertEquals("🇧🇫 🇧🇯 🇨🇮 🇬🇼 🇲🇱 🇳🇪 🇸🇳 🇹🇬", currencyFlagEmoji("XOF")) - assertEquals("🇨🇫 🇨🇬 🇨🇲 🇬🇦 🇬🇶 🇹🇩", currencyFlagEmoji("XAF")) + fun currencyFlagEmoji_showsAllFlagsForCurrenciesSharedByFewCountries() { + assertEquals("🇨🇼 🇸🇽", currencyFlagEmoji("XCG")) assertEquals("🇳🇨 🇵🇫 🇼🇫", currencyFlagEmoji("XPF")) } + @Test + fun currencyFlagEmoji_hidesFlagsForCurrenciesSharedByManyCountries() { + // Showing every flag side by side gets visually noisy past a few countries. + assertNull(currencyFlagEmoji("XCD")) // 8 countries + assertNull(currencyFlagEmoji("XOF")) // 8 countries + assertNull(currencyFlagEmoji("XAF")) // 6 countries + } + @Test fun currencyFlagEmoji_returnsNullForNonNationalCodes() { // ISO 4217 reserves the remaining "X"-prefixed codes for precious metals, testing codes,