commit 9b2f26ff3ee711726bc81de32ccf0d3f7eaa342a
parent d45d020554bf1681c91b573767e170e0b5ea9ecb
Author: Marc Stibane <marc@taler.net>
Date: Sun, 15 Oct 2023 23:33:33 +0200
BarGraph also for Exchanges
Diffstat:
3 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/TalerWallet1/Views/Balances/BalancesSectionView.swift b/TalerWallet1/Views/Balances/BalancesSectionView.swift
@@ -110,11 +110,7 @@ extension BalancesSectionView: View {
}
} header: {
- HStack (alignment: .center, spacing: 10) {
- Text(currency)
- .accessibilityFont(.title2)
- BarGraph(transactions: $completedTransactions, barHeight: 10)
- }
+ BarGraphHeader(stack: stack.push(), currency: currency)
}.id(sectionID)
.task {
// if shownSectionID != sectionID {
diff --git a/TalerWallet1/Views/Exchange/ExchangeSectionView.swift b/TalerWallet1/Views/Exchange/ExchangeSectionView.swift
@@ -95,8 +95,7 @@ struct ExchangeSectionView: View {
}
.accessibilityElement(children: .combine)
} header: {
- Text(currency)
- .accessibilityFont(.title2)
+ BarGraphHeader(stack: stack.push(), currency: currency)
}
}
}
diff --git a/TalerWallet1/Views/HelperViews/BarGraph.swift b/TalerWallet1/Views/HelperViews/BarGraph.swift
@@ -3,9 +3,38 @@
* See LICENSE.md
*/
import SwiftUI
+import SymLog
+let MAXBARS = 10
+
+struct BarGraphHeader: View {
+ private let symLog = SymLogV(0)
+ let stack: CallStack
+ let currency: String
+
+ @EnvironmentObject private var model: WalletModel
+ @State private var completedTransactions: [Transaction] = []
+
+ var body: some View {
+ HStack (alignment: .center, spacing: 10) {
+ Text(currency)
+ .accessibilityFont(.title2)
+ BarGraph(transactions: $completedTransactions,
+ maxBars: MAXBARS, barHeight: 10) // TODO: barHeight relative to fontSize
+ }
+ .task {
+ symLog.log(".task for BarGraphHeader(\(currency)) - reload Transactions")
+ // TODO: only load the 10 most recent transactions
+ let response = await model.transactionsT(stack.push(".task - reload Transactions for \(currency)"),
+ currency: currency)
+ completedTransactions = WalletModel.completedTransactions(response)
+ }
+ }
+}
+// MARK: -
struct BarGraph: View {
@Binding var transactions: [Transaction]
+ let maxBars: Int
let barHeight : Double
func maxValue(_ someTransactions: [Transaction]) -> Double {
@@ -20,7 +49,7 @@ struct BarGraph: View {
}
var body: some View {
- let slice = transactions.prefix(10)
+ let slice = transactions.prefix(maxBars)
let count = slice.count
let tenTransactions: [Transaction] = Array(slice)
let maxValue = maxValue(tenTransactions)