taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit b455d89cd63d082111e0d5562f8d9d13a8c3d810
parent 113fe8ce4169523eb00718a9fd6d46f7b677395f
Author: Marc Stibane <marc@taler.net>
Date:   Wed, 21 May 2025 23:23:01 +0200

update cash (animated)

Diffstat:
MTalerWallet1/Views/OIM/OIMEditView.swift | 4++--
MTalerWallet1/Views/OIM/OIMView.swift | 18++++++------------
MTalerWallet1/Views/OIM/OIMcash.swift | 29++++++++++++++++++++++-------
3 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/TalerWallet1/Views/OIM/OIMEditView.swift b/TalerWallet1/Views/OIM/OIMEditView.swift @@ -137,8 +137,8 @@ struct OIMEditView: View { amount2 = amountToTransfer amountVal = amountToTransfer.centValue availableVal = isAvailable -// print("OIMEditView.task", availableVal, amountVal) - cash.update(amountVal) +// print("OIMEditView.task", availableVal, amountVal) + cash.update2(amountVal) } .onAppear { // print("OIMEditView.onAppear", availableVal, amountVal) diff --git a/TalerWallet1/Views/OIM/OIMView.swift b/TalerWallet1/Views/OIM/OIMView.swift @@ -252,16 +252,7 @@ struct OIMView: View { .ignoresSafeArea(edges: .horizontal) .scrollDisabled(true) .opacity(sending ? 1.0 : 0.01) - } - } - } - .task(id: chestOpen) { - if chestOpen != nil { - availableVal = available?.centValue ?? 0 - cash.update(availableVal) // set cash to available - let maxAvailable = cash.max(available: availableVal) - print("OIMView.task availableVal", availableVal, maxAvailable) - debugTick += 1 + } // for matching positions of money } } .onAppear { @@ -269,10 +260,13 @@ struct OIMView: View { if (chestOpen != nil) { let balance = controller.balances[0] available = balance.available + availableVal = available?.centValue ?? 0 + cash.update2(availableVal) // set cash to available showingActions = true + } else { + availableVal = 0 + cash.update2(availableVal) // set cash to available } - availableVal = available?.centValue ?? 0 - cash.update(availableVal) // set cash to available debugTick += 1 } .onDisappear { diff --git a/TalerWallet1/Views/OIM/OIMcash.swift b/TalerWallet1/Views/OIM/OIMcash.swift @@ -367,22 +367,30 @@ final class OIMcash: ObservableObject, Sendable { } } - func update(_ intVal: UInt64) { + func update2(_ intVal: UInt64, _ duration: TimeInterval = 0, _ initial: TimeInterval = 0) { let result = currency.notesCoins(intVal) - let chng1 = update(result.0, currencyNotesCoins: currency.bankNotes) - let chng2 = update(result.1, currencyNotesCoins: currency.bankCoins) + let chng1 = update1(result.0, currencyNotesCoins: currency.bankNotes, duration, initial) + let chng2 = update1(result.1, currencyNotesCoins: currency.bankCoins, duration, initial) } - func update(_ notesCoins: OIMdenominations, currencyNotesCoins: OIMdenominations) -> Bool { + func update1(_ notesCoins: OIMdenominations, + currencyNotesCoins: OIMdenominations, + _ duration: TimeInterval = 0, + _ initial: TimeInterval = 0) -> Bool { var array = funds var changed = false + var accumulatedDelay = initial + let count = notesCoins.reduce(0) { x, y in + x + y + } + let interval: TimeInterval = (duration <= initial) || (count == 0) ? 0 : (duration - initial) / Double(count) for (index, value) in currencyNotesCoins.enumerated() { let wanted = notesCoins[index] // number of notes which should be shown var shownNotes = array.filter { $0.value == value } var count = shownNotes.count while count > wanted { let note = shownNotes[0] - symLog.log("update: remove \(note.value)") + symLog.log("update: remove \(note.value), \(note.id)") if let index = array.firstIndex(of: note) { array.remove(at: index) changed = true @@ -393,8 +401,15 @@ final class OIMcash: ObservableObject, Sendable { while count < wanted { let note = OIMfund(id: ticker, state: .idle, value: value, flippedVal: nil) ticker += 1 - symLog.log("update: add \(note.value)") - array.append(note) + symLog.log("update: add \(note.value), \(note.id)") + if duration > 0 { + withAnimation(.move1.delay(accumulatedDelay)) { + array.append(note) + } + accumulatedDelay += interval + } else { + array.append(note) + } changed = true count += 1 }