Fix last updated timestamp to be accurate when switching price source
This commit is contained in:
@@ -66,8 +66,8 @@ public struct ContentView: View {
|
|||||||
} header: {
|
} header: {
|
||||||
Text("1 BTC to USD")
|
Text("1 BTC to USD")
|
||||||
} footer: {
|
} footer: {
|
||||||
if priceSource != .manual {
|
if priceSource != .manual, let lastUpdated = satsViewModel.lastUpdated {
|
||||||
Text("Last updated: \(dateFormatter.string(from: satsViewModel.lastUpdated))")
|
Text("Last updated: \(dateFormatter.string(from: lastUpdated))")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +102,7 @@ public struct ContentView: View {
|
|||||||
await updatePrice()
|
await updatePrice()
|
||||||
}
|
}
|
||||||
.onChange(of: priceSource) { newPriceSource in
|
.onChange(of: priceSource) { newPriceSource in
|
||||||
|
satsViewModel.lastUpdated = nil
|
||||||
priceFetcherDelegator.priceSource = newPriceSource
|
priceFetcherDelegator.priceSource = newPriceSource
|
||||||
Task {
|
Task {
|
||||||
await updatePrice()
|
await updatePrice()
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import Foundation
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
class SatsViewModel: ObservableObject {
|
class SatsViewModel: ObservableObject {
|
||||||
@Published var lastUpdated: Date = Date.now
|
@Published var lastUpdated: Date?
|
||||||
|
|
||||||
@Published var btcToUsdStringInternal: String = ""
|
@Published var btcToUsdStringInternal: String = ""
|
||||||
@Published var satsStringInternal: String = ""
|
@Published var satsStringInternal: String = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user