Merge branch 'master' into widgetkotlin

This commit is contained in:
Marcos Rodriguez Velez 2024-07-16 08:39:29 -04:00
commit d89c8d7602
No known key found for this signature in database
GPG Key ID: 6030B2F48CCE86D7

View File

@ -49,9 +49,18 @@ struct PriceWidgetProvider: TimelineProvider {
let previousEntry = PriceWidgetProvider.lastSuccessfulEntry
let previousMarketData = previousEntry?.currentMarketData
let entry = PriceWidgetEntry(date: Date(), family: context.family, currentMarketData: currentMarketData, previousMarketData: previousMarketData ?? emptyMarketData)
PriceWidgetProvider.lastSuccessfulEntry = entry
entries.append(entry)
// Check if the new fetched price is the same as the current price
if let previousMarketData = previousMarketData, previousMarketData.rate == currentMarketData.rate {
// If the new price is the same, only update the date
let updatedEntry = PriceWidgetEntry(date: Date(), family: context.family, currentMarketData: previousMarketData, previousMarketData: previousEntry?.previousMarketData ?? emptyMarketData)
PriceWidgetProvider.lastSuccessfulEntry = updatedEntry
entries.append(updatedEntry)
} else {
// If the new price is different, update the data
let entry = PriceWidgetEntry(date: Date(), family: context.family, currentMarketData: currentMarketData, previousMarketData: previousMarketData ?? emptyMarketData)
PriceWidgetProvider.lastSuccessfulEntry = entry
entries.append(entry)
}
} else {
// Use the last successful entry if available
if let lastEntry = PriceWidgetProvider.lastSuccessfulEntry {