@@ -66,13 +66,7 @@ final class StoreInfoProvider: TimelineProvider {
6666 ///
6767 func placeholder( in context: Context ) -> StoreInfoEntry {
6868 let dependencies = Self . fetchDependencies ( )
69- return StoreInfoEntry . data ( . init( range: Localization . today,
70- name: dependencies? . storeName ?? Localization . myShop,
71- revenue: Self . formattedAmountString ( for: 132.234 , with: dependencies? . storeCurrencySettings) ,
72- visitors: " 67 " ,
73- orders: " 23 " ,
74- conversion: Self . formattedConversionString ( for: 23 / 67 ) ,
75- updatedTime: Self . currentFormattedTime ( ) ) )
69+ return Self . placeholderEntry ( for: dependencies)
7670 }
7771
7872 /// Quick Snapshot. Required when previewing the widget.
@@ -93,21 +87,11 @@ final class StoreInfoProvider: TimelineProvider {
9387 Task {
9488 do {
9589 let todayStats = try await strongService. fetchTodayStats ( for: dependencies. storeID)
96-
97- let entry = StoreInfoEntry . data ( . init( range: Localization . today,
98- name: dependencies. storeName,
99- revenue: Self . formattedAmountString ( for: todayStats. revenue, with: dependencies. storeCurrencySettings) ,
100- visitors: " \( todayStats. totalVisitors) " ,
101- orders: " \( todayStats. totalOrders) " ,
102- conversion: Self . formattedConversionString ( for: todayStats. conversion) ,
103- updatedTime: Self . currentFormattedTime ( ) ) )
104-
90+ let entry = Self . dataEntry ( for: todayStats, with: dependencies)
10591 let reloadDate = Date ( timeIntervalSinceNow: reloadInterval)
10692 let timeline = Timeline < StoreInfoEntry > ( entries: [ entry] , policy: . after( reloadDate) )
10793 completion ( timeline)
108-
10994 } catch {
110-
11195 // WooFoundation does not expose `DDLOG` types. Should we include them?
11296 print ( " ⛔️ Error fetching today's widget stats: \( error) " )
11397
@@ -148,8 +132,34 @@ private extension StoreInfoProvider {
148132 }
149133}
150134
135+ /// Data configuration
136+ ///
151137private extension StoreInfoProvider {
152138
139+ /// Redacted entry with sample data. If dependencies are available - store name and currency settings will be used.
140+ ///
141+ static func placeholderEntry( for dependencies: Dependencies ? ) -> StoreInfoEntry {
142+ StoreInfoEntry . data ( . init( range: Localization . today,
143+ name: dependencies? . storeName ?? Localization . myShop,
144+ revenue: Self . formattedAmountString ( for: 132.234 , with: dependencies? . storeCurrencySettings) ,
145+ visitors: " 67 " ,
146+ orders: " 23 " ,
147+ conversion: Self . formattedConversionString ( for: 23 / 67 ) ,
148+ updatedTime: Self . currentFormattedTime ( ) ) )
149+ }
150+
151+ /// Real data entry.
152+ ///
153+ static func dataEntry( for todayStats: StoreInfoDataService . Stats , with dependencies: Dependencies ) -> StoreInfoEntry {
154+ StoreInfoEntry . data ( . init( range: Localization . today,
155+ name: dependencies. storeName,
156+ revenue: Self . formattedAmountString ( for: todayStats. revenue, with: dependencies. storeCurrencySettings) ,
157+ visitors: " \( todayStats. totalVisitors) " ,
158+ orders: " \( todayStats. totalOrders) " ,
159+ conversion: Self . formattedConversionString ( for: todayStats. conversion) ,
160+ updatedTime: Self . currentFormattedTime ( ) ) )
161+ }
162+
153163 static func formattedAmountString( for amountValue: Decimal , with currencySettings: CurrencySettings ? ) -> String {
154164 let currencyFormatter = CurrencyFormatter ( currencySettings: currencySettings ?? CurrencySettings ( ) )
155165 return currencyFormatter. formatAmount ( amountValue) ?? Constants . valuePlaceholderText
0 commit comments