-
Notifications
You must be signed in to change notification settings - Fork 121
[Woo POS] Modularization: move shared dependencies to shared frameworks in preparation for POS modularization #16159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jaclync
merged 6 commits into
trunk
from
feat/WOOMOB-935-move-shared-dependencies-to-shared-frameworks
Sep 25, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8a369f6
Move shared extensions of DateFormatter and Decimal to WooFoundation.
jaclync 4d96b72
Move SiteAddress to Yosemite while keeping initializer with singleton…
jaclync beaf00f
Move CountryCode.readableCountry to Yosemite for reuse.
jaclync ffe5cda
Move SiteAddress tests to YosemiteTests.
jaclync 744e19c
Move SafariView and SafariSheet to WooFoundation.
jaclync 6ae4441
Add missing imports for SafariView.
jaclync File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
Modules/Sources/WooFoundation/Extensions/DateFormatter+Extensions.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import Foundation | ||
|
|
||
| /// DateFormatter Extensions | ||
| /// | ||
| extension DateFormatter { | ||
| /// Date formatter used for creating a **localized** date and time string. | ||
| /// | ||
| /// Example output in English: "Jan 28, 2018, 11:23 AM" | ||
| /// | ||
| public static let dateAndTimeFormatter: DateFormatter = { | ||
| let formatter = DateFormatter() | ||
| formatter.setLocalizedDateFormatFromTemplate("MMM d yyyy hh:mm a") | ||
|
|
||
| return formatter | ||
| }() | ||
| } |
8 changes: 2 additions & 6 deletions
8
.../Classes/Extensions/Decimal+Helpers.swift → ...ation/Extensions/Decimal+Extensions.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,18 @@ | ||
| import Foundation | ||
|
|
||
| extension Decimal { | ||
|
|
||
| /// Returns the int value of a decimal. We ensure we round up our Decimal before converting it to an Int, using NSDecimalRound. | ||
| /// | ||
| var intValue: Int { | ||
| public var intValue: Int { | ||
| NSDecimalNumber(decimal: whole).intValue | ||
| } | ||
|
|
||
| func rounded(_ roundingMode: NSDecimalNumber.RoundingMode = .up, scale: Int = 0) -> Self { | ||
| public func rounded(_ roundingMode: NSDecimalNumber.RoundingMode = .up, scale: Int = 0) -> Self { | ||
| var result = Self() | ||
| var number = self | ||
| NSDecimalRound(&result, &number, scale, roundingMode) | ||
| return result | ||
| } | ||
|
|
||
| private var whole: Self { rounded( self < 0 ? .down : .up) } | ||
|
|
||
| private var fraction: Self { self - whole } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Modules/Sources/WooFoundation/UI Components/SafariView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import SwiftUI | ||
| import SafariServices | ||
|
|
||
| /// SwiftUI interface for UIKit SFSafariViewController | ||
| /// Provides a visible interface for web browsing, and Safari features | ||
| /// | ||
| public struct SafariView: UIViewControllerRepresentable { | ||
|
|
||
| private let url: URL | ||
|
|
||
| public init(url: URL) { | ||
| self.url = url | ||
| } | ||
|
|
||
| public func makeUIViewController(context: UIViewControllerRepresentableContext<SafariView>) -> SFSafariViewController { | ||
| return SFSafariViewController(url: url) | ||
| } | ||
|
|
||
| public func updateUIViewController(_ uiViewController: SFSafariViewController, | ||
| context: UIViewControllerRepresentableContext<SafariView>) { | ||
|
|
||
| } | ||
| } |
81 changes: 1 addition & 80 deletions
81
WooCommerce/Classes/Tools/SiteAddress.swift → ...ensions/CountryCode+readableCountry.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import Foundation | ||
| import WooFoundation | ||
|
|
||
| /// Represent and parse the Address of the store, returned in the SiteSettings API `/settings/general/` | ||
| /// | ||
| public class SiteAddress { | ||
|
|
||
| private let siteSettings: [SiteSetting] | ||
|
|
||
| public var address: String { | ||
| return getValueFromSiteSettings(Constants.address) ?? "" | ||
| } | ||
|
|
||
| public var address2: String { | ||
| return getValueFromSiteSettings(Constants.address2) ?? "" | ||
| } | ||
|
|
||
| public var city: String { | ||
| return getValueFromSiteSettings(Constants.city) ?? "" | ||
| } | ||
|
|
||
| public var postalCode: String { | ||
| return getValueFromSiteSettings(Constants.postalCode) ?? "" | ||
| } | ||
|
|
||
| public var countryCode: CountryCode { | ||
| guard let countryComponent = getCountryAndStateComponents().first else { | ||
| DDLogError("⛔️ Could not determine country code for site address: no country component found.") | ||
| return .unknown | ||
| } | ||
| guard let countryCode = CountryCode(rawValue: countryComponent) else { | ||
| DDLogError("⛔️ Could not determine country code for country: \(countryComponent)") | ||
| return .unknown | ||
| } | ||
| return countryCode | ||
| } | ||
|
|
||
| /// Returns the name of the country associated with the current store. | ||
| /// The default store country is provided in a format like `HK:KOWLOON` | ||
| /// This method will transform `HK:KOWLOON` into `Hong Kong` | ||
| /// Will return nil if it can not figure out a valid country name | ||
| public var countryName: String? { | ||
| guard countryCode != .unknown else { | ||
| return nil | ||
| } | ||
|
|
||
| return countryCode.readableCountry | ||
| } | ||
|
|
||
| public var state: String { | ||
| return getCountryAndStateComponents().last ?? "" | ||
| } | ||
|
|
||
| public init(siteSettings: [SiteSetting]) { | ||
| self.siteSettings = siteSettings | ||
| } | ||
|
|
||
| private func getCountryAndStateComponents() -> [String] { | ||
| getValueFromSiteSettings(Constants.countryAndState)?.components(separatedBy: ":") ?? [] | ||
| } | ||
|
|
||
| private func getValueFromSiteSettings(_ settingID: String) -> String? { | ||
| return siteSettings.first { (setting) -> Bool in | ||
| return setting.settingID == settingID | ||
| }?.value | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Constants. | ||
| // | ||
| private extension SiteAddress { | ||
| /// The key of the SiteSetting containing the store address | ||
| enum Constants { | ||
| static let address = "woocommerce_store_address" | ||
| static let address2 = "woocommerce_store_address_2" | ||
| static let city = "woocommerce_store_city" | ||
| static let postalCode = "woocommerce_store_postcode" | ||
| static let countryAndState = "woocommerce_default_country" | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
...ommerceTests/Tools/SiteAddressTests.swift → ...sts/Tools/Settings/SiteAddressTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
WooCommerce/Classes/Extensions/SiteAddress+ServiceLocator.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import class Yosemite.SiteAddress | ||
|
|
||
| extension SiteAddress { | ||
| convenience init() { | ||
| self.init(siteSettings: ServiceLocator.selectedSiteSettings.siteSettings) | ||
| } | ||
| } | ||
1 change: 1 addition & 0 deletions
1
WooCommerce/Classes/POS/Presentation/Settings/POSSettingsStoreViewModel.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
WooCommerce/Classes/POS/Presentation/Settings/PointOfSaleSettingsHardwareDetailView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
WooCommerce/Classes/POS/Presentation/Settings/PointOfSaleSettingsHelpDetailView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...e/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/CardReaderManualRowView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
WooCommerce/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/SafariView.swift
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
.../Classes/ViewRelated/Orders/Order Details/WCShip Installation Process/WCShipCTAView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, a good way to keep the backwards compatibility and avoid unnecessary changes after the refactoring 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, there are a few such usage in the app.