Skip to content

Commit 6529ff7

Browse files
committed
Merge Trunk
2 parents 1f8f6ad + a8860c2 commit 6529ff7

File tree

5 files changed

+41
-25
lines changed

5 files changed

+41
-25
lines changed

WooCommerce/Classes/Tools/Shared Site Settings/SelectedSiteSettings.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extension SelectedSiteSettings {
6363
ServiceLocator.currencySettings.updateCurrencyOptions(with: $0)
6464
}
6565

66+
// Needed to correcly format the widget data.
6667
UserDefaults.group?[.defaultStoreCurrencySettings] = try? JSONEncoder().encode(ServiceLocator.currencySettings)
6768
}
6869
}

WooCommerce/Classes/Yosemite/DefaultStoresManager.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ private extension DefaultStoresManager {
511511
UserDefaults.group?[.defaultStoreID] = siteID
512512
UserDefaults.group?[.defaultStoreName] = sessionManager.defaultSite?.name
513513

514+
// Currency Settings are stored in `SelectedSiteSettings.defaultStoreCurrencySettings`
515+
514516
// Reload widgets UI
515517
WidgetCenter.shared.reloadAllTimelines()
516518
}

WooCommerce/StoreWidgets/StoreInfoProvider.swift

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
///
151137
private 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

WooCommerce/StoreWidgets/StoreInfoWidget.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ struct StoreInfoWidget: Widget {
2020
}
2121
}
2222
}
23-
.configurationDisplayName(Localization.storeInfo)
23+
.configurationDisplayName(Localization.title)
24+
.description(Localization.description)
2425
.supportedFamilies([.systemMedium])
2526
}
2627
}
@@ -157,11 +158,16 @@ private struct UnableToFetchView: View {
157158
///
158159
private extension StoreInfoWidget {
159160
enum Localization {
160-
static let storeInfo = AppLocalizedString(
161+
static let title = AppLocalizedString(
161162
"storeWidgets.displayName",
162-
value: "Store Info",
163+
value: "Today",
163164
comment: "Widget title, displayed when selecting which widget to add"
164165
)
166+
static let description = AppLocalizedString(
167+
"storeWidgets.description",
168+
value: "WooCommerce Stats Today",
169+
comment: "Widget description, displayed when selecting which widget to add"
170+
)
165171
}
166172
}
167173

@@ -191,7 +197,7 @@ private extension StoreInfoView {
191197
)
192198
static func updatedAt(_ updatedTime: String) -> LocalizedString {
193199
let format = AppLocalizedString("storeWidgets.infoView.updatedAt",
194-
value: "as of %1$@",
200+
value: "As of %1$@",
195201
comment: "Displays the time when the widget was last updated. %1$@ is the time to render.")
196202
return LocalizedString.localizedStringWithFormat(format, updatedTime)
197203
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11100,7 +11100,6 @@
1110011100
INFOPLIST_FILE = StoreWidgets/Info.plist;
1110111101
INFOPLIST_KEY_CFBundleDisplayName = StoreWidgets;
1110211102
INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2022 Automattic. All rights reserved.";
11103-
IPHONEOS_DEPLOYMENT_TARGET = 15.5;
1110411103
LD_RUNPATH_SEARCH_PATHS = (
1110511104
"$(inherited)",
1110611105
"@executable_path/Frameworks",
@@ -11135,7 +11134,6 @@
1113511134
INFOPLIST_FILE = StoreWidgets/Info.plist;
1113611135
INFOPLIST_KEY_CFBundleDisplayName = StoreWidgets;
1113711136
INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2022 Automattic. All rights reserved.";
11138-
IPHONEOS_DEPLOYMENT_TARGET = 15.5;
1113911137
LD_RUNPATH_SEARCH_PATHS = (
1114011138
"$(inherited)",
1114111139
"@executable_path/Frameworks",
@@ -11169,7 +11167,6 @@
1116911167
INFOPLIST_FILE = StoreWidgets/Info.plist;
1117011168
INFOPLIST_KEY_CFBundleDisplayName = StoreWidgets;
1117111169
INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2022 Automattic. All rights reserved.";
11172-
IPHONEOS_DEPLOYMENT_TARGET = 15.5;
1117311170
LD_RUNPATH_SEARCH_PATHS = (
1117411171
"$(inherited)",
1117511172
"@executable_path/Frameworks",

0 commit comments

Comments
 (0)