commit 3c49da0721bb7427868e3504cffd18c232a629db
parent 8d721d763a65b65ac14922064f69af4e30bd8125
Author: Marc Stibane <marc@taler.net>
Date: Wed, 23 Jul 2025 07:54:47 +0200
cash without index
Diffstat:
4 files changed, 56 insertions(+), 34 deletions(-)
diff --git a/TalerWallet1/Views/OIM/OIMbalances.swift b/TalerWallet1/Views/OIM/OIMbalances.swift
@@ -36,7 +36,7 @@ struct OIMbalances: View {
@EnvironmentObject private var controller: Controller
@EnvironmentObject private var wrapper: NamespaceWrapper
- @StateObject private var cash = OIMcash()
+ @StateObject private var cash = OIMcash(OIMeuros)
@State private var availableVal: UInt64 = 0
@State private var tappedVal: UInt64 = 0
@State private var available: Amount? = nil
@@ -114,7 +114,8 @@ struct OIMbalances: View {
selectedBalance = balance
balanceIndex = index
viewState = .chestIsOpen
- cash.setIndex(index)
+// cash.setIndex(index)
+ cash.setCurrency(oimCurrency)
available = balance.available
availableVal = balance.available.centValue
cash.update2(availableVal, state: .chestOpening, duration, initial) // set cash to available
@@ -250,11 +251,13 @@ struct OIMbalances: View {
.zIndex(itsMe ? 3 : 0)
.opacity((isClosed || itsMe) ? 1 : INVISIBLE)
.matchedGeometryEffect(id: itsMe ? OIMNUMBER
- : String(index),
+// : String(index),
+ : oimCurrency.currencyStr,
in: wrapper.namespace, isSource: false)
Color.clear
.frame(width: 40, height: 40)
- .matchedGeometryEffect(id: OIMCHEST + String(index), in: wrapper.namespace, isSource: true)
+// .matchedGeometryEffect(id: OIMCHEST + String(index), in: wrapper.namespace, isSource: true)
+ .matchedGeometryEffect(id: OIMCHEST + oimCurrency.currencyStr, in: wrapper.namespace, isSource: true)
}
}
}
diff --git a/TalerWallet1/Views/OIM/OIMcash.swift b/TalerWallet1/Views/OIM/OIMcash.swift
@@ -51,7 +51,8 @@ enum FundState: Int {
public struct OIMfund: Identifiable, Equatable, Hashable, Sendable {
public let id: Int // support multiple funds with the same value
var value: UInt64 // can be morphed
- var currencyIndex: Int
+// var currencyIndex: Int
+ var currencyStr: String
var state: FundState
var delay: TimeInterval
var morphTicker: Int? // `semaphore´ to reserve a fund - don't morph this twice concurrently
@@ -59,7 +60,7 @@ public struct OIMfund: Identifiable, Equatable, Hashable, Sendable {
var outValue: UInt64? // if this is set it determines the image (used for flipping)
var targetID: String { // match sourceID for SwiftUI animations
let isDrawer = state.shouldFly || state.drawer || state.removing
- return state.chestOpening ? OIMCHEST + String(currencyIndex)
+ return state.chestOpening ? OIMCHEST + currencyStr // String(currencyIndex)
: state.reveal ? OIMNUMBER
: state.curve ? OIMACTION
: state.history ? OIMSIDE
@@ -69,13 +70,14 @@ public struct OIMfund: Identifiable, Equatable, Hashable, Sendable {
var shouldFly2: Bool { state.shouldFly || state.chestOpening }
var isFlying2: Bool { state.isFlying }
- init(id: Int, value: UInt64, currencyIndex: Int,
+ init(id: Int, value: UInt64, currencyStr: String, // currencyIndex: Int,
state: FundState = .idle, delay: TimeInterval = 0,
morphTicker: Int? = nil, flippedVal: UInt64? = nil, outValue: UInt64? = nil
) {
self.id = id
self.value = value
- self.currencyIndex = currencyIndex
+// self.currencyIndex = currencyIndex
+ self.currencyStr = currencyStr
self.state = state
self.delay = delay
self.morphTicker = morphTicker
@@ -87,33 +89,41 @@ public typealias OIMfunds = [OIMfund]
// MARK: -
final class OIMcash: ObservableObject, Sendable {
- private let symLog = SymLogV()
+ private let symLog = SymLogV(0)
private let logger = Logger(subsystem: "net.taler.gnu", category: "OIMcash")
private var ticker = 0 // increment each time a fund is added (or melted from others)
// let semaphore = AsyncSemaphore(value: 1)
var currency: OIMcurrency
- var currencyIndex: Int
+// var currencyIndex: Int
@Published var funds: OIMfunds = []
- init(_ index: Int? = 0) {
- self.currencyIndex = 0
- self.currency = OIMeuros
- setIndex(index)
+// init(_ index: Int? = 0) {
+// self.currencyIndex = 0
+// self.currency = OIMeuros
+// setIndex(index)
+// }
+
+ init(_ oimCurrency: OIMcurrency) {
+ self.currency = oimCurrency
}
- 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 setCurrency(_ oimCurrency: OIMcurrency) {
+ self.currency = oimCurrency
}
+// 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 {
for note in currency.bankNotes {
if note <= available {
@@ -356,8 +366,11 @@ final class OIMcash: ObservableObject, Sendable {
@discardableResult
func addCash(value: UInt64, _ newState: FundState = .shouldFly, _ flippedVal: UInt64? = nil) -> OIMfund {
let myTicker = ticker; ticker += 1 // TODO: atomic increment!
- let fund = OIMfund(id: myTicker, value: value, currencyIndex: currencyIndex,
- state: newState, flippedVal: flippedVal)
+ let fund = OIMfund(id: myTicker,
+ value: value,
+ currencyStr: currency.currencyStr, // currencyIndex: currencyIndex,
+ state: newState,
+ flippedVal: flippedVal)
symLog.log(">>adding \(value) \(fund.id) \(newState)")
funds.append(fund)
return fund
@@ -529,8 +542,10 @@ final class OIMcash: ObservableObject, Sendable {
}
while count < wanted {
// if interval == 0 { // add all at once
- let fund = OIMfund(id: ticker, value: value,
- currencyIndex: currencyIndex, state: state,
+ let fund = OIMfund(id: ticker,
+ value: value,
+ currencyStr: currency.currencyStr, // currencyIndex: currencyIndex,
+ state: state,
delay: accumulatedDelay)
ticker += 1
symLog.log("update: add \(fund.value), \(fund.id)")
diff --git a/TalerWallet1/Views/OIM/OIMcurrencyDrawer.swift b/TalerWallet1/Views/OIM/OIMcurrencyDrawer.swift
@@ -30,8 +30,10 @@ struct OIMcurrencyDrawer: View {
HStack(alignment: .bottom, spacing: 10) {
ForEach(currency.bankNotes, id: \.self) { value in
let sourceID = -Int(value)
- let fund = OIMfund(id: sourceID, value: value,
- currencyIndex: cash.currencyIndex)
+ let fund = OIMfund(id: sourceID,
+ value: value,
+// currencyIndex: cash.currencyIndex
+ currencyStr: currency.currencyStr)
OIMcurrencyButton(stack: stack.push(),
fund: fund,
currency: currency,
@@ -46,8 +48,10 @@ struct OIMcurrencyDrawer: View {
}
ForEach(currency.bankCoins, id: \.self) { value in
let sourceID = -Int(value)
- let fund = OIMfund(id: sourceID, value: value,
- currencyIndex: cash.currencyIndex)
+ let fund = OIMfund(id: sourceID,
+ value: value,
+// currencyIndex: cash.currencyIndex
+ currencyStr: currency.currencyStr)
OIMcurrencyButton(stack: stack.push(),
fund: fund,
currency: currency,
diff --git a/TalerWallet1/Views/OIM/OIMpayView.swift b/TalerWallet1/Views/OIM/OIMpayView.swift
@@ -17,7 +17,7 @@ struct OIMpayView: View {
@EnvironmentObject private var wrapper: NamespaceWrapper
- @StateObject private var cash = OIMcash()
+ @StateObject private var cash = OIMcash(OIMeuros)
@State private var amountVal: UInt64 = 0
var body: some View {