ManaView (Guthaben + EUR + Topf-Split 80/5/5/5/5 + Bewegungen) + ManaBalanceRow + ManaFormat + ManaCreditsModel. Pendant zur Web-<ManaPage>. Konsumiert ManaCreditsClient (ManaCore), System-Styling, app-agnostisch. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
37 lines
973 B
Swift
37 lines
973 B
Swift
import ManaCore
|
|
import Observation
|
|
|
|
/// Lade-State für `ManaView`. Holt Guthaben + letzte Bewegungen parallel.
|
|
@MainActor
|
|
@Observable
|
|
public final class ManaCreditsModel {
|
|
public enum LoadState: Equatable {
|
|
case idle
|
|
case loading
|
|
case loaded
|
|
case failed(String)
|
|
}
|
|
|
|
public private(set) var balance: ManaCreditBalance?
|
|
public private(set) var transactions: [ManaCreditTransaction] = []
|
|
public private(set) var state: LoadState = .idle
|
|
|
|
private let client: ManaCreditsClient
|
|
|
|
public init(client: ManaCreditsClient) {
|
|
self.client = client
|
|
}
|
|
|
|
public func load() async {
|
|
state = .loading
|
|
do {
|
|
async let b = client.balance()
|
|
async let t = client.transactions(limit: 25)
|
|
balance = try await b
|
|
transactions = try await t
|
|
state = .loaded
|
|
} catch {
|
|
state = .failed(error.localizedDescription)
|
|
}
|
|
}
|
|
}
|