diff options
| author | Christian Cleberg <[email protected]> | 2026-04-13 22:37:22 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-13 22:37:22 -0500 |
| commit | 5dcfe0f147c7871eaf5f3a88bd9e9fded38d4633 (patch) | |
| tree | 6bcbda4f02a131d3e3b870a3904ccd42f4af2f26 /Rune/ViewModels/WalletViewModel.swift | |
| parent | fcf864a15b70e4ecb5bd789b1db3116221c34394 (diff) | |
| download | rune-1.2.0.tar.gz rune-1.2.0.tar.bz2 rune-1.2.0.zip | |
v1.2.0 domain management and wallet expansionv1.2.0
Complete v1.1-aligned domain flows with forwards and glue CRUD, improve API payload resilience, and add wallet transaction/payment views.
Harden error handling and UX states across domain screens, remove out-of-scope DNSSEC/renewal record flows for now, and keep auth/session behavior aligned with token-based usage.
Diffstat (limited to 'Rune/ViewModels/WalletViewModel.swift')
| -rw-r--r-- | Rune/ViewModels/WalletViewModel.swift | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/Rune/ViewModels/WalletViewModel.swift b/Rune/ViewModels/WalletViewModel.swift new file mode 100644 index 0000000..cbe0538 --- /dev/null +++ b/Rune/ViewModels/WalletViewModel.swift @@ -0,0 +1,65 @@ +import Combine +import Foundation + +@MainActor +final class WalletViewModel: ObservableObject { + @Published private(set) var transactions: [WalletTransaction] = [] + @Published private(set) var selectedPayment: WalletPayment? + @Published private(set) var isLoadingTransactions = false + @Published private(set) var isLoadingPayment = false + @Published var transactionsErrorMessage: String? + @Published var paymentErrorMessage: String? + + func reset() { + transactions = [] + selectedPayment = nil + isLoadingTransactions = false + isLoadingPayment = false + transactionsErrorMessage = nil + paymentErrorMessage = nil + } + + func loadTransactions(client: NjallaClient) async { + guard !isLoadingTransactions else { return } + + isLoadingTransactions = true + defer { + isLoadingTransactions = false + } + + do { + transactions = try await client.listTransactions().sorted { + ($0.date ?? "", $0.id) > ($1.date ?? "", $1.id) + } + transactionsErrorMessage = nil + } catch is CancellationError { + return + } catch { + if (error as? URLError)?.code == .cancelled { + return + } + transactionsErrorMessage = error.userFacingMessage + } + } + + func loadPayment(id: String, client: NjallaClient) async { + guard !isLoadingPayment else { return } + + isLoadingPayment = true + defer { + isLoadingPayment = false + } + + do { + selectedPayment = try await client.getPayment(id: id) + paymentErrorMessage = nil + } catch is CancellationError { + return + } catch { + if (error as? URLError)?.code == .cancelled { + return + } + paymentErrorMessage = error.userFacingMessage + } + } +} |
