Fix last updated timestamp to be accurate when switching price source

This commit is contained in:
2024-08-31 10:39:35 +03:00
parent 7f22956557
commit c15eb81995
2 changed files with 4 additions and 3 deletions

View File

@@ -66,8 +66,8 @@ public struct ContentView: View {
} header: {
Text("1 BTC to USD")
} footer: {
if priceSource != .manual {
Text("Last updated: \(dateFormatter.string(from: satsViewModel.lastUpdated))")
if priceSource != .manual, let lastUpdated = satsViewModel.lastUpdated {
Text("Last updated: \(dateFormatter.string(from: lastUpdated))")
}
}
@@ -102,6 +102,7 @@ public struct ContentView: View {
await updatePrice()
}
.onChange(of: priceSource) { newPriceSource in
satsViewModel.lastUpdated = nil
priceFetcherDelegator.priceSource = newPriceSource
Task {
await updatePrice()