commit b32c3b91e021b1fedec4424783835a606d88c9a2
parent faf2a9f065e062afba8e18adb40deda745591127
Author: Marc Stibane <marc@taler.net>
Date: Thu, 24 Apr 2025 12:12:38 +0200
max, moveBack
Diffstat:
2 files changed, 31 insertions(+), 12 deletions(-)
diff --git a/TalerWallet1/Views/OIM/OIMView.swift b/TalerWallet1/Views/OIM/OIMView.swift
@@ -154,8 +154,7 @@ struct OIMView: View {
.environmentObject(cash)
.task {
availableVal = intValue(available)
- let result = currency.notesCoins(availableVal)
- cash.update(result, currency: currency)
+ cash.update(availableVal)
}
}
}
@@ -275,8 +274,7 @@ struct OIMEditView: View {
.task {
amountVal = intValue(amount)
availableVal = isAvailable
- let result = currency.notesCoins(amountVal)
- cash.update(result, currency: currency)
+ cash.update(amountVal)
}
}
}
diff --git a/TalerWallet1/Views/OIM/OIMcash.swift b/TalerWallet1/Views/OIM/OIMcash.swift
@@ -64,17 +64,26 @@ final class OIMcash: ObservableObject, Sendable {
var currency: OIMcurrency
@Published var funds: OIMfunds = []
- @AppStorage("sierraLeone") var sierraLeone: Bool = false
-
init(_ currency: OIMcurrency? = nil) {
if let currency {
self.currency = currency
} else {
self.currency = OIMeuros
}
- if sierraLeone {
- self.currency = OIMleones
+ }
+
+ func max(available: UInt64) -> UInt64 {
+ for note in currency.bankNotes {
+ if note <= available {
+ return note
+ }
+ }
+ for coin in currency.bankCoins {
+ if coin <= available {
+ return coin
+ }
}
+ return 0
}
var delay: Double {
@@ -316,13 +325,15 @@ final class OIMcash: ObservableObject, Sendable {
}
}
+ @discardableResult
func moveDown() -> Double {
let sorted = sortByValue()
var counter = 0.0
var lastVal: UInt64 = 0
for var fund in sorted {
- withAnimation(.easeOut1.delay(counter * 0.1)) {
+// withAnimation(.easeOut1.delay(counter * 0.1)) {
+ withAnimation(.easeOut1) {
fund.state = .returning
self.updateFund(fund)
}
@@ -334,9 +345,19 @@ final class OIMcash: ObservableObject, Sendable {
return counter * 0.1
}
- func update(_ notesCoins: OIMnotesCoins, currency: OIMcurrency) {
- let chng1 = update(notesCoins.0, currencyNotesCoins: currency.bankNotes)
- let chng2 = update(notesCoins.1, currencyNotesCoins: currency.bankCoins)
+ func moveBack() {
+ for var fund in funds {
+ if fund.state == .returning {
+ fund.state = .idle
+ self.updateFund(fund)
+ }
+ }
+ }
+
+ func update(_ intVal: UInt64) {
+ let result = currency.notesCoins(intVal)
+ let chng1 = update(result.0, currencyNotesCoins: currency.bankNotes)
+ let chng2 = update(result.1, currencyNotesCoins: currency.bankCoins)
}
func update(_ notesCoins: OIMdenominations, currencyNotesCoins: OIMdenominations) -> Bool {