[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-ios] 10/36: @Published currencyTicker
From: |
gnunet |
Subject: |
[taler-taler-ios] 10/36: @Published currencyTicker |
Date: |
Mon, 13 Nov 2023 21:27:15 +0100 |
This is an automated email from the git hooks/post-receive script.
marc-stibane pushed a commit to branch master
in repository taler-ios.
commit 1ff1bc377c13eb9411ea9ed0fd5b971f699b0871
Author: Marc Stibane <marc@taler.net>
AuthorDate: Sun Nov 12 12:57:47 2023 +0100
@Published currencyTicker
---
TalerWallet1/Controllers/Controller.swift | 48 ++++++++++++++--------
TalerWallet1/Views/Balances/BalanceRowView.swift | 2 +
.../Views/Balances/BalancesSectionView.swift | 2 +-
TalerWallet1/Views/Balances/PendingRowView.swift | 2 +
TalerWallet1/Views/Main/MainView.swift | 2 +-
.../Views/Transactions/TransactionRowView.swift | 3 +-
6 files changed, 40 insertions(+), 19 deletions(-)
diff --git a/TalerWallet1/Controllers/Controller.swift
b/TalerWallet1/Controllers/Controller.swift
index 891a62a..39fcc4e 100644
--- a/TalerWallet1/Controllers/Controller.swift
+++ b/TalerWallet1/Controllers/Controller.swift
@@ -33,7 +33,7 @@ class Controller: ObservableObject {
private let symLog = SymLogC()
@Published var backendState: BackendState = .none // only used for
launch animation
- @Published var currencyInfos: [CurrencyInfo]
+ @Published var currencyTicker: Int = 0
@AppStorage("useHaptics") var useHaptics: Bool = true // extension
mustn't define this, so it must be here
@AppStorage("playSounds") var playSounds: Int = 1 // extension
mustn't define this, so it must be here
@AppStorage("talerFont") var talerFont: Int = 0 // extension
mustn't define this, so it must be here
@@ -41,6 +41,7 @@ class Controller: ObservableObject {
let logger = Logger(subsystem: "net.taler.gnu", category: "Controller")
let player = AVQueuePlayer()
let semaphore = AsyncSemaphore(value: 1)
+ var currencyInfos: [CurrencyInfo]
var messageForSheet: String? = nil
@@ -52,35 +53,50 @@ class Controller: ObservableObject {
// }
// }
backendState = .instantiated
+ currencyTicker = 0
currencyInfos = []
}
// MARK: -
+ func hasInfo(for currency: String) -> Bool {
+ for info in currencyInfos {
+ if info.scope.currency == currency {
+ return true
+ }
+ }
+ return false
+ }
- func info(for currency: String) -> CurrencyInfo? {
- for currencyInfo in currencyInfos {
- if currencyInfo.scope.currency == currency {
- return currencyInfo
+ func info(for currency: String, _ ticker: Int) -> CurrencyInfo {
+ if ticker != currencyTicker {
+ print("Yikes")
+ }
+ for info in currencyInfos {
+ if info.scope.currency == currency {
+ return info
}
}
- return nil
+ return CurrencyInfo.zero(currency)
}
@MainActor
- func setInfo(_ info: CurrencyInfo) async {
+ func setInfo(_ newInfo: CurrencyInfo) async {
await semaphore.wait()
defer { semaphore.signal() }
- var existing: ScopeInfo? = nil
- for currencyInfo in currencyInfos {
- let scope = currencyInfo.scope
- if scope.currency == info.scope.currency {
- existing = scope
- break
+
+ var replaced = false
+ var newInfos = currencyInfos.map { currencyInfo in
+ if currencyInfo.scope.currency == newInfo.scope.currency {
+ replaced = true
+ return newInfo
+ } else {
+ return currencyInfo
}
}
- if existing != nil {
- currencyInfos.removeAll(where: { $0.scope == existing })
+ if !replaced {
+ newInfos.append(newInfo)
}
- currencyInfos.append(info)
+ currencyInfos = newInfos
+ currencyTicker += 1 // triggers published view update
}
// MARK: -
@MainActor
diff --git a/TalerWallet1/Views/Balances/BalanceRowView.swift
b/TalerWallet1/Views/Balances/BalanceRowView.swift
index 8645194..812bf1f 100644
--- a/TalerWallet1/Views/Balances/BalanceRowView.swift
+++ b/TalerWallet1/Views/Balances/BalanceRowView.swift
@@ -53,6 +53,7 @@ struct BalanceRowView: View {
let recvAction: () -> Void
let rowAction: () -> Void
@Environment(\.sizeCategory) var sizeCategory
+ @EnvironmentObject private var controller: Controller
@AppStorage("iconOnly") var iconOnly: Bool = false
@AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
@@ -72,6 +73,7 @@ struct BalanceRowView: View {
var body: some View {
SingleAxisGeometryReader { width in
VStack (alignment: .trailing) {
+ let currencyInfo = controller.info(for: amount.currencyStr,
controller.currencyTicker)
let amountStr = amount.string(currencyInfo)
BalanceButton(amountStr: amountStr,
sizeCategory: sizeCategory,
diff --git a/TalerWallet1/Views/Balances/BalancesSectionView.swift
b/TalerWallet1/Views/Balances/BalancesSectionView.swift
index ab7f088..3f1fe13 100644
--- a/TalerWallet1/Views/Balances/BalancesSectionView.swift
+++ b/TalerWallet1/Views/Balances/BalancesSectionView.swift
@@ -70,7 +70,7 @@ extension BalancesSectionView: View {
let _ = symLog.vlog() // just to get the # to compare it with
.onAppear & onDisappear
#endif
let currency = balance.scopeInfo.currency
- let currencyInfo = controller.info(for: currency)
+ let currencyInfo = controller.info(for: currency,
controller.currencyTicker)
Section {
if "KUDOS" == currency && !balance.available.isZero {
diff --git a/TalerWallet1/Views/Balances/PendingRowView.swift
b/TalerWallet1/Views/Balances/PendingRowView.swift
index f36c67a..52cd56d 100644
--- a/TalerWallet1/Views/Balances/PendingRowView.swift
+++ b/TalerWallet1/Views/Balances/PendingRowView.swift
@@ -57,6 +57,7 @@ struct PendingRowView: View {
let incoming: Bool
@Environment(\.sizeCategory) var sizeCategory
+ @EnvironmentObject private var controller: Controller
@AppStorage("iconOnly") var iconOnly: Bool = false
let inTitle0 = String(localized: "TitleIncoming_Short", defaultValue:
"Incoming",
@@ -85,6 +86,7 @@ struct PendingRowView: View {
let pendingColor = WalletColors().pendingColor(incoming)
SingleAxisGeometryReader { width in
Group {
+ let currencyInfo = controller.info(for: amount.currencyStr,
controller.currencyTicker)
let amountStr = amount.string(currencyInfo)
let amountWidth = amountStr.width(largeAmountFont: false,
sizeCategory)
let inTitle = iconOnly ? (inTitle0, nil)
diff --git a/TalerWallet1/Views/Main/MainView.swift
b/TalerWallet1/Views/Main/MainView.swift
index 179173f..b16ed8e 100644
--- a/TalerWallet1/Views/Main/MainView.swift
+++ b/TalerWallet1/Views/Main/MainView.swift
@@ -268,7 +268,7 @@ extension MainView {
.onChange(of: balances) { newArray in
for balance in newArray {
let scope = balance.scopeInfo
- if controller.info(for: scope.currency) == nil {
+ if !controller.hasInfo(for: scope.currency) {
Task { // runs on MainActor
symLog?.log("get info for: \(scope.currency)")
do {
diff --git a/TalerWallet1/Views/Transactions/TransactionRowView.swift
b/TalerWallet1/Views/Transactions/TransactionRowView.swift
index 28925c2..165fa06 100644
--- a/TalerWallet1/Views/Transactions/TransactionRowView.swift
+++ b/TalerWallet1/Views/Transactions/TransactionRowView.swift
@@ -62,6 +62,7 @@ struct TransactionRowView: View {
let currencyInfo: CurrencyInfo?
@Environment(\.sizeCategory) var sizeCategory
+ @EnvironmentObject private var controller: Controller
func needVStack(available: CGFloat, contentWidth: CGFloat, valueWidth:
CGFloat) -> Bool {
available < (contentWidth + valueWidth + 40)
@@ -80,7 +81,7 @@ struct TransactionRowView: View {
let foreColor = pending ? WalletColors().pendingColor(incoming)
: done ? WalletColors().transactionColor(incoming)
: WalletColors().incompleteColor
-
+// let currencyInfo = controller.info(for: currency,
controller.currencyTicker)
SingleAxisGeometryReader { width in
Group {
let amountStr = amount.string(currencyInfo)
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-ios] 22/36: amountToTransfer ManualWithdraw, (continued)
- [taler-taler-ios] 22/36: amountToTransfer ManualWithdraw, gnunet, 2023/11/13
- [taler-taler-ios] 33/36: Announce shouldn't change screen, gnunet, 2023/11/13
- [taler-taler-ios] 34/36: Previews, gnunet, 2023/11/13
- [taler-taler-ios] 32/36: Shortcuts (50,25,10,5), gnunet, 2023/11/13
- [taler-taler-ios] 11/36: Debugging, gnunet, 2023/11/13
- [taler-taler-ios] 25/36: amountToTransfer Currency, gnunet, 2023/11/13
- [taler-taler-ios] 16/36: TransactionsArraySliceV, gnunet, 2023/11/13
- [taler-taler-ios] 20/36: amountToTransfer Request, gnunet, 2023/11/13
- [taler-taler-ios] 26/36: Minimalistic, gnunet, 2023/11/13
- [taler-taler-ios] 31/36: Use `te´and `ku´ for previews, gnunet, 2023/11/13
- [taler-taler-ios] 10/36: @Published currencyTicker,
gnunet <=
- [taler-taler-ios] 35/36: Check Available, accessibility, gnunet, 2023/11/13
- [taler-taler-ios] 36/36: Bump version to 0.9.3 (25), gnunet, 2023/11/13
- [taler-taler-ios] 08/36: Cleanup, gnunet, 2023/11/13