[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-ios] 03/69: CurrencyInfo from Exchange
From: |
gnunet |
Subject: |
[taler-taler-ios] 03/69: CurrencyInfo from Exchange |
Date: |
Fri, 19 Jan 2024 09:01:36 +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 d55562269cd5835171591ffb7100f8ea0dffc3f2
Author: Marc Stibane <marc@taler.net>
AuthorDate: Wed Dec 13 22:24:42 2023 +0100
CurrencyInfo from Exchange
---
TalerWallet1/Controllers/Controller.swift | 31 ++++++++++++++++++++---
TalerWallet1/Helper/Controller+playSound.swift | 19 ++++++++++----
TalerWallet1/Model/Model+Exchange.swift | 3 ++-
TalerWallet1/Views/Exchange/ExchangeRowView.swift | 4 +--
TalerWallet1/Views/Main/MainView.swift | 4 +--
5 files changed, 47 insertions(+), 14 deletions(-)
diff --git a/TalerWallet1/Controllers/Controller.swift
b/TalerWallet1/Controllers/Controller.swift
index 05f5d77..c545f3c 100644
--- a/TalerWallet1/Controllers/Controller.swift
+++ b/TalerWallet1/Controllers/Controller.swift
@@ -35,7 +35,7 @@ class Controller: ObservableObject {
private let symLog = SymLogC()
@Published var backendState: BackendState = .none // only used for
launch animation
- @Published var currencyTicker: Int = 0
+ @Published var currencyTicker: Int = 0 // updates
whenever a new currency is added
@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
@@ -59,13 +59,13 @@ class Controller: ObservableObject {
currencyInfos = []
}
// MARK: -
- func hasInfo(for currency: String) -> Bool {
+ func hasInfo(for currency: String) -> CurrencyInfo? {
for info in currencyInfos {
if info.scope.currency == currency {
- return true
+ return info
}
}
- return false
+ return nil
}
func info(for currency: String, _ ticker: Int) -> CurrencyInfo {
@@ -80,6 +80,29 @@ class Controller: ObservableObject {
return CurrencyInfo.zero(currency)
}
+ @MainActor
+ func getInfo(from exchangeBaseUrl: String, model: WalletModel) async ->
CurrencyInfo? {
+ if let exchange = await model.getExchangeByUrl(url: exchangeBaseUrl) {
+ if let scopeInfo = exchange.scopeInfo {
+ if let info = hasInfo(for: scopeInfo.currency) {
+ return info
+ }
+ do {
+ let info = try await model.getCurrencyInfoM(scope:
scopeInfo, delay: 0)
+ await setInfo(info)
+ return info
+ } catch {
+ return nil
+ }
+ } else {
+ // TODO: Error "Can't get scopeInfo"
+ }
+ } else {
+ // TODO: Error "Can't get Exchange Info"
+ }
+ return nil
+ }
+
@MainActor
func setInfo(_ newInfo: CurrencyInfo) async {
await semaphore.wait()
diff --git a/TalerWallet1/Helper/Controller+playSound.swift
b/TalerWallet1/Helper/Controller+playSound.swift
index 7e76e36..cad7b3b 100644
--- a/TalerWallet1/Helper/Controller+playSound.swift
+++ b/TalerWallet1/Helper/Controller+playSound.swift
@@ -8,6 +8,19 @@ import UIKit
extension Controller {
+ @MainActor
+ func hapticNotification(_ feedbackType:
UINotificationFeedbackGenerator.FeedbackType) {
+ if useHaptics {
+
UINotificationFeedbackGenerator().notificationOccurred(feedbackType)
+ }
+ }
+
+ @MainActor
+ func hapticFeedback(_ feedbackStyle:
UIImpactFeedbackGenerator.FeedbackStyle) {
+ UIImpactFeedbackGenerator(style: feedbackStyle).impactOccurred()
+ }
+
+
/// 0 = failure, 1 = received, 2 = sent
@MainActor func playSound(_ number: Int) {
let sysVolume = AVAudioSession.sharedInstance().outputVolume
@@ -31,7 +44,6 @@ extension Controller {
// logger.log("❗️sys:\(sysVolume) vol:\(volume)")
var soundID: SystemSoundID = 0
- let notificationGenerator = useHaptics ?
UINotificationFeedbackGenerator() : nil
if number > 9 {
soundID = UInt32(number)
} else {
@@ -58,9 +70,6 @@ extension Controller {
AudioServicesPlaySystemSound(soundID);
}
}
- if let notificationGenerator {
- notificationGenerator.notificationOccurred(number == 0 ? .error :
.success)
- }
-
+ hapticNotification(number == 0 ? .error : .success)
}
}
diff --git a/TalerWallet1/Model/Model+Exchange.swift
b/TalerWallet1/Model/Model+Exchange.swift
index 4764116..3a8b471 100644
--- a/TalerWallet1/Model/Model+Exchange.swift
+++ b/TalerWallet1/Model/Model+Exchange.swift
@@ -199,7 +199,8 @@ extension WalletModel {
_ = try await sendRequest(request)
}
- func getCurrencyInfo(scope: ScopeInfo, delay: UInt = 0)
+ @MainActor
+ func getCurrencyInfoM(scope: ScopeInfo, delay: UInt = 0)
async throws -> CurrencyInfo {
let request = GetCurrencySpecification(scope: scope)
let response = try await sendRequest(request, ASYNCDELAY + delay)
diff --git a/TalerWallet1/Views/Exchange/ExchangeRowView.swift
b/TalerWallet1/Views/Exchange/ExchangeRowView.swift
index aa93dff..e8dd7de 100644
--- a/TalerWallet1/Views/Exchange/ExchangeRowView.swift
+++ b/TalerWallet1/Views/Exchange/ExchangeRowView.swift
@@ -97,12 +97,12 @@ struct ExchangeRowView: View {
}
}
.task {
- if !controller.hasInfo(for: currency) {
+ if controller.hasInfo(for: currency) == nil {
symLog.log("fetching info for \(currency)")
// FIXME: remove fake ScopeInfo once the REAL one is in
exchange.scopeInfo
let scopeInfo = exchange.scopeInfo ?? ScopeInfo(type: .global,
currency: currency)
do {
- let info = try await model.getCurrencyInfo(scope:
scopeInfo, delay: delay)
+ let info = try await model.getCurrencyInfoM(scope:
scopeInfo, delay: delay)
// logger.info("got info: \(scope.currency, privacy:
.public)")
await controller.setInfo(info)
} catch { // TODO: error handling - couldn't get
CurrencyInfo
diff --git a/TalerWallet1/Views/Main/MainView.swift
b/TalerWallet1/Views/Main/MainView.swift
index 43c6906..ee4b850 100644
--- a/TalerWallet1/Views/Main/MainView.swift
+++ b/TalerWallet1/Views/Main/MainView.swift
@@ -280,11 +280,11 @@ extension MainView {
for balance in newArray {
let scope = balance.scopeInfo
logger.info("balance changed: \(scope.currency, privacy:
.public)")
- if !controller.hasInfo(for: scope.currency) {
+ if controller.hasInfo(for: scope.currency) == nil {
Task { // runs on MainActor
logger.info("Task to get info for:
\(scope.currency, privacy: .public)")
do {
- let info = try await
model.getCurrencyInfo(scope: scope, delay: delay)
+ let info = try await
model.getCurrencyInfoM(scope: scope, delay: delay)
logger.info("got info: \(scope.currency,
privacy: .public)")
await controller.setInfo(info)
} catch { // TODO: error handling - couldn't
get CurrencyInfo
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-ios] branch master updated (a123c3a -> 4167b6d), gnunet, 2024/01/19
- [taler-taler-ios] 06/69: withdraw-exchange, gnunet, 2024/01/19
- [taler-taler-ios] 01/69: WithdrawExchangeV, gnunet, 2024/01/19
- [taler-taler-ios] 04/69: AccountPicker, remove exchangePaytoUris, gnunet, 2024/01/19
- [taler-taler-ios] 03/69: CurrencyInfo from Exchange,
gnunet <=
- [taler-taler-ios] 25/69: colors adapted for WCAG AA, gnunet, 2024/01/19
- [taler-taler-ios] 05/69: ToS language, gnunet, 2024/01/19
- [taler-taler-ios] 19/69: cleanup, gnunet, 2024/01/19
- [taler-taler-ios] 02/69: LoadingView, gnunet, 2024/01/19
- [taler-taler-ios] 12/69: PRINT_CHANGES, gnunet, 2024/01/19
- [taler-taler-ios] 07/69: Haptics, gnunet, 2024/01/19
- [taler-taler-ios] 31/69: Withdraw only once, gnunet, 2024/01/19
- [taler-taler-ios] 22/69: Summary in ThreeAmountsV, gnunet, 2024/01/19
- [taler-taler-ios] 30/69: Layout Balances, gnunet, 2024/01/19
- [taler-taler-ios] 20/69: button color if disabled, gnunet, 2024/01/19