Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/CodexBar/PreferencesGeneralPane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ enum PreferredCurrencyOption: String, CaseIterable, Identifiable {
case usd = "USD"
case gbp = "GBP"
case eur = "EUR"
case czk = "CZK"
case cny = "CNY"
case jpy = "JPY"
case krw = "KRW"
Expand All @@ -100,6 +101,7 @@ enum PreferredCurrencyOption: String, CaseIterable, Identifiable {
case .usd: "USD ($)"
case .gbp: "GBP (£)"
case .eur: "EUR (€)"
case .czk: "CZK (Kč)"
case .cny: "CNY (¥)"
case .jpy: "JPY (¥)"
case .krw: "KRW (₩)"
Expand Down
3 changes: 2 additions & 1 deletion Sources/CodexBarCore/CurrencyExchange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class CurrencyExchange: @unchecked Sendable {

/// All currency codes supported by the converter.
public static let supportedCurrencies: [String] = [
"USD", "GBP", "EUR", "CNY", "JPY", "KRW", "CAD", "AUD", "HKD", "TWD", "SGD", "INR",
"USD", "GBP", "EUR", "CZK", "CNY", "JPY", "KRW", "CAD", "AUD", "HKD", "TWD", "SGD", "INR",
]

private let lock = NSLock()
Expand All @@ -25,6 +25,7 @@ public final class CurrencyExchange: @unchecked Sendable {
"USD": 1.0,
"GBP": 0.79,
"EUR": 0.92,
"CZK": 21.0,
"CNY": 7.27,
"JPY": 154.0,
"KRW": 1428.90,
Expand Down
7 changes: 7 additions & 0 deletions Tests/CodexBarTests/UsageFormatterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,12 @@ struct UsageFormatterTests {
#expect(explicitKRW.contains("₩"))
#expect(!explicitKRW.contains("."))

let czkRate = exchange.rate(for: "CZK") ?? 21.0
#expect(abs((exchange.convert(usdAmount: 10.0, to: "CZK") ?? 0) - 10.0 * czkRate) < epsilon)
let explicitCZK = UsageFormatter.convertedCostString(10.0, preferredCurrency: "CZK", providerCurrency: "USD")
#expect(explicitCZK.contains("CZK"))
#expect(explicitCZK.contains("."))

#expect(exchange.convert(amount: 10.0, from: "CHF", to: "USD") == nil)
let unavailable = UsageFormatter.convertedCostString(
10.0,
Expand All @@ -535,6 +541,7 @@ struct UsageFormatterTests {
#expect(CurrencyExchange.requiresLiveRates(preferredCurrencyCode: "GBP"))
#expect(CurrencyExchange.requiresLiveRates(preferredCurrencyCode: " eur "))
#expect(CurrencyExchange.requiresLiveRates(preferredCurrencyCode: "KRW"))
#expect(CurrencyExchange.requiresLiveRates(preferredCurrencyCode: "CZK"))
}

@Test
Expand Down