commit 7f3338515b3f033ff5c9e2deeda1357cfda9a647 parent 90a5a9a3e7129d805c7fe9db974b72d30c2fb9ac Author: Marc Stibane <marc@taler.net> Date: Sun, 7 Sep 2025 08:05:32 +0200 optional oimEuro for KUDOS Diffstat:
12 files changed, 48 insertions(+), 22 deletions(-)
diff --git a/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift b/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift @@ -33,7 +33,8 @@ struct RequestPayment: View { selectedBalance: Balance?, amountLastUsed: Binding<Amount>, summary: Binding<String>, - iconID: Binding<String?> + iconID: Binding<String?>, + oimEuro: Bool ) { // SwiftUI ensures that the initialization uses the // closure only once during the lifetime of the view, so @@ -43,7 +44,7 @@ struct RequestPayment: View { self._amountLastUsed = amountLastUsed self._summary = summary self._iconID = iconID - let oimCurrency = oimCurrency(selectedBalance?.scopeInfo) // might be nil ==> OIMeuros + let oimCurrency = oimCurrency(selectedBalance?.scopeInfo, oimEuro: oimEuro) // might be nil ==> OIMeuros let oimCash = OIMcash(oimCurrency) self._cash = StateObject(wrappedValue: { oimCash }()) } diff --git a/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift b/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift @@ -19,6 +19,7 @@ struct SendAmountV: View { @Binding var amountLastUsed: Amount @Binding var summary: String @Binding var iconID: String? + let oimEuro: Bool @EnvironmentObject private var controller: Controller @EnvironmentObject private var model: WalletModel @@ -36,7 +37,8 @@ struct SendAmountV: View { selectedBalance: Binding<Balance?>, amountLastUsed: Binding<Amount>, summary: Binding<String>, - iconID: Binding<String?> + iconID: Binding<String?>, + oimEuro: Bool ) { // SwiftUI ensures that the initialization uses the // closure only once during the lifetime of the view, so @@ -46,7 +48,8 @@ struct SendAmountV: View { self._amountLastUsed = amountLastUsed self._summary = summary self._iconID = iconID - let oimCurrency = oimCurrency(selectedBalance.wrappedValue?.scopeInfo) // might be nil ==> OIMeuros + self.oimEuro = oimEuro + let oimCurrency = oimCurrency(selectedBalance.wrappedValue?.scopeInfo, oimEuro: oimEuro) // might be nil ==> OIMeuros let oimCash = OIMcash(oimCurrency) self._cash = StateObject(wrappedValue: { oimCash }()) } @@ -87,7 +90,7 @@ struct SendAmountV: View { amountAvailable = balance.available } print("🚩SendAmountV.newBalance() set selectedBalance and cash.currency") - let oimCurrency = oimCurrency(balance.scopeInfo) // might be nil ==> OIMeuros + let oimCurrency = oimCurrency(balance.scopeInfo, oimEuro: oimEuro) // might be nil ==> OIMeuros selectedBalance = balance cash.currency = oimCurrency } @@ -194,7 +197,8 @@ fileprivate struct Preview_Content: View { selectedBalance: $noBalance, amountLastUsed: $amountToPreview, summary: $summary, - iconID: $iconID) + iconID: $iconID, + oimEuro: false) } } diff --git a/TalerWallet1/Views/Balances/BalancesListView.swift b/TalerWallet1/Views/Balances/BalancesListView.swift @@ -21,6 +21,7 @@ struct BalancesListView: View { @EnvironmentObject private var model: WalletModel @EnvironmentObject private var controller: Controller @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic + @AppStorage("oimEuro") var oimEuro: Bool = false @State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING) // Update currency when used @State private var summary = EMPTYSTRING @@ -91,7 +92,8 @@ struct BalancesListView: View { OIMbalances(stack: stack.push(), selectedBalance: $selectedBalance, // set to user choice qrButtonTapped: $qrButtonTapped, - historyTapped: $historyTapped) + historyTapped: $historyTapped, + oimEuro: oimEuro) .environmentObject(NamespaceWrapper(namespace)) // keep OIMviews apart } } } diff --git a/TalerWallet1/Views/Balances/BalancesPendingRowV.swift b/TalerWallet1/Views/Balances/BalancesPendingRowV.swift @@ -17,6 +17,8 @@ struct BalancesPendingRowV: View { @Binding var pendingTransactions: [TalerTransaction] let reloadPending: (_ stack: CallStack) async -> () + @AppStorage("oimEuro") var oimEuro: Bool = false + @ViewBuilder func pendingRowLabel() -> some View { let pendingIncoming = balance.pendingIncoming let hasIncoming = !pendingIncoming.isZero @@ -65,6 +67,7 @@ struct BalancesPendingRowV: View { balance: balance, selectedBalance: $selectedBalance, // set in there navTitle: String(localized: "Pending", comment: "ViewTitle of TransactionList"), + oimEuro: oimEuro, transactions: $pendingTransactions, reloadAllAction: reloadPending) NavigationLink(destination: destination) { pendingRowLabel() } diff --git a/TalerWallet1/Views/Balances/BalancesSectionView.swift b/TalerWallet1/Views/Balances/BalancesSectionView.swift @@ -37,6 +37,7 @@ struct BalancesSectionView { @AppStorage("developerMode") var developerMode: Bool = false #endif @AppStorage("minimalistic") var minimalistic: Bool = false + @AppStorage("oimEuro") var oimEuro: Bool = false @State private var showSpendingHint = true @State private var isShowingDetailView = false @@ -98,6 +99,7 @@ extension BalancesSectionView: View { balance: balance, selectedBalance: $selectedBalance, navTitle: balance.available.readableDescription, // TODO: format with currency sign + oimEuro: oimEuro, transactions: $completedTransactions, reloadAllAction: loadCompleted) Section { diff --git a/TalerWallet1/Views/Main/MainView.swift b/TalerWallet1/Views/Main/MainView.swift @@ -342,6 +342,7 @@ extension MainView { @AppStorage("developerMode") var developerMode: Bool = false #endif @AppStorage("minimalistic") var minimalistic: Bool = false + @AppStorage("oimEuro") var oimEuro: Bool = false @State private var shouldReloadBalances = 0 @State private var shouldReloadTransactions = 0 @@ -410,12 +411,14 @@ extension MainView { selectedBalance: $selectedBalance, // if nil shows currency picker amountLastUsed: $amountLastUsed, // currency needs to be updated! summary: $summary, - iconID: $iconID) + iconID: $iconID, + oimEuro: oimEuro) let requestDest = RequestPayment(stack: stack.push(Self.name), selectedBalance: selectedBalance, amountLastUsed: $amountLastUsed, // currency needs to be updated! summary: $summary, - iconID: $iconID) + iconID: $iconID, + oimEuro: oimEuro) let depositDest = DepositSelectV(stack: stack.push(Self.name), selectedBalance: selectedBalance, amountLastUsed: $amountLastUsed) diff --git a/TalerWallet1/Views/OIM/OIMbalances.swift b/TalerWallet1/Views/OIM/OIMbalances.swift @@ -33,6 +33,7 @@ struct OIMbalances: View { @Binding var selectedBalance: Balance? // return user's choice @Binding var qrButtonTapped: Bool @Binding var historyTapped: Int? + let oimEuro: Bool @EnvironmentObject private var controller: Controller @EnvironmentObject private var wrapper: NamespaceWrapper @@ -48,14 +49,15 @@ struct OIMbalances: View { init(stack: CallStack, selectedBalance: Binding<Balance?>, qrButtonTapped: Binding<Bool>, - historyTapped: Binding<Int?> + historyTapped: Binding<Int?>, + oimEuro: Bool ) { self.stack = stack self._selectedBalance = selectedBalance self._qrButtonTapped = qrButtonTapped self._historyTapped = historyTapped - - let oimCurrency = oimCurrency(selectedBalance.wrappedValue?.scopeInfo) // might be nil ==> OIMeuros + self.oimEuro = oimEuro + let oimCurrency = oimCurrency(selectedBalance.wrappedValue?.scopeInfo, oimEuro: oimEuro) // might be nil ==> OIMeuros let oimCash = OIMcash(oimCurrency) self._cash = StateObject(wrappedValue: { oimCash }()) } @@ -239,7 +241,7 @@ struct OIMbalances: View { Spacer() HStack(spacing: 30) { ForEach(Array(controller.balances.enumerated()), id: \.element) { index, balance in - let oimCurrency = oimCurrency(balance.scopeInfo) + let oimCurrency = oimCurrency(balance.scopeInfo, oimEuro: oimEuro) let itsMe = selectedBalance == balance let isClosed = selectedBalance == nil let size = isClosed ? 160.0 : OIMbuttonSize diff --git a/TalerWallet1/Views/OIM/OIMcurrency.swift b/TalerWallet1/Views/OIM/OIMcurrency.swift @@ -12,9 +12,10 @@ public typealias OIMnotesCoins = (OIMdenominations, OIMdenominations) // n public let OIMcurrencies = [OIMeuros, OIMleones, OIMxofN, OIMfrancs] -func oimCurrency(_ scopeInfo: ScopeInfo?) -> OIMcurrency { +func oimCurrency(_ scopeInfo: ScopeInfo?, oimEuro: Bool) -> OIMcurrency { let currency = scopeInfo?.currency if currency == DEMOCURRENCY { // map KUDOS to Leones + if oimEuro { return OIMcurrencies[0] } return OIMcurrencies[1] } else if currency == TESTCURRENCY { // map TESTKUDOS to CFA return OIMcurrencies[2] diff --git a/TalerWallet1/Views/Settings/SettingsView.swift b/TalerWallet1/Views/Settings/SettingsView.swift @@ -47,6 +47,7 @@ struct SettingsView: View { @AppStorage("useAuthentication") var useAuthentication: Bool = false @AppStorage("showQRauto16") var showQRauto16: Bool = true @AppStorage("showQRauto17") var showQRauto17: Bool = false + @AppStorage("oimEuro") var oimEuro: Bool = false @State private var checkDisabled = false @State private var withDrawDisabled = false @@ -147,6 +148,12 @@ struct SettingsView: View { description: hideDescriptions ? nil : String(localized: "Backup your money...")) {} } #endif + +#if OIM + SettingsToggle(name: String(localized: "OIM: Euro"), value: $oimEuro, id1: "oimEuro", + description: minimalistic ? nil : String(localized: "OIM currency for KUDOS")) +#endif + SettingsToggle(name: String(localized: "Minimalistic"), value: $minimalistic, id1: "minimal", description: hideDescriptions ? nil : String(localized: "Omit text where possible")) { hideDescriptions = minimalistic //withAnimation { hideDescriptions = minimalistic } diff --git a/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift b/TalerWallet1/Views/Sheets/P2P_Sheets/P2pReceiveURIView.swift @@ -14,10 +14,9 @@ import SymLog struct P2pReceiveURIView: View { private let symLog = SymLogV(0) let stack: CallStack + let url: URL // the scanned URL + let oimEuro: Bool - // the scanned URL - let url: URL - @EnvironmentObject private var model: WalletModel @EnvironmentObject private var controller: Controller @Environment(\.colorScheme) private var colorScheme @@ -35,12 +34,12 @@ struct P2pReceiveURIView: View { let navTitle = String(localized: "Receive", comment: "Nav Title") // Since there is no selectedBalance, we cannot know which currency we'll need to render at this time - init(stack: CallStack, url: URL) { + init(stack: CallStack, url: URL, oimEuro: Bool) { self.stack = stack self.url = url self.oimEuro = oimEuro // let oimCurrency = oimCurrency(selectedBalance.wrappedValue?.scopeInfo) // might be nil ==> OIMeuros - let oimCurrency = oimCurrency(nil) // nil ==> OIMeuros + let oimCurrency = oimCurrency(nil, oimEuro: oimEuro) // nil ==> OIMeuros let oimCash = OIMcash(oimCurrency) self._cash = StateObject(wrappedValue: { oimCash }()) } @@ -52,7 +51,7 @@ struct P2pReceiveURIView: View { let baseUrl = ppResponse.exchangeBaseUrl exchange = try? await model.getExchangeByUrl(url: baseUrl) await controller.checkCurrencyInfo(for: baseUrl, model: model) - let oimCurrency = oimCurrency(ppResponse.scopeInfo) + let oimCurrency = oimCurrency(ppResponse.scopeInfo, oimEuro: oimEuro) cash.setCurrency(oimCurrency) peerPushCreditResponse = ppResponse } else { diff --git a/TalerWallet1/Views/Sheets/URLSheet.swift b/TalerWallet1/Views/Sheets/URLSheet.swift @@ -18,6 +18,7 @@ struct URLSheet: View { @EnvironmentObject private var controller: Controller @EnvironmentObject private var model: WalletModel @AppStorage("shouldShowWarning") var shouldShowWarning: Bool = true + @AppStorage("oimEuro") var oimEuro: Bool = false @State private var amountToTransfer = Amount.zero(currency: EMPTYSTRING) @State private var summary = EMPTYSTRING @@ -56,7 +57,7 @@ struct URLSheet: View { case .payPull: P2pPayURIView(stack: stack.push(), url: passedURL) case .payPush: - P2pReceiveURIView(stack: stack.push(), url: passedURL) + P2pReceiveURIView(stack: stack.push(), url: passedURL, oimEuro: oimEuro) case .payTemplate: PayTemplateV(stack: stack.push(), url: passedURL) case .refund: diff --git a/TalerWallet1/Views/Transactions/TransactionsListView.swift b/TalerWallet1/Views/Transactions/TransactionsListView.swift @@ -38,6 +38,7 @@ struct TransactionsListView: View { balance: Balance, selectedBalance: Binding<Balance?>, navTitle: String?, + oimEuro: Bool, transactions: Binding<[TalerTransaction]>, reloadAllAction: @escaping (_ stack: CallStack) async -> () ) { @@ -51,7 +52,7 @@ struct TransactionsListView: View { self._transactions = transactions self.reloadAllAction = reloadAllAction self._selectedBalance = selectedBalance - let oimCurrency = oimCurrency(balance.scopeInfo) + let oimCurrency = oimCurrency(balance.scopeInfo, oimEuro: oimEuro) let oimCash = OIMcash(oimCurrency) self._cash = StateObject(wrappedValue: { oimCash }()) }