blob: f0106dec464bab827a952c40764d635820ac8fe4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
import SwiftUI
struct WalletTransactionsView: View {
@ObservedObject var viewModel: WalletViewModel
let client: NjallaClient
var body: some View {
List {
if let errorMessage = viewModel.transactionsErrorMessage {
Section {
InlineErrorView(message: errorMessage, retryTitle: "Retry Transactions") {
Task {
await viewModel.loadTransactions(client: client)
}
}
.listRowInsets(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16))
}
}
if viewModel.isLoadingTransactions && viewModel.transactions.isEmpty {
Section {
HStack {
Spacer()
ProgressView("Loading Transactions")
Spacer()
}
}
} else if viewModel.transactions.isEmpty {
Section {
ContentUnavailableView(
"No Transactions",
systemImage: "eurosign.circle",
description: Text("No wallet transactions were returned for this account.")
)
}
} else {
ForEach(viewModel.transactions) { transaction in
NavigationLink {
WalletPaymentDetailView(transactionID: transaction.id, viewModel: viewModel, client: client)
} label: {
VStack(alignment: .leading, spacing: 4) {
Text(transaction.type ?? "Transaction")
.font(.headline)
Text(transactionDateText(transaction))
.font(.subheadline)
.foregroundStyle(.secondary)
if let amount = transaction.amount {
Text("Amount: €\(amount)")
.font(.subheadline)
.foregroundStyle(.secondary)
}
}
.padding(.vertical, 4)
}
}
}
}
.listStyle(.insetGrouped)
.navigationTitle("Transactions")
.navigationBarTitleDisplayMode(.inline)
.task {
await viewModel.loadTransactions(client: client)
}
.refreshable {
await viewModel.loadTransactions(client: client)
}
}
private func transactionDateText(_ transaction: WalletTransaction) -> String {
if let date = transaction.date, !date.isEmpty {
return date
}
return "ID: \(transaction.id)"
}
}
|