commit 0d610ea036d05d198e095d049a5586bba7b19989
parent 37f368ae5ce2dbcb100a5a753ddf14a65add1d57
Author: Marc Stibane <marc@taler.net>
Date: Tue, 15 Jul 2025 18:53:25 +0200
XOF
Diffstat:
9 files changed, 62 insertions(+), 43 deletions(-)
diff --git a/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift b/TalerWallet1/Views/Actions/Peer2peer/RequestPayment.swift
@@ -44,9 +44,7 @@ struct RequestPayment: View {
self._summary = summary
self._iconID = iconID
//#if OIM
- let index = selectedIndex ?? 0
- let currency = index == 0 ? OIMeuros : OIMleones
- let oimCash = OIMcash(currency, currencyIndex: (index > 0) ? 1 : 0)
+ let oimCash = OIMcash(selectedIndex)
self._cash = StateObject(wrappedValue: { oimCash }())
//#endif
}
diff --git a/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift b/TalerWallet1/Views/Actions/Peer2peer/SendAmountV.swift
@@ -46,9 +46,7 @@ struct SendAmountV: View {
self._summary = summary
self._iconID = iconID
//#if OIM
- let index = selectedIndex ?? 0
- let currency = index == 0 ? OIMeuros : OIMleones
- let oimCash = OIMcash(currency, currencyIndex: (index > 0) ? 1 : 0)
+ let oimCash = OIMcash(selectedIndex)
self._cash = StateObject(wrappedValue: { oimCash }())
//#endif
}
diff --git a/TalerWallet1/Views/OIM/OIMEditView.swift b/TalerWallet1/Views/OIM/OIMEditView.swift
@@ -79,12 +79,10 @@ struct OIMEditView: View {
// let _ = Self._printChanges()
// let _ = print(">>> OIMEditView", available, amount, stack.peek()?.file)
- let noteBase = cash.currency.noteBase
- let isSierra = noteBase == "SLE"
OIMnavBack(stack: stack.push(),
- currencyName: noteBase,
+ currencyName: cash.currency.currency,
+ chest: cash.currency.chest,
isFinal: false,
- isSierra: isSierra,
isSending: sending,
// amount: $amount2,
amount: amountToTransfer,
diff --git a/TalerWallet1/Views/OIM/OIMSubjectView.swift b/TalerWallet1/Views/OIM/OIMSubjectView.swift
@@ -80,16 +80,14 @@ struct OIMSubjectView: View {
var body: some View {
// let _ = Self._printChanges()
let currency = cash.currency
- let noteBase = currency.noteBase
- let isSierra = noteBase == "SLE"
let goals1 = ["blank", "Phone", "Electricity", "gas pump", "Hammer", "Water"]
let goals2 = ["shopping", "Rent", "Schooling", "Repay loan", "Medical"].shuffled()
let gotAction = (selectedGoal != nil) ? sendAction : nil
OIMnavBack(stack: stack.push(),
- currencyName: noteBase,
+ currencyName: currency.currency,
+ chest: currency.chest,
isFinal: false,
- isSierra: isSierra,
isSending: sending,
amount: amount2,
action: gotAction
diff --git a/TalerWallet1/Views/OIM/OIMView.swift b/TalerWallet1/Views/OIM/OIMView.swift
@@ -22,8 +22,8 @@ let OIMSIDE = "OIMside"
struct OIMnavBack<Content: View>: View {
let stack: CallStack
let currencyName: String
+ let chest: String
let isFinal: Bool // bordered action button
- let isSierra: Bool
let isSending: Bool // move action button
let amount: Amount?
let action: (() -> Void)?
@@ -38,7 +38,7 @@ struct OIMnavBack<Content: View>: View {
content()
VStack {
HStack {
- OIMbalanceButton(isOpen: true, isSierra: isSierra, isFinal: false) {
+ OIMbalanceButton(isOpen: true, chest: chest, isFinal: false) {
var transaction = Transaction()
transaction.disablesAnimations = true
withTransaction(transaction) {
@@ -72,9 +72,10 @@ struct OIMtitleView: View {
@EnvironmentObject private var wrapper: NamespaceWrapper
var body: some View {
+ let chest = cash.currency.chest
HStack(alignment: .top) {
// invisible - only serves as point where the selected balance chest moves to
- OIMbalanceButton(isOpen: true, isSierra: false, isFinal: false) {}
+ OIMbalanceButton(isOpen: true, chest: chest, isFinal: false) {}
.frame(width: OIMbuttonSize, height: OIMbuttonSize)
.disabled(true)
.opacity(0.01)
@@ -84,11 +85,11 @@ struct OIMtitleView: View {
if history {
Spacer()
}
- OIMamountV(amount: amount, currencyName: cash.currency.noteBase)
+ OIMamountV(amount: amount, currencyName: cash.currency.currency)
if !history {
if isSending {
Spacer()
- OIMamountV(amount: secondAmount, currencyName: cash.currency.noteBase)
+ OIMamountV(amount: secondAmount, currencyName: cash.currency.currency)
}
OIMactionButton(type: .sendP2P, isFinal: false, action: nil)
@@ -207,7 +208,7 @@ struct OIMView: View {
chestOpen = index
viewState = .chestIsOpen
selectedIndex = index
- cash.currency = index == 0 ? OIMeuros : OIMleones
+ cash.setIndex(index)
selectedBalance = balance
available = balance.available
availableVal = balance.available.centValue
@@ -321,13 +322,14 @@ struct OIMView: View {
// ForEach(controller.balances, id: \.self) { balance in
// OIMbalanceButton(isOpen: selectedBalance == balance) {
+ let chests = ["EUR", "SLE", "CdI"]
let balance = controller.balances[0]
- ForEach(0...1, id: \.self) { index in
+ ForEach(0...2, id: \.self) { index in
let itsMe = chestOpen == index
let isClosed = chestOpen == nil
let size = isClosed ? 160.0 : OIMbuttonSize
ZStack {
- OIMbalanceButton(isOpen: itsMe, isSierra: index > 0, isFinal: false) {
+ OIMbalanceButton(isOpen: itsMe, chest: chests[index], isFinal: false) {
if itsMe {
closeChest()
} else {
diff --git a/TalerWallet1/Views/OIM/OIMactionButtons.swift b/TalerWallet1/Views/OIM/OIMactionButtons.swift
@@ -7,6 +7,9 @@
*/
import SwiftUI
+fileprivate let chestOpen = "ChestOpen"
+fileprivate let chestClosed = "ChestClosed"
+
enum OIMactions {
case withdrawal
case deposit
@@ -62,15 +65,13 @@ struct OIMrequestButton: View {
struct OIMbalanceButton: View {
let isOpen: Bool
- let isSierra: Bool
+ let chest: String
let isFinal: Bool
let action: () -> Void
var body: some View {
- let imageName = isSierra ? (isOpen ? "ChestSLopen" : "ChestSLclosed")
-// : (isOpen ? "ChestDEopen" : "ChestDEclosed")
-// : (isOpen ? "ChestEUopen" : "ChestEUclosed")
- : (isOpen ? "ChestEUopen1" : "ChestEUclosed1")
+ let chestName = isOpen ? chestOpen : chestClosed
+ let imageName = chestName + chest
Button(action: action) {
Image(imageName)
.resizable()
diff --git a/TalerWallet1/Views/OIM/OIMcash.swift b/TalerWallet1/Views/OIM/OIMcash.swift
@@ -95,14 +95,23 @@ final class OIMcash: ObservableObject, Sendable {
var currencyIndex: Int
@Published var funds: OIMfunds = []
- init(_ currency: OIMcurrency? = nil, currencyIndex: Int = 0) {
- if let currency {
- self.currency = currency
- self.currencyIndex = currencyIndex
- } else {
- self.currency = OIMeuros
- self.currencyIndex = 0
+ init(_ index: Int? = 0) {
+ self.currencyIndex = 0
+ self.currency = OIMeuros
+ setIndex(index)
+ }
+
+ func setIndex(_ index: Int? = 0) {
+ if let index {
+ let count = OIMcurrencies.count
+ if index < count {
+ self.currencyIndex = index
+ self.currency = OIMcurrencies[index]
+ return
+ }
}
+ self.currencyIndex = 0
+ self.currency = OIMeuros
}
func max(available: UInt64) -> UInt64 {
diff --git a/TalerWallet1/Views/OIM/OIMcurrency.swift b/TalerWallet1/Views/OIM/OIMcurrency.swift
@@ -10,24 +10,40 @@ import Foundation
public typealias OIMdenominations = [UInt64]
public typealias OIMnotesCoins = (OIMdenominations, OIMdenominations) // number of notes and coins
+public let OIMcurrencies = [OIMeuros, OIMleones, OIMxofN]
// 6 banknotes, 8 coins of which 6 are fractionals < 100
public let OIMeuros = OIMcurrency(bankNotes: [20000, 10000, 5000, 2000, 1000, 500],
bankCoins: [200, 100, 50, 20, 10, 5, 2, 1],
coinSizes: [258, 232, 242, 222, 198, 212, 188, 162],
- noteBase: "EUR", coinBase: "eur")
+ noteBase: "EUR", coinBase: "eur",
+ currency: "EUR", chest: "EUR")
-// 3 stacks, 5 banknotes, 5 coins (all fractionals)
+// 5 banknotes, 7 coins (no fractionals)
+public let OIMxofN = OIMcurrency(bankNotes: [10000, 5000, 2000, 1000, 500],
+ bankCoins: [200, 100, 50, 25, 10, 5, 1],
+ coinSizes: [180, 207, 174, 207, 175, 170, 131],
+ noteBase: "XOFn", coinBase: "xof",
+ currency: "CFA", chest: "CdI")
+// 4 banknotes, 8 coins (no fractionals)
+public let OIMxofC = OIMcurrency(bankNotes: [10000, 5000, 2000, 1000],
+ bankCoins: [500, 200, 100, 50, 25, 10, 5, 1],
+ coinSizes: [200, 180, 207, 174, 207, 175, 170, 131],
+ noteBase: "XOFn", coinBase: "xof",
+ currency: "CFA", chest: "CdI")
+// 1 stack, 5 banknotes, 5 coins (all fractionals)
public let OIMleones = OIMcurrency(bankNotes: [ 10000, 2000, 1000, 500, 200, 100],
bankCoins: [ 50, 10, 5, 1],
coinSizes: [270, 240, 228, 208],
// [ 260mm 270px, 240mm 250px, 230mm 240px, 225mm 228px, 200mm 208px]
- noteBase: "SLE", coinBase: "sle")
+ noteBase: "SLE", coinBase: "sle",
+ currency: "SLE", chest: "SLE")
// 6 banknotes, 6 coins of which 5 are fractionals < 100
public let OIMdollars = OIMcurrency(bankNotes: [10000, 5000, 2000, 1000, 500, 200], // XXX x 265
bankCoins: [100, 50, 25, 10, 5, 1],
coinSizes: [265, 306, 243, 180, 212, 190],
- noteBase: "USD", coinBase: "usd")
+ noteBase: "USD", coinBase: "usd",
+ currency: "USD", chest: "DEU")
// MARK: -
public struct OIMcurrency: Sendable {
let bankNotes: OIMdenominations // values of each banknote, in cents, descending
@@ -35,6 +51,8 @@ public struct OIMcurrency: Sendable {
let coinSizes: [CGFloat] // coin sizes
let noteBase: String
let coinBase: String
+ let currency: String
+ let chest: String
func coinSize(_ value: UInt64) -> CGFloat? {
for (index, element) in bankCoins.enumerated() {
diff --git a/TalerWallet1/Views/OIM/OIMp2pReceiveView.swift b/TalerWallet1/Views/OIM/OIMp2pReceiveView.swift
@@ -27,13 +27,10 @@ struct OIMp2pReceiveView: View {
var body: some View {
// let _ = Self._printChanges()
let currency = cash.currency
- let noteBase = currency.noteBase
- let isSierra = noteBase == "SLE"
-
OIMnavBack(stack: stack.push(),
- currencyName: noteBase,
+ currencyName: currency.currency,
+ chest: currency.chest,
isFinal: false,
- isSierra: isSierra,
isSending: false,
amount: amount,
action: { }