diff --git a/Sources/SatsPrice/ContentView.swift b/Sources/SatsPrice/ContentView.swift index 5e0a8ad..fe047c0 100644 --- a/Sources/SatsPrice/ContentView.swift +++ b/Sources/SatsPrice/ContentView.swift @@ -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() diff --git a/Sources/SatsPrice/SatsViewModel.swift b/Sources/SatsPrice/SatsViewModel.swift index c4a1ea2..13a0cf7 100644 --- a/Sources/SatsPrice/SatsViewModel.swift +++ b/Sources/SatsPrice/SatsViewModel.swift @@ -13,7 +13,7 @@ import Foundation import SwiftUI class SatsViewModel: ObservableObject { - @Published var lastUpdated: Date = Date.now + @Published var lastUpdated: Date? @Published var btcToUsdStringInternal: String = "" @Published var satsStringInternal: String = ""