[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-ios] 17/32: getCurrencySpecification
From: |
gnunet |
Subject: |
[taler-taler-ios] 17/32: getCurrencySpecification |
Date: |
Mon, 16 Oct 2023 00:03:15 +0200 |
This is an automated email from the git hooks/post-receive script.
marc-stibane pushed a commit to branch master
in repository taler-ios.
commit 608250ee9a2126147b9b4c133ac57c1db91a3b94
Author: Marc Stibane <marc@taler.net>
AuthorDate: Fri Oct 13 19:18:18 2023 +0200
getCurrencySpecification
---
TalerWallet1/Model/Model+Exchange.swift | 13 +++++------
taler-swift/Sources/taler-swift/Amount.swift | 34 +++++++++++++++++++++++-----
2 files changed, 34 insertions(+), 13 deletions(-)
diff --git a/TalerWallet1/Model/Model+Exchange.swift
b/TalerWallet1/Model/Model+Exchange.swift
index b5d6641..bf4a2ca 100644
--- a/TalerWallet1/Model/Model+Exchange.swift
+++ b/TalerWallet1/Model/Model+Exchange.swift
@@ -96,10 +96,9 @@ fileprivate struct AddExchange:
WalletBackendFormattedRequest {
}
/// A request to get info about a currency
-
-fileprivate struct GetScopedCurrencyInfo: WalletBackendFormattedRequest {
- typealias Response = ScopedCurrencyInfo
- func operation() -> String { return "getScopedCurrencyInfo" }
+fileprivate struct GetCurrencySpecification: WalletBackendFormattedRequest {
+ typealias Response = CurrencySpecification
+ func operation() -> String { return "getCurrencySpecification" }
func args() -> Args { return Args(scope: scope) }
var scope: ScopeInfo
@@ -130,9 +129,9 @@ extension WalletModel {
_ = try await sendRequest(request)
}
- @MainActor func getScopedCurrencyInfoM(scope: ScopeInfo)
- async throws -> ScopedCurrencyInfo { // M for MainActor
- let request = GetScopedCurrencyInfo(scope: scope)
+ @MainActor func getCurrencySpecificationM(scope: ScopeInfo)
+ async throws -> CurrencySpecification { // M for MainActor
+ let request = GetCurrencySpecification(scope: scope)
let response = try await sendRequest(request, ASYNCDELAY)
return response
}
diff --git a/taler-swift/Sources/taler-swift/Amount.swift
b/taler-swift/Sources/taler-swift/Amount.swift
index 2e91e6c..088e237 100644
--- a/taler-swift/Sources/taler-swift/Amount.swift
+++ b/taler-swift/Sources/taler-swift/Amount.swift
@@ -38,11 +38,33 @@ enum AmountError: Error {
case divideByZero
}
-public struct ScopedCurrencyInfo: Codable, Sendable {
+public struct CurrencySpecification: Codable, Sendable {
+ enum CodingKeys: String, CodingKey {
+ case decimalSeparator = "decimal_separator"
+ case name = "name"
+ case fractionalInputDigits = "num_fractional_input_digits"
+ case fractionalNormalDigits = "num_fractional_normal_digits"
+ case fractionalTrailingZeroDigits =
"num_fractional_trailing_zero_digits"
+ case isCurrencyNameLeading = "is_currency_name_leading"
+ case altUnitNames = "alt_unit_names"
+ }
+ /// e.g. “.” for $ and ¥; “,” for €
let decimalSeparator: String
- let numFractionalDigits: Int // 0 Yen, 2 €,$, 3 arabic
- let numTinyDigits: Int // SuperScriptDigits
+ /// some name for this CurrencySpecification
+ let name: String
+ /// how much digits the user may enter after the decimal separator
+ let fractionalInputDigits: Int
+ /// €,$,£: 2; some arabic currencies: 3, ¥: 0
+ let fractionalNormalDigits: Int
+ /// usually same as numFractionalNormalDigits, but e.g. might be 2 for ¥
+ let fractionalTrailingZeroDigits: Int
+ /// true for “$ 3.50”; false for “3,50 €”
let isCurrencyNameLeading: Bool
+ /// map of powers of 10 to alternative currency names / symbols
+ /// must always have an entry under "0" that defines the base name
+ /// e.g. "0 => €" or "3 => k€". For BTC, would be "0 => BTC, -3 => mBTC".
+ /// This way, we can also communicate the currency symbol to be used.
+ let altUnitNames: [Int : String]
}
/// A value of some currency.
@@ -69,7 +91,7 @@ public final class Amount: Codable, Hashable, @unchecked
Sendable, CustomStringC
var fraction: UInt32
/// Additional info for formatting currency strings
- var currencyInfo: ScopedCurrencyInfo?
+ var currencySpecification: CurrencySpecification?
public func hash(into hasher: inout Hasher) {
hasher.combine(currency)
@@ -96,8 +118,8 @@ public final class Amount: Codable, Hashable, @unchecked
Sendable, CustomStringC
/// The string representation of the value, formatted as
"`integer`.`fraction`".
public var valueStr: String {
var decimalSeparator = "."
- if let currencyInfo {
- decimalSeparator = currencyInfo.decimalSeparator
+ if let currencySpecification { // TODO: use locale
+ decimalSeparator = currencySpecification.decimalSeparator
}
if fraction == 0 {
return "\(integer)"
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-ios] branch master updated (bb640f0 -> 65313c5), gnunet, 2023/10/15
- [taler-taler-ios] 04/32: CallStack, gnunet, 2023/10/15
- [taler-taler-ios] 19/32: AccessibilityNotification.Announcement, gnunet, 2023/10/15
- [taler-taler-ios] 01/32: products seem no longer mandatory, gnunet, 2023/10/15
- [taler-taler-ios] 18/32: updateExchange, gnunet, 2023/10/15
- [taler-taler-ios] 14/32: fix bars, gnunet, 2023/10/15
- [taler-taler-ios] 03/32: Debugging, gnunet, 2023/10/15
- [taler-taler-ios] 17/32: getCurrencySpecification,
gnunet <=
- [taler-taler-ios] 02/32: Layout for QR-View and ThreeAmounts, gnunet, 2023/10/15
- [taler-taler-ios] 08/32: cleanup, gnunet, 2023/10/15
- [taler-taler-ios] 13/32: width of rendered string, gnunet, 2023/10/15
- [taler-taler-ios] 10/32: secret token, gnunet, 2023/10/15
- [taler-taler-ios] 15/32: TwoRowButtons, gnunet, 2023/10/15
- [taler-taler-ios] 05/32: No spellout, gnunet, 2023/10/15
- [taler-taler-ios] 09/32: TabBar for Taler Wallet - GNU Taler stays on SideView, gnunet, 2023/10/15
- [taler-taler-ios] 16/32: Source of Truth for balances, gnunet, 2023/10/15
- [taler-taler-ios] 30/32: font, gnunet, 2023/10/15
- [taler-taler-ios] 27/32: SingleAxisGeometryReader, gnunet, 2023/10/15