Skip to content

Commit

Permalink
Share store TZ to extension
Browse files Browse the repository at this point in the history
  • Loading branch information
ealeksandrov committed Sep 12, 2022
1 parent 06e4392 commit 76eac48
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions WooCommerce/Classes/Extensions/UserDefaults+Woo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extension UserDefaults {
case defaultSiteAddress
case defaultStoreID
case defaultStoreName
case defaultStoreTimeZoneGMTOffset
case defaultAnonymousID
case defaultRoles
case deviceID
Expand Down
1 change: 1 addition & 0 deletions WooCommerce/Classes/Yosemite/DefaultStoresManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ private extension DefaultStoresManager {
// Non-critical store info
UserDefaults.group?[.defaultStoreID] = siteID
UserDefaults.group?[.defaultStoreName] = sessionManager.defaultSite?.name
UserDefaults.group?[.defaultStoreTimeZoneGMTOffset] = sessionManager.defaultSite?.siteTimezone.secondsFromGMT() ?? TimeZone.current.secondsFromGMT()

// Reload widgets UI
WidgetCenter.shared.reloadAllTimelines()
Expand Down
7 changes: 5 additions & 2 deletions WooCommerce/StoreWidgets/StoreInfoProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ private extension StoreInfoProvider {
let authToken: String
let storeID: Int64
let storeName: String
let storeTimeZone: TimeZone
}

/// Fetches the required dependencies from the keychain and the shared users default.
Expand All @@ -112,10 +113,12 @@ private extension StoreInfoProvider {
let keychain = Keychain(service: WooConstants.keychainServiceName)
guard let authToken = keychain[WooConstants.authToken],
let storeID = UserDefaults.group?[.defaultStoreID] as? Int64,
let storeName = UserDefaults.group?[.defaultStoreName] as? String else {
let storeName = UserDefaults.group?[.defaultStoreName] as? String,
let storeTimeZoneGMTOffset = UserDefaults.group?[.defaultStoreTimeZoneGMTOffset] as? Int,
let storeTimeZone = TimeZone(secondsFromGMT: storeTimeZoneGMTOffset) else {
return nil
}
return Dependencies(authToken: authToken, storeID: storeID, storeName: storeName)
return Dependencies(authToken: authToken, storeID: storeID, storeName: storeName, storeTimeZone: storeTimeZone)
}
}

Expand Down

0 comments on commit 76eac48

Please sign in to comment.