From 44c2d943528a12ba265457b71e6bc47ae67f9a13 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Fri, 3 Nov 2023 02:11:07 +0200 Subject: [PATCH 01/26] Update: correctly hook up add domain button to common function --- .../Me/All Domains/Views/AllDomainsListViewController.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Me/All Domains/Views/AllDomainsListViewController.swift b/WordPress/Classes/ViewRelated/Me/All Domains/Views/AllDomainsListViewController.swift index 7623c4a0d349..74d7d8123697 100644 --- a/WordPress/Classes/ViewRelated/Me/All Domains/Views/AllDomainsListViewController.swift +++ b/WordPress/Classes/ViewRelated/Me/All Domains/Views/AllDomainsListViewController.swift @@ -70,10 +70,11 @@ final class AllDomainsListViewController: UIViewController { private func setupBarButtonItems() { let addAction = UIAction { [weak self] _ in - self?.navigateToAddDomain() + self?.viewModel.addDomainAction?() } let addBarButtonItem = UIBarButtonItem(systemItem: .add, primaryAction: addAction) - self.navigationItem.rightBarButtonItem = .init(systemItem: .add) + + self.navigationItem.rightBarButtonItem = addBarButtonItem } private func setupSearchBar() { From 6cefb09d1d6531e9a5c30d22f1b71485bdc96eb7 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Fri, 3 Nov 2023 04:18:53 +0200 Subject: [PATCH 02/26] Update: refactor domain suggestions to handle not passing a site --- ...DomainSuggestionsTableViewController.swift | 5 ++-- ...isterDomainSuggestionsViewController.swift | 29 ++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/DomainSuggestionsTableViewController.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/DomainSuggestionsTableViewController.swift index e18abc2660be..6a598a85e1df 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/DomainSuggestionsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/DomainSuggestionsTableViewController.swift @@ -33,7 +33,7 @@ class DomainSuggestionsTableViewController: UITableViewController { weak var delegate: DomainSuggestionsTableViewControllerDelegate? var domainSuggestionType: DomainsServiceRemote.DomainSuggestionType = .noWordpressDotCom var domainSelectionType: DomainSelectionType? - var primaryDomainAddress: String = "" + var primaryDomainAddress: String? var useFadedColorForParentDomains: Bool { return false @@ -287,7 +287,8 @@ extension DomainSuggestionsTableViewController { private func topBannerCell() -> UITableViewCell { let cell = UITableViewCell() - guard let textLabel = cell.textLabel else { + guard let textLabel = cell.textLabel, + let primaryDomainAddress else { return cell } diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift index 3dfeefa20b90..61081b6137f2 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift @@ -19,7 +19,7 @@ class RegisterDomainSuggestionsViewController: UIViewController { private var constraintsInitialized = false - private var site: Blog! + private var site: Blog? var domainPurchasedCallback: DomainPurchasedCallback! var domainAddedToCartCallback: DomainAddedToCartCallback? @@ -53,7 +53,7 @@ class RegisterDomainSuggestionsViewController: UIViewController { return buttonViewController }() - static func instance(site: Blog, + static func instance(site: Blog?, domainSelectionType: DomainSelectionType = .registerWithPaidPlan, includeSupportButton: Bool = true, domainPurchasedCallback: DomainPurchasedCallback? = nil) -> RegisterDomainSuggestionsViewController { @@ -68,7 +68,11 @@ class RegisterDomainSuggestionsViewController: UIViewController { return controller } - private static func siteNameForSuggestions(for site: Blog) -> String? { + private static func siteNameForSuggestions(for site: Blog?) -> String? { + guard let site else { + return nil + } + if let siteTitle = site.settings?.name?.nonEmptyString() { return siteTitle } @@ -175,9 +179,9 @@ class RegisterDomainSuggestionsViewController: UIViewController { vc.siteName = siteName vc.blog = site vc.domainSelectionType = domainSelectionType - vc.primaryDomainAddress = site.primaryDomainAddress + vc.primaryDomainAddress = site?.primaryDomainAddress - if site.hasBloggerPlan { + if site?.hasBloggerPlan == true { vc.domainSuggestionType = .allowlistedTopLevelDomains(["blog"]) } @@ -220,8 +224,11 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega guard let domain = domain else { return } - - WPAnalytics.track(.domainsSearchSelectDomainTapped, properties: WPAnalytics.domainsProperties(for: site), blog: site) + if let site { + WPAnalytics.track(.domainsSearchSelectDomainTapped, properties: WPAnalytics.domainsProperties(for: site), blog: site) + } else { + WPAnalytics.track(.domainsSearchSelectDomainTapped) + } let onFailure: () -> () = { [weak self] in self?.displayActionableNotice(title: TextContent.errorTitle, actionTitle: TextContent.errorDismiss) @@ -268,7 +275,7 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega } private func pushRegisterDomainDetailsViewController(_ domain: FullyQuotedDomainSuggestion) { - guard let siteID = site.dotComID?.intValue else { + guard let siteID = site?.dotComID?.intValue else { DDLogError("Cannot register domains for sites without a dotComID") return } @@ -284,10 +291,11 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega self.navigationController?.pushViewController(controller, animated: true) } + // TODO: Create a counterpart that handles no site private func createCart(_ domain: FullyQuotedDomainSuggestion, onSuccess: @escaping () -> (), onFailure: @escaping () -> ()) { - guard let siteID = site.dotComID?.intValue else { + guard let siteID = site?.dotComID?.intValue else { DDLogError("Cannot register domains for sites without a dotComID") return } @@ -341,7 +349,8 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega } private func presentWebViewForCurrentSite(domainSuggestion: FullyQuotedDomainSuggestion) { - guard let homeURL = site.homeURL, + guard let site, + let homeURL = site.homeURL, let siteUrl = URL(string: homeURL as String), let host = siteUrl.host, let url = URL(string: Constants.checkoutWebAddress + host), let siteID = site.dotComID?.intValue else { From 195d4498488a0f0bd4d72e26138f75168d538f16 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Fri, 3 Nov 2023 04:40:51 +0200 Subject: [PATCH 03/26] Update: introduce new domain selection type --- .../DomainSuggestionsTableViewController.swift | 3 ++- .../RegisterDomainSuggestionsViewController.swift | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/DomainSuggestionsTableViewController.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/DomainSuggestionsTableViewController.swift index 6a598a85e1df..aae765d51180 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/DomainSuggestionsTableViewController.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/DomainSuggestionsTableViewController.swift @@ -378,7 +378,8 @@ extension DomainSuggestionsTableViewController { let attributedString = NSMutableAttributedString() let hasDomainCredit = blog?.hasDomainCredit ?? false - let freeForFirstYear = hasDomainCredit || domainSelectionType == .purchaseWithPaidPlan + let supportsPlans = domainSelectionType == .purchaseWithPaidPlan || domainSelectionType == .purchaseFromDomainManagement + let freeForFirstYear = hasDomainCredit || supportsPlans if freeForFirstYear { attributedString.append(attributedFreeForTheFirstYear()) diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift index 61081b6137f2..2b8c345abfcc 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift @@ -8,6 +8,7 @@ enum DomainSelectionType { case registerWithPaidPlan case purchaseWithPaidPlan case purchaseSeparately + case purchaseFromDomainManagement } class RegisterDomainSuggestionsViewController: UIViewController { @@ -262,6 +263,8 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega }, onFailure: onFailure ) + case .purchaseFromDomainManagement: + print("Hello world") } } From 70d35a0026fc5ed152369b5d651552b73e0231c1 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Fri, 3 Nov 2023 06:06:22 +0200 Subject: [PATCH 04/26] Update: refactor `RegisterDomainDetailsServiceProxy` to accept nil as siteID --- .../ViewModel/RegisterDomainDetailsServiceProxy.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainDetails/ViewModel/RegisterDomainDetailsServiceProxy.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainDetails/ViewModel/RegisterDomainDetailsServiceProxy.swift index 55fc74ae22cf..c7155b937d15 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainDetails/ViewModel/RegisterDomainDetailsServiceProxy.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainDetails/ViewModel/RegisterDomainDetailsServiceProxy.swift @@ -34,13 +34,13 @@ protocol RegisterDomainDetailsServiceProxyProtocol { failure: @escaping (Error) -> Void) func createTemporaryDomainShoppingCart( - siteID: Int, + siteID: Int?, domainSuggestion: DomainSuggestion, privacyProtectionEnabled: Bool, success: @escaping (CartResponseProtocol) -> Void, failure: @escaping (Error) -> Void) - func createPersistentDomainShoppingCart(siteID: Int, + func createPersistentDomainShoppingCart(siteID: Int?, domainSuggestion: DomainSuggestion, privacyProtectionEnabled: Bool, success: @escaping (CartResponseProtocol) -> Void, @@ -164,7 +164,7 @@ class RegisterDomainDetailsServiceProxy: RegisterDomainDetailsServiceProxyProtoc } func createTemporaryDomainShoppingCart( - siteID: Int, + siteID: Int?, domainSuggestion: DomainSuggestion, privacyProtectionEnabled: Bool, success: @escaping (CartResponseProtocol) -> Void, @@ -177,7 +177,7 @@ class RegisterDomainDetailsServiceProxy: RegisterDomainDetailsServiceProxyProtoc failure: failure) } - func createPersistentDomainShoppingCart(siteID: Int, + func createPersistentDomainShoppingCart(siteID: Int?, domainSuggestion: DomainSuggestion, privacyProtectionEnabled: Bool, success: @escaping (CartResponseProtocol) -> Void, From 6bcb7b9accf4509f239bccedc68434fb259e998a Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 02:41:50 +0200 Subject: [PATCH 05/26] Update: refactor RegisterDomainSuggestionsVC's helpers to handle no siteID --- ...egisterDomainSuggestionsViewController.swift | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift index 2b8c345abfcc..ffe74f5ba130 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift @@ -21,7 +21,7 @@ class RegisterDomainSuggestionsViewController: UIViewController { private var constraintsInitialized = false private var site: Blog? - var domainPurchasedCallback: DomainPurchasedCallback! + var domainPurchasedCallback: DomainPurchasedCallback? var domainAddedToCartCallback: DomainAddedToCartCallback? private var domain: FullyQuotedDomainSuggestion? @@ -298,11 +298,7 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega private func createCart(_ domain: FullyQuotedDomainSuggestion, onSuccess: @escaping () -> (), onFailure: @escaping () -> ()) { - guard let siteID = site?.dotComID?.intValue else { - DDLogError("Cannot register domains for sites without a dotComID") - return - } - + let siteID = site?.dotComID?.intValue let proxy = RegisterDomainDetailsServiceProxy() proxy.createPersistentDomainShoppingCart(siteID: siteID, domainSuggestion: domain.remoteSuggestion(), @@ -324,14 +320,12 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega /// /// - Parameters: /// - newURL: the newly set URL for the web view. - /// - siteID: the ID of the site we're trying to register the domain against. /// - domain: the domain the user is purchasing. /// - onCancel: the closure that will be executed if we detect the conditions for cancelling the registration were met. /// - onSuccess: the closure that will be executed if we detect a successful domain registration. /// private func handleWebViewURLChange( _ newURL: URL, - siteID: Int, domain: String, onCancel: () -> Void, onSuccess: (String) -> Void) { @@ -355,8 +349,7 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega guard let site, let homeURL = site.homeURL, let siteUrl = URL(string: homeURL as String), let host = siteUrl.host, - let url = URL(string: Constants.checkoutWebAddress + host), - let siteID = site.dotComID?.intValue else { + let url = URL(string: Constants.checkoutWebAddress + host) else { return } @@ -375,7 +368,7 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega return } - self.handleWebViewURLChange(newURL, siteID: siteID, domain: domainSuggestion.domainName, onCancel: { + self.handleWebViewURLChange(newURL, domain: domainSuggestion.domainName, onCancel: { navController.dismiss(animated: true) }) { domain in self.dismiss(animated: true, completion: { [weak self] in @@ -383,7 +376,7 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega return } - self.domainPurchasedCallback(self, domain) + self.domainPurchasedCallback?(self, domain) }) } } From d77f52d8b62e37259d09b2829818d04f97497ca1 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 03:31:19 +0200 Subject: [PATCH 06/26] Add: Basic implementation of `AllDomainsAddDomainCoordinator` --- .../AllDomainsAddDomainCoordinator.swift | 30 +++++++++++++++++++ WordPress/WordPress.xcodeproj/project.pbxproj | 14 +++++++++ 2 files changed, 44 insertions(+) create mode 100644 WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift diff --git a/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift b/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift new file mode 100644 index 000000000000..fa0dc227e34f --- /dev/null +++ b/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift @@ -0,0 +1,30 @@ +import Foundation + +@objc final class AllDomainsAddDomainCoordinator: NSObject { + static func presentAddDomainFlow(in allDomainsViewController: AllDomainsListViewController, + source: String) { + let domainSuggestionsViewController = RegisterDomainSuggestionsViewController.instance( + site: nil, + domainSelectionType: .purchaseFromDomainManagement, + includeSupportButton: false, + title: Strings.searchTitle + ) + + let domainPurchasedCallback = { (domainViewController: RegisterDomainSuggestionsViewController, domainName: String) in + allDomainsViewController.reloadDomains() + } + + domainSuggestionsViewController.domainPurchasedCallback = domainPurchasedCallback + + let navigationController = UINavigationController(rootViewController: domainSuggestionsViewController) + navigationController.isModalInPresentation = true + allDomainsViewController.present(navigationController, animated: true) + } +} + +extension AllDomainsAddDomainCoordinator { + private enum Strings { + static let searchTitle = NSLocalizedString("Search for a domain", + comment: "Search domain - Title for the Suggested domains screen") + } +} diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index 7aba258db563..bb025682a85e 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -1726,6 +1726,8 @@ 8031F34A292FF46B00E8F95E /* ExtensionConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800035C0292307E8007D2D26 /* ExtensionConfiguration.swift */; }; 8031F34B292FF46E00E8F95E /* ExtensionConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800035C0292307E8007D2D26 /* ExtensionConfiguration.swift */; }; 8031F34C29302A2500E8F95E /* ExtensionConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800035C229230A0B007D2D26 /* ExtensionConfiguration.swift */; }; + 80348F2E2AF870A70045CCD3 /* AllDomainsAddDomainCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80348F2D2AF870A70045CCD3 /* AllDomainsAddDomainCoordinator.swift */; }; + 80348F2F2AF870A70045CCD3 /* AllDomainsAddDomainCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80348F2D2AF870A70045CCD3 /* AllDomainsAddDomainCoordinator.swift */; }; 80379C6E2A5C0D8F00D924AC /* PostTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80379C6D2A5C0D8F00D924AC /* PostTests.swift */; }; 80379C6F2A5C0D8F00D924AC /* PostTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80379C6D2A5C0D8F00D924AC /* PostTests.swift */; }; 803BB9792959543D00B3F6D6 /* RootViewCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 803BB9782959543D00B3F6D6 /* RootViewCoordinator.swift */; }; @@ -7327,6 +7329,7 @@ 801D9519291AC0B00051993E /* OverlayFrequencyTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverlayFrequencyTracker.swift; sourceTree = ""; }; 801D951C291ADB7E0051993E /* OverlayFrequencyTrackerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverlayFrequencyTrackerTests.swift; sourceTree = ""; }; 80293CF6284450AD0083F946 /* WordPress-Swift.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WordPress-Swift.h"; sourceTree = ""; }; + 80348F2D2AF870A70045CCD3 /* AllDomainsAddDomainCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllDomainsAddDomainCoordinator.swift; sourceTree = ""; }; 80379C6D2A5C0D8F00D924AC /* PostTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostTests.swift; sourceTree = ""; }; 803BB9782959543D00B3F6D6 /* RootViewCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootViewCoordinator.swift; sourceTree = ""; }; 803BB97B2959559500B3F6D6 /* RootViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootViewPresenter.swift; sourceTree = ""; }; @@ -10156,6 +10159,7 @@ 08D61F1F2AD0633600BF3D00 /* All Domains */ = { isa = PBXGroup; children = ( + 80348F2C2AF8708A0045CCD3 /* Coordinators */, F4141EF02AE99F14000D2AAE /* View Models */, F4141EEF2AE99EE2000D2AAE /* Views */, ); @@ -13278,6 +13282,14 @@ name = "Lottie Animations"; sourceTree = ""; }; + 80348F2C2AF8708A0045CCD3 /* Coordinators */ = { + isa = PBXGroup; + children = ( + 80348F2D2AF870A70045CCD3 /* AllDomainsAddDomainCoordinator.swift */, + ); + path = Coordinators; + sourceTree = ""; + }; 803BB97E295957A200B3F6D6 /* Root View */ = { isa = PBXGroup; children = ( @@ -22355,6 +22367,7 @@ 8261B4CC1EA8E13700668298 /* SVProgressHUD+Dismiss.m in Sources */, 329F8E5624DDAC61002A5311 /* DynamicHeightCollectionView.swift in Sources */, FECA442F28350B7800D01F15 /* PromptRemindersScheduler.swift in Sources */, + 80348F2E2AF870A70045CCD3 /* AllDomainsAddDomainCoordinator.swift in Sources */, 0CB424EE2ADEE3CD0080B807 /* PostSearchTokenTableCell.swift in Sources */, 436D56242117312700CEAA33 /* RegisterDomainDetailsViewModel+RowList.swift in Sources */, C81CCD65243AECA200A83E27 /* TenorGIF.swift in Sources */, @@ -24891,6 +24904,7 @@ FABB23DF2602FC2C00C8785C /* BlogSelectorViewController.m in Sources */, FABB23E02602FC2C00C8785C /* HomepageSettingsViewController.swift in Sources */, 93E6336D272AF504009DACF8 /* LoginEpilogueDividerView.swift in Sources */, + 80348F2F2AF870A70045CCD3 /* AllDomainsAddDomainCoordinator.swift in Sources */, FABB23E12602FC2C00C8785C /* TenorMediaGroup.swift in Sources */, FABB23E22602FC2C00C8785C /* SiteSuggestionService.swift in Sources */, FABB23E32602FC2C00C8785C /* NotificationsViewController+PushPrimer.swift in Sources */, From 7144701eacb72e8d32a34fa22ae777f8fb24ad27 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 03:32:14 +0200 Subject: [PATCH 07/26] Update: add public function to reload domains list after purchase --- .../Me/All Domains/Views/AllDomainsListViewController.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/WordPress/Classes/ViewRelated/Me/All Domains/Views/AllDomainsListViewController.swift b/WordPress/Classes/ViewRelated/Me/All Domains/Views/AllDomainsListViewController.swift index 74d7d8123697..8b4bb91bf35d 100644 --- a/WordPress/Classes/ViewRelated/Me/All Domains/Views/AllDomainsListViewController.swift +++ b/WordPress/Classes/ViewRelated/Me/All Domains/Views/AllDomainsListViewController.swift @@ -45,6 +45,12 @@ final class AllDomainsListViewController: UIViewController { fatalError("init(coder:) has not been implemented") } + // MARK: Public Functions + + func reloadDomains() { + viewModel.loadData() + } + // MARK: - View Lifecycle override func viewDidLoad() { From cf8bf05176c6f2f4568a2649a74f0bcffd35d932 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 03:33:05 +0200 Subject: [PATCH 08/26] Update: add ability to customize title of suggestions view --- .../RegisterDomainSuggestionsViewController.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift index ffe74f5ba130..47ae2c327500 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift @@ -29,6 +29,7 @@ class RegisterDomainSuggestionsViewController: UIViewController { private var domainsTableViewController: DomainSuggestionsTableViewController? private var domainSelectionType: DomainSelectionType = .registerWithPaidPlan private var includeSupportButton: Bool = true + private var navBarTitle: String = TextContent.title private var webViewURLChangeObservation: NSKeyValueObservation? @@ -57,6 +58,7 @@ class RegisterDomainSuggestionsViewController: UIViewController { static func instance(site: Blog?, domainSelectionType: DomainSelectionType = .registerWithPaidPlan, includeSupportButton: Bool = true, + title: String = TextContent.title, domainPurchasedCallback: DomainPurchasedCallback? = nil) -> RegisterDomainSuggestionsViewController { let storyboard = UIStoryboard(name: Constants.storyboardIdentifier, bundle: Bundle.main) let controller = storyboard.instantiateViewController(withIdentifier: Constants.viewControllerIdentifier) as! RegisterDomainSuggestionsViewController @@ -65,6 +67,7 @@ class RegisterDomainSuggestionsViewController: UIViewController { controller.domainPurchasedCallback = domainPurchasedCallback controller.includeSupportButton = includeSupportButton controller.siteName = siteNameForSuggestions(for: site) + controller.navBarTitle = title return controller } @@ -89,7 +92,7 @@ class RegisterDomainSuggestionsViewController: UIViewController { } private func configure() { - title = TextContent.title + title = navBarTitle WPStyleGuide.configureColors(view: view, tableView: nil) /// If this is the first view controller in the navigation controller - show the cancel button From 536cdcd3ec1bcf56b0bcdb3303746a0b1bfc5d00 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 05:10:23 +0200 Subject: [PATCH 09/26] Update: Add support for custom title in checkout --- WordPress/Classes/Utility/WebKitViewController.swift | 6 ++++-- WordPress/Classes/Utility/WebViewControllerFactory.swift | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/WordPress/Classes/Utility/WebKitViewController.swift b/WordPress/Classes/Utility/WebKitViewController.swift index f08b8e343ee3..d4ceea2cc77f 100644 --- a/WordPress/Classes/Utility/WebKitViewController.swift +++ b/WordPress/Classes/Utility/WebKitViewController.swift @@ -513,8 +513,10 @@ class WebKitViewController: UIViewController, WebKitAuthenticatable { assertionFailure("Observed change to web view that we are not handling") } - // Set the title for the HUD which shows up on tap+hold w/ accessibile font sizes enabled - navigationItem.title = "\(titleView.titleLabel.text ?? "")\n\n\(String(describing: titleView.subtitleLabel.text ?? ""))" + if customTitle == nil { + // Set the title for the HUD which shows up on tap+hold w/ accessibile font sizes enabled + navigationItem.title = "\(titleView.titleLabel.text ?? "")\n\n\(String(describing: titleView.subtitleLabel.text ?? ""))" + } // Accessibility values which emulate those found in Safari navigationItem.accessibilityLabel = NSLocalizedString("Title", comment: "Accessibility label for web page preview title") diff --git a/WordPress/Classes/Utility/WebViewControllerFactory.swift b/WordPress/Classes/Utility/WebViewControllerFactory.swift index cce60657d323..654bb0323d96 100644 --- a/WordPress/Classes/Utility/WebViewControllerFactory.swift +++ b/WordPress/Classes/Utility/WebViewControllerFactory.swift @@ -45,10 +45,13 @@ class WebViewControllerFactory: NSObject { return controller(configuration: configuration, source: source) } - static func controllerWithDefaultAccountAndSecureInteraction(url: URL, source: String) -> WebKitViewController { + static func controllerWithDefaultAccountAndSecureInteraction(url: URL, + source: String, + title: String? = nil) -> WebKitViewController { let configuration = WebViewControllerConfiguration(url: url) configuration.authenticateWithDefaultAccount() configuration.secureInteraction = true + configuration.customTitle = title return controller(configuration: configuration, source: source) } From 5d7359ac72a763162ef9e4042f6cfaa9b37c6869 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 05:12:17 +0200 Subject: [PATCH 10/26] Update: change string key to use convention --- .../Coordinators/AllDomainsAddDomainCoordinator.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift b/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift index fa0dc227e34f..4d26c4244590 100644 --- a/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift +++ b/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift @@ -24,7 +24,8 @@ import Foundation extension AllDomainsAddDomainCoordinator { private enum Strings { - static let searchTitle = NSLocalizedString("Search for a domain", + static let searchTitle = NSLocalizedString("domain.management.addDomain.search.title", + value: "Search for a domain", comment: "Search domain - Title for the Suggested domains screen") } } From 6b63115fee383641b05bda2d6f9dcc3f128fe061 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 05:13:00 +0200 Subject: [PATCH 11/26] Add: helper func for starting checkout for no site domains --- ...isterDomainSuggestionsViewController.swift | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift index 47ae2c327500..5e69be5c3714 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift @@ -390,6 +390,47 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega self?.present(navController, animated: true) } } + + private func presentWebViewForNoSite(domainSuggestion: FullyQuotedDomainSuggestion) { + guard let url = URL(string: Constants.noSiteCheckoutWebAddress) else { + return + } + + let webViewController = WebViewControllerFactory.controllerWithDefaultAccountAndSecureInteraction(url: url, + source: "domains_register", // TODO: Update source + title: TextContent.checkoutTitle) + + // WORKAROUND: The reason why we have to use this mechanism to detect success and failure conditions + // for domain registration is because our checkout process (for some unknown reason) doesn't trigger + // call to WKWebViewDelegate methods. + // + // This was last checked by @diegoreymendez on 2021-09-22. + // + webViewURLChangeObservation = webViewController.webView.observe(\.url, options: .new) { [weak self] _, change in + guard let self = self, + let newURL = change.newValue as? URL else { + return + } + + self.handleWebViewURLChange(newURL, domain: domainSuggestion.domainName, onCancel: { + self.navigationController?.popViewController(animated: true) + }) { domain in + self.dismiss(animated: true, completion: { [weak self] in + guard let self = self else { + return + } + + self.domainPurchasedCallback?(self, domain) + }) + } + } + + // TODO: Track showing no site checkout + + webViewController.configureSandboxStore { [weak self] in + self?.navigationController?.pushViewController(webViewController, animated: true) + } + } } // MARK: - Constants @@ -409,6 +450,9 @@ extension RegisterDomainSuggestionsViewController { static let errorDismiss = NSLocalizedString("domains.failure.dismiss", value: "Dismiss", comment: "Action shown in a bottom notice to dismiss it.") + static let checkoutTitle = NSLocalizedString("domains.checkout.title", + value: "Checkout", + comment: "Title for the checkout screen.") } enum Constants { @@ -417,6 +461,7 @@ extension RegisterDomainSuggestionsViewController { static let viewControllerIdentifier = "RegisterDomainSuggestionsViewController" static let checkoutWebAddress = "https://wordpress.com/checkout/" + static let noSiteCheckoutWebAddress = "https://wordpress.com/checkout/no-site?isDomainOnly=1" // store sandbox cookie static let storeSandboxCookieName = "store_sandbox" static let storeSandboxCookieDomain = ".wordpress.com" From 5d17c8b74d3e030d592decf1d64f42c8c93916a5 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 07:41:33 +0200 Subject: [PATCH 12/26] Fix typo --- WordPress/Classes/Utility/WebKitViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Classes/Utility/WebKitViewController.swift b/WordPress/Classes/Utility/WebKitViewController.swift index d4ceea2cc77f..a14fd27a169b 100644 --- a/WordPress/Classes/Utility/WebKitViewController.swift +++ b/WordPress/Classes/Utility/WebKitViewController.swift @@ -514,7 +514,7 @@ class WebKitViewController: UIViewController, WebKitAuthenticatable { } if customTitle == nil { - // Set the title for the HUD which shows up on tap+hold w/ accessibile font sizes enabled + // Set the title for the HUD which shows up on tap+hold w/ accessible font sizes enabled navigationItem.title = "\(titleView.titleLabel.text ?? "")\n\n\(String(describing: titleView.subtitleLabel.text ?? ""))" } From 73095a426c38711b938996e352c8666377c2a6fc Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 07:47:27 +0200 Subject: [PATCH 13/26] Refactor: introduce coordinator logic into `RegisterDomainSuggestionsViewController` --- .../FreeToPaidPlansCoordinator.swift | 5 +- ...ogDetailsViewController+DomainCredit.swift | 5 +- ...isterDomainSuggestionsViewController.swift | 273 +++++++++++------- .../Views/DomainsDashboardFactory.swift | 3 +- .../AllDomainsAddDomainCoordinator.swift | 9 +- .../ViewRelated/Plugins/PluginViewModel.swift | 4 +- 6 files changed, 189 insertions(+), 110 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Free to Paid Plans/FreeToPaidPlansCoordinator.swift b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Free to Paid Plans/FreeToPaidPlansCoordinator.swift index d7662557ea9c..9c08976dad34 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Free to Paid Plans/FreeToPaidPlansCoordinator.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Free to Paid Plans/FreeToPaidPlansCoordinator.swift @@ -7,8 +7,9 @@ import SwiftUI source: String, blog: Blog ) { + let coordinator = RegisterDomainCoordinator(site: blog) let domainSuggestionsViewController = RegisterDomainSuggestionsViewController.instance( - site: blog, + coordinator: coordinator, domainSelectionType: .purchaseWithPaidPlan, includeSupportButton: false ) @@ -39,7 +40,7 @@ import SwiftUI } } - let domainAddedToCart = { (domainViewController: RegisterDomainSuggestionsViewController, domainName: String) in + let domainAddedToCart = { (domainViewController: UIViewController, domainName: String) in guard let viewModel = PlanSelectionViewModel(blog: blog) else { return } let planSelectionViewController = PlanSelectionViewController(viewModel: viewModel) planSelectionViewController.planSelectedCallback = { planSelectionViewController, checkoutURL in diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController+DomainCredit.swift b/WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController+DomainCredit.swift index 023947bda2c6..4285fd8443ca 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController+DomainCredit.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController+DomainCredit.swift @@ -21,8 +21,11 @@ extension BlogDetailsViewController { } @objc func showDomainCreditRedemption() { + let coordinator = RegisterDomainCoordinator(site: blog) let controller = RegisterDomainSuggestionsViewController - .instance(site: blog, domainSelectionType: .registerWithPaidPlan, domainPurchasedCallback: { [weak self] _, domain in + .instance(coordinator: coordinator, + domainSelectionType: .registerWithPaidPlan, + domainPurchasedCallback: { [weak self] _, domain in WPAnalytics.track(.domainCreditRedemptionSuccess) self?.presentDomainCreditRedemptionSuccess(domain: domain) }) diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift index 5e69be5c3714..d611f8052b6a 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift @@ -12,27 +12,30 @@ enum DomainSelectionType { } class RegisterDomainSuggestionsViewController: UIViewController { - typealias DomainPurchasedCallback = ((RegisterDomainSuggestionsViewController, String) -> Void) - typealias DomainAddedToCartCallback = ((RegisterDomainSuggestionsViewController, String) -> Void) @IBOutlet weak var buttonContainerBottomConstraint: NSLayoutConstraint! @IBOutlet weak var buttonContainerViewHeightConstraint: NSLayoutConstraint! private var constraintsInitialized = false - private var site: Blog? - var domainPurchasedCallback: DomainPurchasedCallback? - var domainAddedToCartCallback: DomainAddedToCartCallback? + var domainPurchasedCallback: RegisterDomainCoordinator.DomainPurchasedCallback? { + didSet { + coordinator?.domainPurchasedCallback = domainPurchasedCallback + } + } + var domainAddedToCartCallback: RegisterDomainCoordinator.DomainAddedToCartCallback? { + didSet { + coordinator?.domainAddedToCartCallback = domainAddedToCartCallback + } + } - private var domain: FullyQuotedDomainSuggestion? + private var coordinator: RegisterDomainCoordinator? private var siteName: String? private var domainsTableViewController: DomainSuggestionsTableViewController? private var domainSelectionType: DomainSelectionType = .registerWithPaidPlan private var includeSupportButton: Bool = true private var navBarTitle: String = TextContent.title - private var webViewURLChangeObservation: NSKeyValueObservation? - override func viewDidLoad() { super.viewDidLoad() configure() @@ -55,18 +58,18 @@ class RegisterDomainSuggestionsViewController: UIViewController { return buttonViewController }() - static func instance(site: Blog?, + static func instance(coordinator: RegisterDomainCoordinator, domainSelectionType: DomainSelectionType = .registerWithPaidPlan, includeSupportButton: Bool = true, title: String = TextContent.title, - domainPurchasedCallback: DomainPurchasedCallback? = nil) -> RegisterDomainSuggestionsViewController { + domainPurchasedCallback: RegisterDomainCoordinator.DomainPurchasedCallback? = nil) -> RegisterDomainSuggestionsViewController { let storyboard = UIStoryboard(name: Constants.storyboardIdentifier, bundle: Bundle.main) let controller = storyboard.instantiateViewController(withIdentifier: Constants.viewControllerIdentifier) as! RegisterDomainSuggestionsViewController - controller.site = site + controller.coordinator = coordinator controller.domainSelectionType = domainSelectionType controller.domainPurchasedCallback = domainPurchasedCallback controller.includeSupportButton = includeSupportButton - controller.siteName = siteNameForSuggestions(for: site) + controller.siteName = siteNameForSuggestions(for: coordinator.site) controller.navBarTitle = title return controller @@ -181,11 +184,11 @@ class RegisterDomainSuggestionsViewController: UIViewController { if let vc = segue.destination as? DomainSuggestionsTableViewController { vc.delegate = self vc.siteName = siteName - vc.blog = site + vc.blog = coordinator?.site vc.domainSelectionType = domainSelectionType - vc.primaryDomainAddress = site?.primaryDomainAddress + vc.primaryDomainAddress = coordinator?.site?.primaryDomainAddress - if site?.hasBloggerPlan == true { + if coordinator?.site?.hasBloggerPlan == true { vc.domainSuggestionType = .allowlistedTopLevelDomains(["blog"]) } @@ -211,7 +214,7 @@ class RegisterDomainSuggestionsViewController: UIViewController { extension RegisterDomainSuggestionsViewController: DomainSuggestionsTableViewControllerDelegate { func domainSelected(_ domain: FullyQuotedDomainSuggestion) { WPAnalytics.track(.automatedTransferCustomDomainSuggestionSelected) - self.domain = domain + coordinator?.domain = domain showButton(animated: true) } @@ -225,10 +228,11 @@ extension RegisterDomainSuggestionsViewController: DomainSuggestionsTableViewCon extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelegate { func primaryButtonPressed() { - guard let domain = domain else { + guard let coordinator, + let domain = coordinator.domain else { return } - if let site { + if let site = coordinator.site { WPAnalytics.track(.domainsSearchSelectDomainTapped, properties: WPAnalytics.domainsProperties(for: site), blog: site) } else { WPAnalytics.track(.domainsSearchSelectDomainTapped) @@ -244,17 +248,18 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega pushRegisterDomainDetailsViewController(domain) case .purchaseSeparately: setPrimaryButtonLoading(true) - createCart( + coordinator.createCart( domain, onSuccess: { [weak self] in - self?.presentWebViewForCurrentSite(domainSuggestion: domain) - self?.setPrimaryButtonLoading(false, afterDelay: 0.25) + guard let self else { return } + self.coordinator?.presentWebViewForCurrentSite(on: self, domainSuggestion: domain) + self.setPrimaryButtonLoading(false, afterDelay: 0.25) }, onFailure: onFailure ) case .purchaseWithPaidPlan: setPrimaryButtonLoading(true) - createCart( + coordinator.createCart( domain, onSuccess: { [weak self] in guard let self = self else { @@ -267,7 +272,7 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega onFailure: onFailure ) case .purchaseFromDomainManagement: - print("Hello world") + pushPurchaseDomainChoiceScreen(domain: domain) } } @@ -281,7 +286,7 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega } private func pushRegisterDomainDetailsViewController(_ domain: FullyQuotedDomainSuggestion) { - guard let siteID = site?.dotComID?.intValue else { + guard let siteID = coordinator?.site?.dotComID?.intValue else { DDLogError("Cannot register domains for sites without a dotComID") return } @@ -297,10 +302,74 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega self.navigationController?.pushViewController(controller, animated: true) } - // TODO: Create a counterpart that handles no site - private func createCart(_ domain: FullyQuotedDomainSuggestion, - onSuccess: @escaping () -> (), - onFailure: @escaping () -> ()) { + private func pushPurchaseDomainChoiceScreen(domain: FullyQuotedDomainSuggestion) { + let view = DomainPurchaseChoicesView { [weak self] in + guard let self else { return } + self.coordinator?.handleNoSiteChoice(on: self, domain: domain) + } chooseSiteAction: { [weak self] in + guard let self else { return } + self.coordinator?.handleExistingSiteChoice(on: self, domain: domain) + } + let hostingController = UIHostingController(rootView: view) + hostingController.title = TextContent.domainChoiceTitle + self.navigationController?.pushViewController(hostingController, animated: true) + } +} + +// MARK: - Constants +extension RegisterDomainSuggestionsViewController { + + enum TextContent { + + static let title = NSLocalizedString("Search domains", + comment: "Search domain - Title for the Suggested domains screen") + static let primaryButtonTitle = NSLocalizedString("Select domain", + comment: "Register domain - Title for the Choose domain button of Suggested domains screen") + static let supportButtonTitle = NSLocalizedString("Help", comment: "Help button") + + static let errorTitle = NSLocalizedString("domains.failure.title", + value: "Sorry, the domain you are trying to add cannot be bought on the Jetpack app at this time.", + comment: "Content show when the domain selection action fails.") + static let errorDismiss = NSLocalizedString("domains.failure.dismiss", + value: "Dismiss", + comment: "Action shown in a bottom notice to dismiss it.") + static let domainChoiceTitle = NSLocalizedString("domains.purchase.choice.title", + value: "Purchase Domain", + comment: "Title for the screen where the user can choose how to use the domain they're end up purchasing.") + } + + enum Constants { + // storyboard identifiers + static let storyboardIdentifier = "RegisterDomain" + static let viewControllerIdentifier = "RegisterDomainSuggestionsViewController" + } +} + +class RegisterDomainCoordinator { + + // MARK: Type Aliases + + typealias DomainPurchasedCallback = ((UIViewController, String) -> Void) + typealias DomainAddedToCartCallback = ((UIViewController, String) -> Void) + + // MARK: Variables + + var site: Blog? + var domainPurchasedCallback: DomainPurchasedCallback? + var domainAddedToCartCallback: DomainAddedToCartCallback? + var domain: FullyQuotedDomainSuggestion? + + private var webViewURLChangeObservation: NSKeyValueObservation? + + init(site: Blog?) { + self.site = site + } + + // MARK: Public Functions + + func createCart(_ domain: FullyQuotedDomainSuggestion, + onSuccess: @escaping () -> (), + onFailure: @escaping () -> ()) { let siteID = site?.dotComID?.intValue let proxy = RegisterDomainDetailsServiceProxy() proxy.createPersistentDomainShoppingCart(siteID: siteID, @@ -314,50 +383,15 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega }) } - static private let checkoutURLPrefix = "https://wordpress.com/checkout" - static private let checkoutSuccessURLPrefix = "https://wordpress.com/checkout/thank-you/" - - /// Handles URL changes in the web view. We only allow the user to stay within certain URLs. Falling outside these URLs - /// results in the web view being dismissed. This method also handles the success condition for a successful domain registration - /// through said web view. - /// - /// - Parameters: - /// - newURL: the newly set URL for the web view. - /// - domain: the domain the user is purchasing. - /// - onCancel: the closure that will be executed if we detect the conditions for cancelling the registration were met. - /// - onSuccess: the closure that will be executed if we detect a successful domain registration. - /// - private func handleWebViewURLChange( - _ newURL: URL, - domain: String, - onCancel: () -> Void, - onSuccess: (String) -> Void) { - - let canOpenNewURL = newURL.absoluteString.starts(with: Self.checkoutURLPrefix) - - guard canOpenNewURL else { - onCancel() - return - } - - let domainRegistrationSucceeded = newURL.absoluteString.starts(with: Self.checkoutSuccessURLPrefix) - - if domainRegistrationSucceeded { - onSuccess(domain) - - } - } - - private func presentWebViewForCurrentSite(domainSuggestion: FullyQuotedDomainSuggestion) { - guard let site, - let homeURL = site.homeURL, - let siteUrl = URL(string: homeURL as String), let host = siteUrl.host, - let url = URL(string: Constants.checkoutWebAddress + host) else { + func presentWebViewForNoSite(on viewController: UIViewController, + domainSuggestion: FullyQuotedDomainSuggestion) { + guard let url = URL(string: Constants.noSiteCheckoutWebAddress) else { return } - let webViewController = WebViewControllerFactory.controllerWithDefaultAccountAndSecureInteraction(url: url, source: "domains_register") - let navController = LightNavigationController(rootViewController: webViewController) + let webViewController = WebViewControllerFactory.controllerWithDefaultAccountAndSecureInteraction(url: url, + source: "domains_register", // TODO: Update source + title: TextContent.checkoutTitle) // WORKAROUND: The reason why we have to use this mechanism to detect success and failure conditions // for domain registration is because our checkout process (for some unknown reason) doesn't trigger @@ -372,33 +406,36 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega } self.handleWebViewURLChange(newURL, domain: domainSuggestion.domainName, onCancel: { - navController.dismiss(animated: true) + viewController.navigationController?.popViewController(animated: true) }) { domain in - self.dismiss(animated: true, completion: { [weak self] in + viewController.dismiss(animated: true, completion: { [weak self] in guard let self = self else { return } - self.domainPurchasedCallback?(self, domain) + self.domainPurchasedCallback?(viewController, domain) }) } } - WPAnalytics.track(.domainsPurchaseWebviewViewed, properties: WPAnalytics.domainsProperties(for: site), blog: site) + // TODO: Track showing no site checkout - webViewController.configureSandboxStore { [weak self] in - self?.present(navController, animated: true) + webViewController.configureSandboxStore { + viewController.navigationController?.pushViewController(webViewController, animated: true) } } - private func presentWebViewForNoSite(domainSuggestion: FullyQuotedDomainSuggestion) { - guard let url = URL(string: Constants.noSiteCheckoutWebAddress) else { + func presentWebViewForCurrentSite(on viewController: UIViewController, + domainSuggestion: FullyQuotedDomainSuggestion) { + guard let site, + let homeURL = site.homeURL, + let siteUrl = URL(string: homeURL as String), let host = siteUrl.host, + let url = URL(string: Constants.checkoutWebAddress + host) else { return } - let webViewController = WebViewControllerFactory.controllerWithDefaultAccountAndSecureInteraction(url: url, - source: "domains_register", // TODO: Update source - title: TextContent.checkoutTitle) + let webViewController = WebViewControllerFactory.controllerWithDefaultAccountAndSecureInteraction(url: url, source: "domains_register") + let navController = LightNavigationController(rootViewController: webViewController) // WORKAROUND: The reason why we have to use this mechanism to detect success and failure conditions // for domain registration is because our checkout process (for some unknown reason) doesn't trigger @@ -413,37 +450,77 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega } self.handleWebViewURLChange(newURL, domain: domainSuggestion.domainName, onCancel: { - self.navigationController?.popViewController(animated: true) + navController.dismiss(animated: true) }) { domain in - self.dismiss(animated: true, completion: { [weak self] in + viewController.dismiss(animated: true, completion: { [weak self] in guard let self = self else { return } - self.domainPurchasedCallback?(self, domain) + self.domainPurchasedCallback?(viewController, domain) }) } } - // TODO: Track showing no site checkout + WPAnalytics.track(.domainsPurchaseWebviewViewed, properties: WPAnalytics.domainsProperties(for: site), blog: site) + + webViewController.configureSandboxStore { + viewController.present(navController, animated: true) + } + } + + func handleNoSiteChoice(on viewController: UIViewController, domain: FullyQuotedDomainSuggestion) { + createCart( + domain, + onSuccess: { [weak self] in + self?.presentWebViewForNoSite(on: viewController, domainSuggestion: domain) + }) { + viewController.displayActionableNotice(title: TextContent.errorTitle, actionTitle: TextContent.errorDismiss) + } + } + + func handleExistingSiteChoice(on viewController: UIViewController, domain: FullyQuotedDomainSuggestion) { + print("handleExistingSiteChoice") + } + + // MARK: Helpers + + /// Handles URL changes in the web view. We only allow the user to stay within certain URLs. Falling outside these URLs + /// results in the web view being dismissed. This method also handles the success condition for a successful domain registration + /// through said web view. + /// + /// - Parameters: + /// - newURL: the newly set URL for the web view. + /// - domain: the domain the user is purchasing. + /// - onCancel: the closure that will be executed if we detect the conditions for cancelling the registration were met. + /// - onSuccess: the closure that will be executed if we detect a successful domain registration. + /// + private func handleWebViewURLChange( + _ newURL: URL, + domain: String, + onCancel: () -> Void, + onSuccess: (String) -> Void) { + + let canOpenNewURL = newURL.absoluteString.starts(with: Constants.checkoutWebAddress) + + guard canOpenNewURL else { + onCancel() + return + } + + let domainRegistrationSucceeded = newURL.absoluteString.starts(with: Constants.checkoutSuccessURLPrefix) + + if domainRegistrationSucceeded { + onSuccess(domain) - webViewController.configureSandboxStore { [weak self] in - self?.navigationController?.pushViewController(webViewController, animated: true) } } } // MARK: - Constants -extension RegisterDomainSuggestionsViewController { +extension RegisterDomainCoordinator { enum TextContent { - - static let title = NSLocalizedString("Search domains", - comment: "Search domain - Title for the Suggested domains screen") - static let primaryButtonTitle = NSLocalizedString("Select domain", - comment: "Register domain - Title for the Choose domain button of Suggested domains screen") - static let supportButtonTitle = NSLocalizedString("Help", comment: "Help button") - static let errorTitle = NSLocalizedString("domains.failure.title", value: "Sorry, the domain you are trying to add cannot be bought on the Jetpack app at this time.", comment: "Content show when the domain selection action fails.") @@ -456,14 +533,8 @@ extension RegisterDomainSuggestionsViewController { } enum Constants { - // storyboard identifiers - static let storyboardIdentifier = "RegisterDomain" - static let viewControllerIdentifier = "RegisterDomainSuggestionsViewController" - static let checkoutWebAddress = "https://wordpress.com/checkout/" static let noSiteCheckoutWebAddress = "https://wordpress.com/checkout/no-site?isDomainOnly=1" - // store sandbox cookie - static let storeSandboxCookieName = "store_sandbox" - static let storeSandboxCookieDomain = ".wordpress.com" + static let checkoutSuccessURLPrefix = "https://wordpress.com/checkout/thank-you/" } } diff --git a/WordPress/Classes/ViewRelated/Domains/Views/DomainsDashboardFactory.swift b/WordPress/Classes/ViewRelated/Domains/Views/DomainsDashboardFactory.swift index b720d367e9c6..dbf1965268c9 100644 --- a/WordPress/Classes/ViewRelated/Domains/Views/DomainsDashboardFactory.swift +++ b/WordPress/Classes/ViewRelated/Domains/Views/DomainsDashboardFactory.swift @@ -9,8 +9,9 @@ struct DomainsDashboardFactory { } static func makeDomainsSuggestionViewController(blog: Blog, domainSelectionType: DomainSelectionType, onDismiss: @escaping () -> Void) -> RegisterDomainSuggestionsViewController { + let coordinator = RegisterDomainCoordinator(site: blog) let viewController = RegisterDomainSuggestionsViewController.instance( - site: blog, + coordinator: coordinator, domainSelectionType: domainSelectionType, includeSupportButton: false) diff --git a/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift b/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift index 4d26c4244590..8a8057d2f422 100644 --- a/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift +++ b/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift @@ -3,14 +3,15 @@ import Foundation @objc final class AllDomainsAddDomainCoordinator: NSObject { static func presentAddDomainFlow(in allDomainsViewController: AllDomainsListViewController, source: String) { + let coordinator = RegisterDomainCoordinator(site: nil) let domainSuggestionsViewController = RegisterDomainSuggestionsViewController.instance( - site: nil, + coordinator: coordinator, domainSelectionType: .purchaseFromDomainManagement, includeSupportButton: false, - title: Strings.searchTitle - ) + title: Strings.searchTitle) - let domainPurchasedCallback = { (domainViewController: RegisterDomainSuggestionsViewController, domainName: String) in + + let domainPurchasedCallback = { (domainViewController: UIViewController, domainName: String) in allDomainsViewController.reloadDomains() } diff --git a/WordPress/Classes/ViewRelated/Plugins/PluginViewModel.swift b/WordPress/Classes/ViewRelated/Plugins/PluginViewModel.swift index db15ba3332b9..373249013fee 100644 --- a/WordPress/Classes/ViewRelated/Plugins/PluginViewModel.swift +++ b/WordPress/Classes/ViewRelated/Plugins/PluginViewModel.swift @@ -540,7 +540,9 @@ class PluginViewModel: Observable { return } - let controller = RegisterDomainSuggestionsViewController.instance(site: blog, domainPurchasedCallback: { [weak self] _, domain in + let coordinator = RegisterDomainCoordinator(site: blog) + let controller = RegisterDomainSuggestionsViewController.instance(coordinator: coordinator, + domainPurchasedCallback: { [weak self] _, domain in guard let strongSelf = self, let atHelper = AutomatedTransferHelper(site: strongSelf.site, plugin: directoryEntry) else { From 085756fd0f927bafc08a3a5428097985d03ab079 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 07:51:00 +0200 Subject: [PATCH 14/26] Update: move `RegisterDomainCoordinator` to its own file --- .../RegisterDomainCoordinator.swift | 195 ++++++++++++++++++ ...isterDomainSuggestionsViewController.swift | 194 ----------------- WordPress/WordPress.xcodeproj/project.pbxproj | 9 +- 3 files changed, 203 insertions(+), 195 deletions(-) create mode 100644 WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift new file mode 100644 index 000000000000..98295987d08b --- /dev/null +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift @@ -0,0 +1,195 @@ +import Foundation + +class RegisterDomainCoordinator { + + // MARK: Type Aliases + + typealias DomainPurchasedCallback = ((UIViewController, String) -> Void) + typealias DomainAddedToCartCallback = ((UIViewController, String) -> Void) + + // MARK: Variables + + var site: Blog? + var domainPurchasedCallback: DomainPurchasedCallback? + var domainAddedToCartCallback: DomainAddedToCartCallback? + var domain: FullyQuotedDomainSuggestion? + + private var webViewURLChangeObservation: NSKeyValueObservation? + + init(site: Blog?) { + self.site = site + } + + // MARK: Public Functions + + func createCart(_ domain: FullyQuotedDomainSuggestion, + onSuccess: @escaping () -> (), + onFailure: @escaping () -> ()) { + let siteID = site?.dotComID?.intValue + let proxy = RegisterDomainDetailsServiceProxy() + proxy.createPersistentDomainShoppingCart(siteID: siteID, + domainSuggestion: domain.remoteSuggestion(), + privacyProtectionEnabled: domain.supportsPrivacy ?? false, + success: { _ in + onSuccess() + }, + failure: { _ in + onFailure() + }) + } + + func presentWebViewForNoSite(on viewController: UIViewController, + domainSuggestion: FullyQuotedDomainSuggestion) { + guard let url = URL(string: Constants.noSiteCheckoutWebAddress) else { + return + } + + let webViewController = WebViewControllerFactory.controllerWithDefaultAccountAndSecureInteraction(url: url, + source: "domains_register", // TODO: Update source + title: TextContent.checkoutTitle) + + // WORKAROUND: The reason why we have to use this mechanism to detect success and failure conditions + // for domain registration is because our checkout process (for some unknown reason) doesn't trigger + // call to WKWebViewDelegate methods. + // + // This was last checked by @diegoreymendez on 2021-09-22. + // + webViewURLChangeObservation = webViewController.webView.observe(\.url, options: .new) { [weak self] _, change in + guard let self = self, + let newURL = change.newValue as? URL else { + return + } + + self.handleWebViewURLChange(newURL, domain: domainSuggestion.domainName, onCancel: { + viewController.navigationController?.popViewController(animated: true) + }) { domain in + viewController.dismiss(animated: true, completion: { [weak self] in + guard let self = self else { + return + } + + self.domainPurchasedCallback?(viewController, domain) + }) + } + } + + // TODO: Track showing no site checkout + + webViewController.configureSandboxStore { + viewController.navigationController?.pushViewController(webViewController, animated: true) + } + } + + func presentWebViewForCurrentSite(on viewController: UIViewController, + domainSuggestion: FullyQuotedDomainSuggestion) { + guard let site, + let homeURL = site.homeURL, + let siteUrl = URL(string: homeURL as String), let host = siteUrl.host, + let url = URL(string: Constants.checkoutWebAddress + host) else { + return + } + + let webViewController = WebViewControllerFactory.controllerWithDefaultAccountAndSecureInteraction(url: url, source: "domains_register") + let navController = LightNavigationController(rootViewController: webViewController) + + // WORKAROUND: The reason why we have to use this mechanism to detect success and failure conditions + // for domain registration is because our checkout process (for some unknown reason) doesn't trigger + // call to WKWebViewDelegate methods. + // + // This was last checked by @diegoreymendez on 2021-09-22. + // + webViewURLChangeObservation = webViewController.webView.observe(\.url, options: .new) { [weak self] _, change in + guard let self = self, + let newURL = change.newValue as? URL else { + return + } + + self.handleWebViewURLChange(newURL, domain: domainSuggestion.domainName, onCancel: { + navController.dismiss(animated: true) + }) { domain in + viewController.dismiss(animated: true, completion: { [weak self] in + guard let self = self else { + return + } + + self.domainPurchasedCallback?(viewController, domain) + }) + } + } + + WPAnalytics.track(.domainsPurchaseWebviewViewed, properties: WPAnalytics.domainsProperties(for: site), blog: site) + + webViewController.configureSandboxStore { + viewController.present(navController, animated: true) + } + } + + func handleNoSiteChoice(on viewController: UIViewController, domain: FullyQuotedDomainSuggestion) { + createCart( + domain, + onSuccess: { [weak self] in + self?.presentWebViewForNoSite(on: viewController, domainSuggestion: domain) + }) { + viewController.displayActionableNotice(title: TextContent.errorTitle, actionTitle: TextContent.errorDismiss) + } + } + + func handleExistingSiteChoice(on viewController: UIViewController, domain: FullyQuotedDomainSuggestion) { + print("handleExistingSiteChoice") + } + + // MARK: Helpers + + /// Handles URL changes in the web view. We only allow the user to stay within certain URLs. Falling outside these URLs + /// results in the web view being dismissed. This method also handles the success condition for a successful domain registration + /// through said web view. + /// + /// - Parameters: + /// - newURL: the newly set URL for the web view. + /// - domain: the domain the user is purchasing. + /// - onCancel: the closure that will be executed if we detect the conditions for cancelling the registration were met. + /// - onSuccess: the closure that will be executed if we detect a successful domain registration. + /// + private func handleWebViewURLChange( + _ newURL: URL, + domain: String, + onCancel: () -> Void, + onSuccess: (String) -> Void) { + + let canOpenNewURL = newURL.absoluteString.starts(with: Constants.checkoutWebAddress) + + guard canOpenNewURL else { + onCancel() + return + } + + let domainRegistrationSucceeded = newURL.absoluteString.starts(with: Constants.checkoutSuccessURLPrefix) + + if domainRegistrationSucceeded { + onSuccess(domain) + + } + } +} + +// MARK: - Constants +extension RegisterDomainCoordinator { + + enum TextContent { + static let errorTitle = NSLocalizedString("domains.failure.title", + value: "Sorry, the domain you are trying to add cannot be bought on the Jetpack app at this time.", + comment: "Content show when the domain selection action fails.") + static let errorDismiss = NSLocalizedString("domains.failure.dismiss", + value: "Dismiss", + comment: "Action shown in a bottom notice to dismiss it.") + static let checkoutTitle = NSLocalizedString("domains.checkout.title", + value: "Checkout", + comment: "Title for the checkout screen.") + } + + enum Constants { + static let checkoutWebAddress = "https://wordpress.com/checkout/" + static let noSiteCheckoutWebAddress = "https://wordpress.com/checkout/no-site?isDomainOnly=1" + static let checkoutSuccessURLPrefix = "https://wordpress.com/checkout/thank-you/" + } +} diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift index d611f8052b6a..e460075abe31 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift @@ -344,197 +344,3 @@ extension RegisterDomainSuggestionsViewController { static let viewControllerIdentifier = "RegisterDomainSuggestionsViewController" } } - -class RegisterDomainCoordinator { - - // MARK: Type Aliases - - typealias DomainPurchasedCallback = ((UIViewController, String) -> Void) - typealias DomainAddedToCartCallback = ((UIViewController, String) -> Void) - - // MARK: Variables - - var site: Blog? - var domainPurchasedCallback: DomainPurchasedCallback? - var domainAddedToCartCallback: DomainAddedToCartCallback? - var domain: FullyQuotedDomainSuggestion? - - private var webViewURLChangeObservation: NSKeyValueObservation? - - init(site: Blog?) { - self.site = site - } - - // MARK: Public Functions - - func createCart(_ domain: FullyQuotedDomainSuggestion, - onSuccess: @escaping () -> (), - onFailure: @escaping () -> ()) { - let siteID = site?.dotComID?.intValue - let proxy = RegisterDomainDetailsServiceProxy() - proxy.createPersistentDomainShoppingCart(siteID: siteID, - domainSuggestion: domain.remoteSuggestion(), - privacyProtectionEnabled: domain.supportsPrivacy ?? false, - success: { _ in - onSuccess() - }, - failure: { _ in - onFailure() - }) - } - - func presentWebViewForNoSite(on viewController: UIViewController, - domainSuggestion: FullyQuotedDomainSuggestion) { - guard let url = URL(string: Constants.noSiteCheckoutWebAddress) else { - return - } - - let webViewController = WebViewControllerFactory.controllerWithDefaultAccountAndSecureInteraction(url: url, - source: "domains_register", // TODO: Update source - title: TextContent.checkoutTitle) - - // WORKAROUND: The reason why we have to use this mechanism to detect success and failure conditions - // for domain registration is because our checkout process (for some unknown reason) doesn't trigger - // call to WKWebViewDelegate methods. - // - // This was last checked by @diegoreymendez on 2021-09-22. - // - webViewURLChangeObservation = webViewController.webView.observe(\.url, options: .new) { [weak self] _, change in - guard let self = self, - let newURL = change.newValue as? URL else { - return - } - - self.handleWebViewURLChange(newURL, domain: domainSuggestion.domainName, onCancel: { - viewController.navigationController?.popViewController(animated: true) - }) { domain in - viewController.dismiss(animated: true, completion: { [weak self] in - guard let self = self else { - return - } - - self.domainPurchasedCallback?(viewController, domain) - }) - } - } - - // TODO: Track showing no site checkout - - webViewController.configureSandboxStore { - viewController.navigationController?.pushViewController(webViewController, animated: true) - } - } - - func presentWebViewForCurrentSite(on viewController: UIViewController, - domainSuggestion: FullyQuotedDomainSuggestion) { - guard let site, - let homeURL = site.homeURL, - let siteUrl = URL(string: homeURL as String), let host = siteUrl.host, - let url = URL(string: Constants.checkoutWebAddress + host) else { - return - } - - let webViewController = WebViewControllerFactory.controllerWithDefaultAccountAndSecureInteraction(url: url, source: "domains_register") - let navController = LightNavigationController(rootViewController: webViewController) - - // WORKAROUND: The reason why we have to use this mechanism to detect success and failure conditions - // for domain registration is because our checkout process (for some unknown reason) doesn't trigger - // call to WKWebViewDelegate methods. - // - // This was last checked by @diegoreymendez on 2021-09-22. - // - webViewURLChangeObservation = webViewController.webView.observe(\.url, options: .new) { [weak self] _, change in - guard let self = self, - let newURL = change.newValue as? URL else { - return - } - - self.handleWebViewURLChange(newURL, domain: domainSuggestion.domainName, onCancel: { - navController.dismiss(animated: true) - }) { domain in - viewController.dismiss(animated: true, completion: { [weak self] in - guard let self = self else { - return - } - - self.domainPurchasedCallback?(viewController, domain) - }) - } - } - - WPAnalytics.track(.domainsPurchaseWebviewViewed, properties: WPAnalytics.domainsProperties(for: site), blog: site) - - webViewController.configureSandboxStore { - viewController.present(navController, animated: true) - } - } - - func handleNoSiteChoice(on viewController: UIViewController, domain: FullyQuotedDomainSuggestion) { - createCart( - domain, - onSuccess: { [weak self] in - self?.presentWebViewForNoSite(on: viewController, domainSuggestion: domain) - }) { - viewController.displayActionableNotice(title: TextContent.errorTitle, actionTitle: TextContent.errorDismiss) - } - } - - func handleExistingSiteChoice(on viewController: UIViewController, domain: FullyQuotedDomainSuggestion) { - print("handleExistingSiteChoice") - } - - // MARK: Helpers - - /// Handles URL changes in the web view. We only allow the user to stay within certain URLs. Falling outside these URLs - /// results in the web view being dismissed. This method also handles the success condition for a successful domain registration - /// through said web view. - /// - /// - Parameters: - /// - newURL: the newly set URL for the web view. - /// - domain: the domain the user is purchasing. - /// - onCancel: the closure that will be executed if we detect the conditions for cancelling the registration were met. - /// - onSuccess: the closure that will be executed if we detect a successful domain registration. - /// - private func handleWebViewURLChange( - _ newURL: URL, - domain: String, - onCancel: () -> Void, - onSuccess: (String) -> Void) { - - let canOpenNewURL = newURL.absoluteString.starts(with: Constants.checkoutWebAddress) - - guard canOpenNewURL else { - onCancel() - return - } - - let domainRegistrationSucceeded = newURL.absoluteString.starts(with: Constants.checkoutSuccessURLPrefix) - - if domainRegistrationSucceeded { - onSuccess(domain) - - } - } -} - -// MARK: - Constants -extension RegisterDomainCoordinator { - - enum TextContent { - static let errorTitle = NSLocalizedString("domains.failure.title", - value: "Sorry, the domain you are trying to add cannot be bought on the Jetpack app at this time.", - comment: "Content show when the domain selection action fails.") - static let errorDismiss = NSLocalizedString("domains.failure.dismiss", - value: "Dismiss", - comment: "Action shown in a bottom notice to dismiss it.") - static let checkoutTitle = NSLocalizedString("domains.checkout.title", - value: "Checkout", - comment: "Title for the checkout screen.") - } - - enum Constants { - static let checkoutWebAddress = "https://wordpress.com/checkout/" - static let noSiteCheckoutWebAddress = "https://wordpress.com/checkout/no-site?isDomainOnly=1" - static let checkoutSuccessURLPrefix = "https://wordpress.com/checkout/thank-you/" - } -} diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index 24309ae718e0..dab14538e303 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -1729,6 +1729,7 @@ 80348F2E2AF870A70045CCD3 /* AllDomainsAddDomainCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80348F2D2AF870A70045CCD3 /* AllDomainsAddDomainCoordinator.swift */; }; 80348F312AF87FEA0045CCD3 /* AllDomainsListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80348F302AF87FEA0045CCD3 /* AllDomainsListViewController.swift */; }; 80348F332AF880820045CCD3 /* DomainPurchaseChoicesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80348F322AF880820045CCD3 /* DomainPurchaseChoicesView.swift */; }; + 80348F342AF89BD00045CCD3 /* AllDomainsAddDomainCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80348F2D2AF870A70045CCD3 /* AllDomainsAddDomainCoordinator.swift */; }; 80379C6E2A5C0D8F00D924AC /* PostTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80379C6D2A5C0D8F00D924AC /* PostTests.swift */; }; 80379C6F2A5C0D8F00D924AC /* PostTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80379C6D2A5C0D8F00D924AC /* PostTests.swift */; }; 803BB9792959543D00B3F6D6 /* RootViewCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 803BB9782959543D00B3F6D6 /* RootViewCoordinator.swift */; }; @@ -1981,6 +1982,8 @@ 80D9D04729F765C900FE3400 /* FailableDecodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80D9D04529F760C400FE3400 /* FailableDecodable.swift */; }; 80D9D04A29FC0D9000FE3400 /* NSMutableArray+NullableObjects.m in Sources */ = {isa = PBXBuildFile; fileRef = 80D9D04929FC0D9000FE3400 /* NSMutableArray+NullableObjects.m */; }; 80D9D04B29FC118900FE3400 /* NSMutableArray+NullableObjects.m in Sources */ = {isa = PBXBuildFile; fileRef = 80D9D04929FC0D9000FE3400 /* NSMutableArray+NullableObjects.m */; }; + 80DB57922AF8B59B00C728FF /* RegisterDomainCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80DB57912AF8B59B00C728FF /* RegisterDomainCoordinator.swift */; }; + 80DB57932AF8B59B00C728FF /* RegisterDomainCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80DB57912AF8B59B00C728FF /* RegisterDomainCoordinator.swift */; }; 80EF671F27F135EB0063B138 /* WhatIsNewViewAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80EF671E27F135EB0063B138 /* WhatIsNewViewAppearance.swift */; }; 80EF672027F135EB0063B138 /* WhatIsNewViewAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80EF671E27F135EB0063B138 /* WhatIsNewViewAppearance.swift */; }; 80EF672227F160720063B138 /* DashboardCustomAnnouncementCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80EF672127F160720063B138 /* DashboardCustomAnnouncementCell.swift */; }; @@ -7399,6 +7402,7 @@ 80D9D04529F760C400FE3400 /* FailableDecodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FailableDecodable.swift; sourceTree = ""; }; 80D9D04829FC0D9000FE3400 /* NSMutableArray+NullableObjects.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSMutableArray+NullableObjects.h"; sourceTree = ""; }; 80D9D04929FC0D9000FE3400 /* NSMutableArray+NullableObjects.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSMutableArray+NullableObjects.m"; sourceTree = ""; }; + 80DB57912AF8B59B00C728FF /* RegisterDomainCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterDomainCoordinator.swift; sourceTree = ""; }; 80EF671E27F135EB0063B138 /* WhatIsNewViewAppearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WhatIsNewViewAppearance.swift; sourceTree = ""; }; 80EF672127F160720063B138 /* DashboardCustomAnnouncementCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardCustomAnnouncementCell.swift; sourceTree = ""; }; 80EF672427F3D63B0063B138 /* DashboardStatsStackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardStatsStackView.swift; sourceTree = ""; }; @@ -12047,6 +12051,7 @@ 3FAF9CC426D03C7400268EA2 /* DomainSuggestionViewControllerWrapper.swift */, 171096CA270F01EA001BCDD6 /* DomainSuggestionsTableViewController.swift */, 436D560C2117312600CEAA33 /* RegisterDomainSuggestionsViewController.swift */, + 80DB57912AF8B59B00C728FF /* RegisterDomainCoordinator.swift */, ); path = RegisterDomainSuggestions; sourceTree = ""; @@ -22329,6 +22334,7 @@ E61084C11B9B47BA008050C5 /* ReaderSiteTopic.swift in Sources */, 0878580328B4CF950069F96C /* UserPersistentRepositoryUtility.swift in Sources */, FE18495827F5ACBA00D26879 /* DashboardPromptsCardCell.swift in Sources */, + 80DB57922AF8B59B00C728FF /* RegisterDomainCoordinator.swift in Sources */, FAB8004925AEDC2300D5D54A /* JetpackBackupCompleteViewController.swift in Sources */, 9A8ECE0C2254A3260043C8DA /* JetpackLoginViewController.swift in Sources */, 46F583A92624CE790010A723 /* BlockEditorSettings+CoreDataClass.swift in Sources */, @@ -24911,9 +24917,9 @@ FABB23DF2602FC2C00C8785C /* BlogSelectorViewController.m in Sources */, FABB23E02602FC2C00C8785C /* HomepageSettingsViewController.swift in Sources */, 93E6336D272AF504009DACF8 /* LoginEpilogueDividerView.swift in Sources */, - 80348F2F2AF870A70045CCD3 /* AllDomainsAddDomainCoordinator.swift in Sources */, FABB23E12602FC2C00C8785C /* TenorMediaGroup.swift in Sources */, FABB23E22602FC2C00C8785C /* SiteSuggestionService.swift in Sources */, + 80348F342AF89BD00045CCD3 /* AllDomainsAddDomainCoordinator.swift in Sources */, FABB23E32602FC2C00C8785C /* NotificationsViewController+PushPrimer.swift in Sources */, FABB23E42602FC2C00C8785C /* ReaderPostService.m in Sources */, FABB23E52602FC2C00C8785C /* EditorMediaUtility.swift in Sources */, @@ -25558,6 +25564,7 @@ FABB25AB2602FC2C00C8785C /* FancyAlertViewController+NotificationPrimer.swift in Sources */, FABB25AC2602FC2C00C8785C /* Charts+Support.swift in Sources */, FABB25AD2602FC2C00C8785C /* SharingAuthorizationWebViewController.swift in Sources */, + 80DB57932AF8B59B00C728FF /* RegisterDomainCoordinator.swift in Sources */, 3FB1929326C6C57A000F5AA3 /* TimeSelectionView.swift in Sources */, FABB25AE2602FC2C00C8785C /* SearchWrapperView.swift in Sources */, 98830A932747043B0061A87C /* BorderedButtonTableViewCell.swift in Sources */, From 25341705ef850f6c2a1b688d00e9885392feee15 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 08:04:30 +0200 Subject: [PATCH 15/26] Update: Move callbacks to coordinator --- .../FreeToPaidPlansCoordinator.swift | 2 +- ...ogDetailsViewController+DomainCredit.swift | 13 +++++++------ .../RegisterDomainCoordinator.swift | 3 ++- ...isterDomainSuggestionsViewController.swift | 19 +++---------------- .../Views/DomainsDashboardFactory.swift | 2 +- .../AllDomainsAddDomainCoordinator.swift | 2 +- .../ViewRelated/Plugins/PluginViewModel.swift | 5 ++--- 7 files changed, 17 insertions(+), 29 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Free to Paid Plans/FreeToPaidPlansCoordinator.swift b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Free to Paid Plans/FreeToPaidPlansCoordinator.swift index 9c08976dad34..5b970a5599b3 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Free to Paid Plans/FreeToPaidPlansCoordinator.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Free to Paid Plans/FreeToPaidPlansCoordinator.swift @@ -48,7 +48,7 @@ import SwiftUI } domainViewController.navigationController?.pushViewController(planSelectionViewController, animated: true) } - domainSuggestionsViewController.domainAddedToCartCallback = domainAddedToCart + coordinator.domainAddedToCartCallback = domainAddedToCart let navigationController = UINavigationController(rootViewController: domainSuggestionsViewController) dashboardViewController.present(navigationController, animated: true) diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController+DomainCredit.swift b/WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController+DomainCredit.swift index 4285fd8443ca..98cdd53988eb 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController+DomainCredit.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController+DomainCredit.swift @@ -21,14 +21,15 @@ extension BlogDetailsViewController { } @objc func showDomainCreditRedemption() { - let coordinator = RegisterDomainCoordinator(site: blog) + let coordinator = RegisterDomainCoordinator(site: blog, + domainPurchasedCallback: { [weak self] _, domain in + WPAnalytics.track(.domainCreditRedemptionSuccess) + self?.presentDomainCreditRedemptionSuccess(domain: domain) + }) let controller = RegisterDomainSuggestionsViewController .instance(coordinator: coordinator, - domainSelectionType: .registerWithPaidPlan, - domainPurchasedCallback: { [weak self] _, domain in - WPAnalytics.track(.domainCreditRedemptionSuccess) - self?.presentDomainCreditRedemptionSuccess(domain: domain) - }) + domainSelectionType: .registerWithPaidPlan) + let navigationController = UINavigationController(rootViewController: controller) present(navigationController, animated: true) } diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift index 98295987d08b..c206dd9a52b2 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift @@ -16,8 +16,9 @@ class RegisterDomainCoordinator { private var webViewURLChangeObservation: NSKeyValueObservation? - init(site: Blog?) { + init(site: Blog?, domainPurchasedCallback: RegisterDomainCoordinator.DomainPurchasedCallback? = nil) { self.site = site + self.domainPurchasedCallback = domainPurchasedCallback } // MARK: Public Functions diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift index e460075abe31..528dd3077f90 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift @@ -18,17 +18,6 @@ class RegisterDomainSuggestionsViewController: UIViewController { private var constraintsInitialized = false - var domainPurchasedCallback: RegisterDomainCoordinator.DomainPurchasedCallback? { - didSet { - coordinator?.domainPurchasedCallback = domainPurchasedCallback - } - } - var domainAddedToCartCallback: RegisterDomainCoordinator.DomainAddedToCartCallback? { - didSet { - coordinator?.domainAddedToCartCallback = domainAddedToCartCallback - } - } - private var coordinator: RegisterDomainCoordinator? private var siteName: String? private var domainsTableViewController: DomainSuggestionsTableViewController? @@ -61,13 +50,11 @@ class RegisterDomainSuggestionsViewController: UIViewController { static func instance(coordinator: RegisterDomainCoordinator, domainSelectionType: DomainSelectionType = .registerWithPaidPlan, includeSupportButton: Bool = true, - title: String = TextContent.title, - domainPurchasedCallback: RegisterDomainCoordinator.DomainPurchasedCallback? = nil) -> RegisterDomainSuggestionsViewController { + title: String = TextContent.title) -> RegisterDomainSuggestionsViewController { let storyboard = UIStoryboard(name: Constants.storyboardIdentifier, bundle: Bundle.main) let controller = storyboard.instantiateViewController(withIdentifier: Constants.viewControllerIdentifier) as! RegisterDomainSuggestionsViewController controller.coordinator = coordinator controller.domainSelectionType = domainSelectionType - controller.domainPurchasedCallback = domainPurchasedCallback controller.includeSupportButton = includeSupportButton controller.siteName = siteNameForSuggestions(for: coordinator.site) controller.navBarTitle = title @@ -266,7 +253,7 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega return } - self.domainAddedToCartCallback?(self, domain.domainName) + self.coordinator?.domainAddedToCartCallback?(self, domain.domainName) self.setPrimaryButtonLoading(false, afterDelay: 0.25) }, onFailure: onFailure @@ -297,7 +284,7 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega return } - self.domainPurchasedCallback?(self, name) + self.coordinator?.domainPurchasedCallback?(self, name) } self.navigationController?.pushViewController(controller, animated: true) } diff --git a/WordPress/Classes/ViewRelated/Domains/Views/DomainsDashboardFactory.swift b/WordPress/Classes/ViewRelated/Domains/Views/DomainsDashboardFactory.swift index dbf1965268c9..8c5cb24d8441 100644 --- a/WordPress/Classes/ViewRelated/Domains/Views/DomainsDashboardFactory.swift +++ b/WordPress/Classes/ViewRelated/Domains/Views/DomainsDashboardFactory.swift @@ -15,7 +15,7 @@ struct DomainsDashboardFactory { domainSelectionType: domainSelectionType, includeSupportButton: false) - viewController.domainPurchasedCallback = { viewController, domain in + coordinator.domainPurchasedCallback = { viewController, domain in let blogService = BlogService(coreDataStack: ContextManager.shared) blogService.syncBlogAndAllMetadata(blog) { } WPAnalytics.track(.domainCreditRedemptionSuccess) diff --git a/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift b/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift index 8a8057d2f422..e903c0bda639 100644 --- a/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift +++ b/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift @@ -15,7 +15,7 @@ import Foundation allDomainsViewController.reloadDomains() } - domainSuggestionsViewController.domainPurchasedCallback = domainPurchasedCallback + coordinator.domainPurchasedCallback = domainPurchasedCallback let navigationController = UINavigationController(rootViewController: domainSuggestionsViewController) navigationController.isModalInPresentation = true diff --git a/WordPress/Classes/ViewRelated/Plugins/PluginViewModel.swift b/WordPress/Classes/ViewRelated/Plugins/PluginViewModel.swift index 373249013fee..c5fcf1fb00b9 100644 --- a/WordPress/Classes/ViewRelated/Plugins/PluginViewModel.swift +++ b/WordPress/Classes/ViewRelated/Plugins/PluginViewModel.swift @@ -540,9 +540,7 @@ class PluginViewModel: Observable { return } - let coordinator = RegisterDomainCoordinator(site: blog) - let controller = RegisterDomainSuggestionsViewController.instance(coordinator: coordinator, - domainPurchasedCallback: { [weak self] _, domain in + let coordinator = RegisterDomainCoordinator(site: blog, domainPurchasedCallback: { [weak self] _, domain in guard let strongSelf = self, let atHelper = AutomatedTransferHelper(site: strongSelf.site, plugin: directoryEntry) else { @@ -553,6 +551,7 @@ class PluginViewModel: Observable { atHelper.startAutomatedTransferProcess(retryingAfterFailure: true) }) + let controller = RegisterDomainSuggestionsViewController.instance(coordinator: coordinator) let navigationController = UINavigationController(rootViewController: controller) self.present?(navigationController) } From 5d81e1f5e80d369216e0155dcf2d988ef2283c0b Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 08:16:41 +0200 Subject: [PATCH 16/26] Update: hookup new flow to all domains screen --- .../Coordinators/AllDomainsAddDomainCoordinator.swift | 3 +-- .../Me/All Domains/Views/AllDomainsListViewController.swift | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift b/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift index e903c0bda639..347d07b89f56 100644 --- a/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift +++ b/WordPress/Classes/ViewRelated/Me/All Domains/Coordinators/AllDomainsAddDomainCoordinator.swift @@ -1,8 +1,7 @@ import Foundation @objc final class AllDomainsAddDomainCoordinator: NSObject { - static func presentAddDomainFlow(in allDomainsViewController: AllDomainsListViewController, - source: String) { + static func presentAddDomainFlow(in allDomainsViewController: AllDomainsListViewController) { let coordinator = RegisterDomainCoordinator(site: nil) let domainSuggestionsViewController = RegisterDomainSuggestionsViewController.instance( coordinator: coordinator, diff --git a/WordPress/Classes/ViewRelated/Me/All Domains/Views/AllDomainsListViewController.swift b/WordPress/Classes/ViewRelated/Me/All Domains/Views/AllDomainsListViewController.swift index 2c953f32211d..a6e130ac2c81 100644 --- a/WordPress/Classes/ViewRelated/Me/All Domains/Views/AllDomainsListViewController.swift +++ b/WordPress/Classes/ViewRelated/Me/All Domains/Views/AllDomainsListViewController.swift @@ -144,7 +144,7 @@ final class AllDomainsListViewController: UIViewController { // MARK: - Navigation private func navigateToAddDomain() { - + AllDomainsAddDomainCoordinator.presentAddDomainFlow(in: self) } } From 61ae067d62f62af1500aeeaf18d3edc26eca115b Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 08:41:00 +0200 Subject: [PATCH 17/26] Update: integrate right version of WPKit --- Podfile | 4 ++-- Podfile.lock | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Podfile b/Podfile index 2ea87c2ab9d4..1f51684c1c7f 100644 --- a/Podfile +++ b/Podfile @@ -51,9 +51,9 @@ end def wordpress_kit # Anything compatible with 8.9, starting from 8.9.1 which has a breaking change fix - pod 'WordPressKit', '~> 8.10' + # pod 'WordPressKit', '~> 8.10' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', tag: '' - # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: '' + pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: 'task/21780-no-site-cart' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '' # pod 'WordPressKit', path: '../WordPressKit-iOS' end diff --git a/Podfile.lock b/Podfile.lock index 0a4ded667a18..0f579b458aa9 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -126,7 +126,7 @@ DEPENDENCIES: - SwiftLint (~> 0.50) - WordPress-Editor-iOS (~> 1.19.9) - WordPressAuthenticator (>= 7.2.1, ~> 7.2) - - WordPressKit (~> 8.10) + - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, branch `task/21780-no-site-cart`) - WordPressShared (~> 2.2) - WordPressUI (~> 1.15) - WPMediaPicker (>= 1.8.10, ~> 1.8) @@ -134,8 +134,6 @@ DEPENDENCIES: - ZIPFoundation (~> 0.9.8) SPEC REPOS: - https://github.com/wordpress-mobile/cocoapods-specs.git: - - WordPressKit trunk: - Alamofire - AlamofireImage @@ -185,11 +183,17 @@ EXTERNAL SOURCES: :tag: 0.2.0 Gutenberg: :podspec: https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-v1.107.0.podspec + WordPressKit: + :branch: task/21780-no-site-cart + :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git CHECKOUT OPTIONS: FSInteractiveMap: :git: https://github.com/wordpress-mobile/FSInteractiveMap.git :tag: 0.2.0 + WordPressKit: + :commit: 70bb55e4b1e5eb9e38cdc3c1e013128b96ed83b9 + :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git SPEC CHECKSUMS: Alamofire: 3ec537f71edc9804815215393ae2b1a8ea33a844 @@ -223,7 +227,7 @@ SPEC CHECKSUMS: WordPress-Aztec-iOS: fbebd569c61baa252b3f5058c0a2a9a6ada686bb WordPress-Editor-iOS: bda9f7f942212589b890329a0cb22547311749ef WordPressAuthenticator: eb60491871a2b8819017deed2970b054d2678547 - WordPressKit: 30510174ad90a997acef42a5880bdda45c5c66e9 + WordPressKit: ef52a8d69434c0b81799999e8b19e68dc6a377b2 WordPressShared: 87f3ee89b0a3e83106106f13a8b71605fb8eb6d2 WordPressUI: a491454affda3b0fb812812e637dc5e8f8f6bd06 WPMediaPicker: 332812329cbdc672cdb385b8ac3a389f668d3012 @@ -237,6 +241,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: d170fa8e270b2a32bef9dcdcabff5b8f1a5deced -PODFILE CHECKSUM: 87283d92c99164bd6b27423cd2474decb698219e +PODFILE CHECKSUM: 6340036cfd212cbdbb1c467360c75afadd0c5b80 COCOAPODS: 1.14.2 From d5ba65760683a15966cd9097313b292f04d3d01d Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 09:07:25 +0200 Subject: [PATCH 18/26] Refactor: remove duplicate code --- .../RegisterDomainCoordinator.swift | 113 +++++++++--------- 1 file changed, 56 insertions(+), 57 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift index c206dd9a52b2..2ea8f75e30b5 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift @@ -44,43 +44,14 @@ class RegisterDomainCoordinator { guard let url = URL(string: Constants.noSiteCheckoutWebAddress) else { return } - - let webViewController = WebViewControllerFactory.controllerWithDefaultAccountAndSecureInteraction(url: url, - source: "domains_register", // TODO: Update source - title: TextContent.checkoutTitle) - - // WORKAROUND: The reason why we have to use this mechanism to detect success and failure conditions - // for domain registration is because our checkout process (for some unknown reason) doesn't trigger - // call to WKWebViewDelegate methods. - // - // This was last checked by @diegoreymendez on 2021-09-22. - // - webViewURLChangeObservation = webViewController.webView.observe(\.url, options: .new) { [weak self] _, change in - guard let self = self, - let newURL = change.newValue as? URL else { - return - } - - self.handleWebViewURLChange(newURL, domain: domainSuggestion.domainName, onCancel: { - viewController.navigationController?.popViewController(animated: true) - }) { domain in - viewController.dismiss(animated: true, completion: { [weak self] in - guard let self = self else { - return - } - - self.domainPurchasedCallback?(viewController, domain) - }) - } - } - - // TODO: Track showing no site checkout - - webViewController.configureSandboxStore { - viewController.navigationController?.pushViewController(webViewController, animated: true) - } + + presentCheckoutWebview(on: viewController, + domainSuggestion: domainSuggestion, + url: url, + title: TextContent.checkoutTitle, + shouldPush: true) } - + func presentWebViewForCurrentSite(on viewController: UIViewController, domainSuggestion: FullyQuotedDomainSuggestion) { guard let site, @@ -89,8 +60,40 @@ class RegisterDomainCoordinator { let url = URL(string: Constants.checkoutWebAddress + host) else { return } + + presentCheckoutWebview(on: viewController, + domainSuggestion: domainSuggestion, + url: url, + title: nil, + shouldPush: false) + } - let webViewController = WebViewControllerFactory.controllerWithDefaultAccountAndSecureInteraction(url: url, source: "domains_register") + func handleNoSiteChoice(on viewController: UIViewController, domain: FullyQuotedDomainSuggestion) { + createCart( + domain, + onSuccess: { [weak self] in + self?.presentWebViewForNoSite(on: viewController, domainSuggestion: domain) + }) { + viewController.displayActionableNotice(title: TextContent.errorTitle, actionTitle: TextContent.errorDismiss) + } + } + + func handleExistingSiteChoice(on viewController: UIViewController, domain: FullyQuotedDomainSuggestion) { + print("handleExistingSiteChoice") + } + + // MARK: Helpers + + private func presentCheckoutWebview(on viewController: UIViewController, + domainSuggestion: FullyQuotedDomainSuggestion, + url: URL, + title: String?, + shouldPush: Bool) { + + let webViewController = WebViewControllerFactory.controllerWithDefaultAccountAndSecureInteraction( + url: url, + source: "domains_register", // TODO: Update source + title: title) let navController = LightNavigationController(rootViewController: webViewController) // WORKAROUND: The reason why we have to use this mechanism to detect success and failure conditions @@ -106,7 +109,11 @@ class RegisterDomainCoordinator { } self.handleWebViewURLChange(newURL, domain: domainSuggestion.domainName, onCancel: { - navController.dismiss(animated: true) + if shouldPush { + viewController.navigationController?.popViewController(animated: true) + } else { + navController.dismiss(animated: true) + } }) { domain in viewController.dismiss(animated: true, completion: { [weak self] in guard let self = self else { @@ -118,29 +125,21 @@ class RegisterDomainCoordinator { } } - WPAnalytics.track(.domainsPurchaseWebviewViewed, properties: WPAnalytics.domainsProperties(for: site), blog: site) - - webViewController.configureSandboxStore { - viewController.present(navController, animated: true) + if let site { + WPAnalytics.track(.domainsPurchaseWebviewViewed, properties: WPAnalytics.domainsProperties(for: site), blog: site) + } else { + // TODO: Track showing no site checkout } - } - - func handleNoSiteChoice(on viewController: UIViewController, domain: FullyQuotedDomainSuggestion) { - createCart( - domain, - onSuccess: { [weak self] in - self?.presentWebViewForNoSite(on: viewController, domainSuggestion: domain) - }) { - viewController.displayActionableNotice(title: TextContent.errorTitle, actionTitle: TextContent.errorDismiss) + + webViewController.configureSandboxStore { + if shouldPush { + viewController.navigationController?.pushViewController(webViewController, animated: true) + } else { + viewController.present(navController, animated: true) } + } } - func handleExistingSiteChoice(on viewController: UIViewController, domain: FullyQuotedDomainSuggestion) { - print("handleExistingSiteChoice") - } - - // MARK: Helpers - /// Handles URL changes in the web view. We only allow the user to stay within certain URLs. Falling outside these URLs /// results in the web view being dismissed. This method also handles the success condition for a successful domain registration /// through said web view. From 8d61f2cad8e8d13c62e8dedfc8a4ee632ee7ea2f Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 09:10:31 +0200 Subject: [PATCH 19/26] Fix: lint errors --- .../RegisterDomainCoordinator.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift index 2ea8f75e30b5..77e59fdd802b 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift @@ -44,14 +44,14 @@ class RegisterDomainCoordinator { guard let url = URL(string: Constants.noSiteCheckoutWebAddress) else { return } - + presentCheckoutWebview(on: viewController, domainSuggestion: domainSuggestion, url: url, title: TextContent.checkoutTitle, shouldPush: true) } - + func presentWebViewForCurrentSite(on viewController: UIViewController, domainSuggestion: FullyQuotedDomainSuggestion) { guard let site, @@ -60,7 +60,7 @@ class RegisterDomainCoordinator { let url = URL(string: Constants.checkoutWebAddress + host) else { return } - + presentCheckoutWebview(on: viewController, domainSuggestion: domainSuggestion, url: url, @@ -83,13 +83,13 @@ class RegisterDomainCoordinator { } // MARK: Helpers - + private func presentCheckoutWebview(on viewController: UIViewController, domainSuggestion: FullyQuotedDomainSuggestion, url: URL, title: String?, shouldPush: Bool) { - + let webViewController = WebViewControllerFactory.controllerWithDefaultAccountAndSecureInteraction( url: url, source: "domains_register", // TODO: Update source @@ -130,7 +130,7 @@ class RegisterDomainCoordinator { } else { // TODO: Track showing no site checkout } - + webViewController.configureSandboxStore { if shouldPush { viewController.navigationController?.pushViewController(webViewController, animated: true) From 422c787d75f6c0394fc86e27078da40d8389b5c4 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 09:44:57 +0200 Subject: [PATCH 20/26] Update: fix build error --- WordPress/WordPress.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index dab14538e303..74f95f768008 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -1726,7 +1726,6 @@ 8031F34A292FF46B00E8F95E /* ExtensionConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800035C0292307E8007D2D26 /* ExtensionConfiguration.swift */; }; 8031F34B292FF46E00E8F95E /* ExtensionConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800035C0292307E8007D2D26 /* ExtensionConfiguration.swift */; }; 8031F34C29302A2500E8F95E /* ExtensionConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 800035C229230A0B007D2D26 /* ExtensionConfiguration.swift */; }; - 80348F2E2AF870A70045CCD3 /* AllDomainsAddDomainCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80348F2D2AF870A70045CCD3 /* AllDomainsAddDomainCoordinator.swift */; }; 80348F312AF87FEA0045CCD3 /* AllDomainsListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80348F302AF87FEA0045CCD3 /* AllDomainsListViewController.swift */; }; 80348F332AF880820045CCD3 /* DomainPurchaseChoicesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80348F322AF880820045CCD3 /* DomainPurchaseChoicesView.swift */; }; 80348F342AF89BD00045CCD3 /* AllDomainsAddDomainCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80348F2D2AF870A70045CCD3 /* AllDomainsAddDomainCoordinator.swift */; }; @@ -1984,6 +1983,7 @@ 80D9D04B29FC118900FE3400 /* NSMutableArray+NullableObjects.m in Sources */ = {isa = PBXBuildFile; fileRef = 80D9D04929FC0D9000FE3400 /* NSMutableArray+NullableObjects.m */; }; 80DB57922AF8B59B00C728FF /* RegisterDomainCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80DB57912AF8B59B00C728FF /* RegisterDomainCoordinator.swift */; }; 80DB57932AF8B59B00C728FF /* RegisterDomainCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80DB57912AF8B59B00C728FF /* RegisterDomainCoordinator.swift */; }; + 80DB57942AF8D04600C728FF /* DomainPurchaseChoicesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80348F322AF880820045CCD3 /* DomainPurchaseChoicesView.swift */; }; 80EF671F27F135EB0063B138 /* WhatIsNewViewAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80EF671E27F135EB0063B138 /* WhatIsNewViewAppearance.swift */; }; 80EF672027F135EB0063B138 /* WhatIsNewViewAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80EF671E27F135EB0063B138 /* WhatIsNewViewAppearance.swift */; }; 80EF672227F160720063B138 /* DashboardCustomAnnouncementCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80EF672127F160720063B138 /* DashboardCustomAnnouncementCell.swift */; }; @@ -22383,7 +22383,6 @@ 8261B4CC1EA8E13700668298 /* SVProgressHUD+Dismiss.m in Sources */, 329F8E5624DDAC61002A5311 /* DynamicHeightCollectionView.swift in Sources */, FECA442F28350B7800D01F15 /* PromptRemindersScheduler.swift in Sources */, - 80348F2E2AF870A70045CCD3 /* AllDomainsAddDomainCoordinator.swift in Sources */, 0CB424EE2ADEE3CD0080B807 /* PostSearchTokenTableCell.swift in Sources */, 436D56242117312700CEAA33 /* RegisterDomainDetailsViewModel+RowList.swift in Sources */, C81CCD65243AECA200A83E27 /* TenorGIF.swift in Sources */, @@ -22663,6 +22662,7 @@ FAC086D725EDFB1E00B94F2A /* ReaderRelatedPostsCell.swift in Sources */, 324780E1247F2E2A00987525 /* NoResultsViewController+FollowedSites.swift in Sources */, E100C6BB1741473000AE48D8 /* WordPress-11-12.xcmappingmodel in Sources */, + 80DB57942AF8D04600C728FF /* DomainPurchaseChoicesView.swift in Sources */, B07F133E2A16C69800AF7FCF /* PlanSelectionViewController.swift in Sources */, 837A53D72AD8C3A400B941A2 /* ReaderFollowButton.swift in Sources */, 9822A8412624CFB900FD8A03 /* UserProfileSiteCell.swift in Sources */, From 012caac305e4ae7c83df027ec570fb25859e644e Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Mon, 6 Nov 2023 14:55:56 +0200 Subject: [PATCH 21/26] Tests: fix build error --- .../WordPressTest/RegisterDomainDetailsServiceProxyMock.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/WordPressTest/RegisterDomainDetailsServiceProxyMock.swift b/WordPress/WordPressTest/RegisterDomainDetailsServiceProxyMock.swift index e49ded8c740b..4d9760c2f783 100644 --- a/WordPress/WordPressTest/RegisterDomainDetailsServiceProxyMock.swift +++ b/WordPress/WordPressTest/RegisterDomainDetailsServiceProxyMock.swift @@ -130,7 +130,7 @@ class RegisterDomainDetailsServiceProxyMock: RegisterDomainDetailsServiceProxyPr }, failure: failure) } - func createTemporaryDomainShoppingCart(siteID: Int, + func createTemporaryDomainShoppingCart(siteID: Int?, domainSuggestion: DomainSuggestion, privacyProtectionEnabled: Bool, success: @escaping (CartResponseProtocol) -> Void, @@ -143,7 +143,7 @@ class RegisterDomainDetailsServiceProxyMock: RegisterDomainDetailsServiceProxyPr success(response) } - func createPersistentDomainShoppingCart(siteID: Int, + func createPersistentDomainShoppingCart(siteID: Int?, domainSuggestion: DomainSuggestion, privacyProtectionEnabled: Bool, success: @escaping (CartResponseProtocol) -> Void, From 42c5b70c80566e5f8c972b1580c63f0a3c89fd48 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Tue, 7 Nov 2023 01:32:49 +0200 Subject: [PATCH 22/26] Update: remove redundant domain params inside coordinator --- .../RegisterDomainCoordinator.swift | 27 +++++++++---------- ...isterDomainSuggestionsViewController.swift | 26 +++++++++--------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift index 77e59fdd802b..c6c2a9a323e4 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift @@ -23,9 +23,9 @@ class RegisterDomainCoordinator { // MARK: Public Functions - func createCart(_ domain: FullyQuotedDomainSuggestion, - onSuccess: @escaping () -> (), + func createCart(onSuccess: @escaping () -> (), onFailure: @escaping () -> ()) { + guard let domain else { return } let siteID = site?.dotComID?.intValue let proxy = RegisterDomainDetailsServiceProxy() proxy.createPersistentDomainShoppingCart(siteID: siteID, @@ -39,22 +39,22 @@ class RegisterDomainCoordinator { }) } - func presentWebViewForNoSite(on viewController: UIViewController, - domainSuggestion: FullyQuotedDomainSuggestion) { - guard let url = URL(string: Constants.noSiteCheckoutWebAddress) else { + func presentWebViewForNoSite(on viewController: UIViewController) { + guard let domain, + let url = URL(string: Constants.noSiteCheckoutWebAddress) else { return } presentCheckoutWebview(on: viewController, - domainSuggestion: domainSuggestion, + domainSuggestion: domain, url: url, title: TextContent.checkoutTitle, shouldPush: true) } - func presentWebViewForCurrentSite(on viewController: UIViewController, - domainSuggestion: FullyQuotedDomainSuggestion) { - guard let site, + func presentWebViewForCurrentSite(on viewController: UIViewController) { + guard let domain, + let site, let homeURL = site.homeURL, let siteUrl = URL(string: homeURL as String), let host = siteUrl.host, let url = URL(string: Constants.checkoutWebAddress + host) else { @@ -62,23 +62,22 @@ class RegisterDomainCoordinator { } presentCheckoutWebview(on: viewController, - domainSuggestion: domainSuggestion, + domainSuggestion: domain, url: url, title: nil, shouldPush: false) } - func handleNoSiteChoice(on viewController: UIViewController, domain: FullyQuotedDomainSuggestion) { + func handleNoSiteChoice(on viewController: UIViewController) { createCart( - domain, onSuccess: { [weak self] in - self?.presentWebViewForNoSite(on: viewController, domainSuggestion: domain) + self?.presentWebViewForNoSite(on: viewController) }) { viewController.displayActionableNotice(title: TextContent.errorTitle, actionTitle: TextContent.errorDismiss) } } - func handleExistingSiteChoice(on viewController: UIViewController, domain: FullyQuotedDomainSuggestion) { + func handleExistingSiteChoice(on viewController: UIViewController) { print("handleExistingSiteChoice") } diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift index 528dd3077f90..502b74545692 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainSuggestionsViewController.swift @@ -215,8 +215,7 @@ extension RegisterDomainSuggestionsViewController: DomainSuggestionsTableViewCon extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelegate { func primaryButtonPressed() { - guard let coordinator, - let domain = coordinator.domain else { + guard let coordinator else { return } if let site = coordinator.site { @@ -232,14 +231,13 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega switch domainSelectionType { case .registerWithPaidPlan: - pushRegisterDomainDetailsViewController(domain) + pushRegisterDomainDetailsViewController() case .purchaseSeparately: setPrimaryButtonLoading(true) coordinator.createCart( - domain, onSuccess: { [weak self] in guard let self else { return } - self.coordinator?.presentWebViewForCurrentSite(on: self, domainSuggestion: domain) + self.coordinator?.presentWebViewForCurrentSite(on: self) self.setPrimaryButtonLoading(false, afterDelay: 0.25) }, onFailure: onFailure @@ -247,9 +245,9 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega case .purchaseWithPaidPlan: setPrimaryButtonLoading(true) coordinator.createCart( - domain, onSuccess: { [weak self] in - guard let self = self else { + guard let self = self, + let domain = self.coordinator?.domain else { return } @@ -259,7 +257,7 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega onFailure: onFailure ) case .purchaseFromDomainManagement: - pushPurchaseDomainChoiceScreen(domain: domain) + pushPurchaseDomainChoiceScreen() } } @@ -272,12 +270,16 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega } } - private func pushRegisterDomainDetailsViewController(_ domain: FullyQuotedDomainSuggestion) { + private func pushRegisterDomainDetailsViewController() { guard let siteID = coordinator?.site?.dotComID?.intValue else { DDLogError("Cannot register domains for sites without a dotComID") return } + guard let domain = coordinator?.domain else { + return + } + let controller = RegisterDomainDetailsViewController() controller.viewModel = RegisterDomainDetailsViewModel(siteID: siteID, domain: domain) { [weak self] name in guard let self = self else { @@ -289,13 +291,13 @@ extension RegisterDomainSuggestionsViewController: NUXButtonViewControllerDelega self.navigationController?.pushViewController(controller, animated: true) } - private func pushPurchaseDomainChoiceScreen(domain: FullyQuotedDomainSuggestion) { + private func pushPurchaseDomainChoiceScreen() { let view = DomainPurchaseChoicesView { [weak self] in guard let self else { return } - self.coordinator?.handleNoSiteChoice(on: self, domain: domain) + self.coordinator?.handleNoSiteChoice(on: self) } chooseSiteAction: { [weak self] in guard let self else { return } - self.coordinator?.handleExistingSiteChoice(on: self, domain: domain) + self.coordinator?.handleExistingSiteChoice(on: self) } let hostingController = UIHostingController(rootView: view) hostingController.title = TextContent.domainChoiceTitle From 243562a5ea5da815dd5354a4fd0ad3dd5804fd02 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Tue, 7 Nov 2023 01:38:32 +0200 Subject: [PATCH 23/26] Update: track error messages --- .../RegisterDomainCoordinator.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift index c6c2a9a323e4..c0740757b927 100644 --- a/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift +++ b/WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainSuggestions/RegisterDomainCoordinator.swift @@ -1,4 +1,5 @@ import Foundation +import AutomatticTracks class RegisterDomainCoordinator { @@ -9,6 +10,8 @@ class RegisterDomainCoordinator { // MARK: Variables + private let crashLogger: CrashLogging + var site: Blog? var domainPurchasedCallback: DomainPurchasedCallback? var domainAddedToCartCallback: DomainAddedToCartCallback? @@ -16,9 +19,12 @@ class RegisterDomainCoordinator { private var webViewURLChangeObservation: NSKeyValueObservation? - init(site: Blog?, domainPurchasedCallback: RegisterDomainCoordinator.DomainPurchasedCallback? = nil) { + init(site: Blog?, + domainPurchasedCallback: RegisterDomainCoordinator.DomainPurchasedCallback? = nil, + crashLogger: CrashLogging = .main) { self.site = site self.domainPurchasedCallback = domainPurchasedCallback + self.crashLogger = crashLogger } // MARK: Public Functions @@ -42,6 +48,8 @@ class RegisterDomainCoordinator { func presentWebViewForNoSite(on viewController: UIViewController) { guard let domain, let url = URL(string: Constants.noSiteCheckoutWebAddress) else { + crashLogger.logMessage("Failed to present domain checkout webview for no-site.", + level: .error) return } @@ -58,6 +66,8 @@ class RegisterDomainCoordinator { let homeURL = site.homeURL, let siteUrl = URL(string: homeURL as String), let host = siteUrl.host, let url = URL(string: Constants.checkoutWebAddress + host) else { + crashLogger.logMessage("Failed to present domain checkout webview for current site.", + level: .error) return } From 0dc2c8a1e922c88c4b61ea242123dc9594211373 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Tue, 7 Nov 2023 02:31:29 +0200 Subject: [PATCH 24/26] Update: point to latest WPKit commit --- Podfile | 4 ++-- Podfile.lock | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Podfile b/Podfile index 1f51684c1c7f..169eb8856652 100644 --- a/Podfile +++ b/Podfile @@ -53,8 +53,8 @@ def wordpress_kit # Anything compatible with 8.9, starting from 8.9.1 which has a breaking change fix # pod 'WordPressKit', '~> 8.10' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', tag: '' - pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: 'task/21780-no-site-cart' - # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '' + # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: '' + pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '1ed1cddc0d17d79be190a201ae645c525b874eb4' # pod 'WordPressKit', path: '../WordPressKit-iOS' end diff --git a/Podfile.lock b/Podfile.lock index 0f579b458aa9..fcd451eb223f 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -126,7 +126,7 @@ DEPENDENCIES: - SwiftLint (~> 0.50) - WordPress-Editor-iOS (~> 1.19.9) - WordPressAuthenticator (>= 7.2.1, ~> 7.2) - - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, branch `task/21780-no-site-cart`) + - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, commit `1ed1cddc0d17d79be190a201ae645c525b874eb4`) - WordPressShared (~> 2.2) - WordPressUI (~> 1.15) - WPMediaPicker (>= 1.8.10, ~> 1.8) @@ -184,7 +184,7 @@ EXTERNAL SOURCES: Gutenberg: :podspec: https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-v1.107.0.podspec WordPressKit: - :branch: task/21780-no-site-cart + :commit: 1ed1cddc0d17d79be190a201ae645c525b874eb4 :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git CHECKOUT OPTIONS: @@ -192,7 +192,7 @@ CHECKOUT OPTIONS: :git: https://github.com/wordpress-mobile/FSInteractiveMap.git :tag: 0.2.0 WordPressKit: - :commit: 70bb55e4b1e5eb9e38cdc3c1e013128b96ed83b9 + :commit: 1ed1cddc0d17d79be190a201ae645c525b874eb4 :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git SPEC CHECKSUMS: @@ -241,6 +241,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: d170fa8e270b2a32bef9dcdcabff5b8f1a5deced -PODFILE CHECKSUM: 6340036cfd212cbdbb1c467360c75afadd0c5b80 +PODFILE CHECKSUM: dcdd7629c48cbef17842719c35e37536bcf51e5b COCOAPODS: 1.14.2 From a5803513159d7e56dd37b7179003d42fa8befaa4 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Tue, 7 Nov 2023 09:49:15 +0200 Subject: [PATCH 25/26] Update: point WPKit to trunk --- Podfile | 4 ++-- Podfile.lock | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Podfile b/Podfile index 169eb8856652..27947c831dc8 100644 --- a/Podfile +++ b/Podfile @@ -53,8 +53,8 @@ def wordpress_kit # Anything compatible with 8.9, starting from 8.9.1 which has a breaking change fix # pod 'WordPressKit', '~> 8.10' # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', tag: '' - # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: '' - pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '1ed1cddc0d17d79be190a201ae645c525b874eb4' + pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', branch: 'trunk' + # pod 'WordPressKit', git: 'https://github.com/wordpress-mobile/WordPressKit-iOS.git', commit: '' # pod 'WordPressKit', path: '../WordPressKit-iOS' end diff --git a/Podfile.lock b/Podfile.lock index fcd451eb223f..221694e27d20 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -126,7 +126,7 @@ DEPENDENCIES: - SwiftLint (~> 0.50) - WordPress-Editor-iOS (~> 1.19.9) - WordPressAuthenticator (>= 7.2.1, ~> 7.2) - - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, commit `1ed1cddc0d17d79be190a201ae645c525b874eb4`) + - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, branch `trunk`) - WordPressShared (~> 2.2) - WordPressUI (~> 1.15) - WPMediaPicker (>= 1.8.10, ~> 1.8) @@ -184,7 +184,7 @@ EXTERNAL SOURCES: Gutenberg: :podspec: https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-v1.107.0.podspec WordPressKit: - :commit: 1ed1cddc0d17d79be190a201ae645c525b874eb4 + :branch: trunk :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git CHECKOUT OPTIONS: @@ -241,6 +241,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: d170fa8e270b2a32bef9dcdcabff5b8f1a5deced -PODFILE CHECKSUM: dcdd7629c48cbef17842719c35e37536bcf51e5b +PODFILE CHECKSUM: 32668955e63d88fa5e19b00553baefae59c2a879 COCOAPODS: 1.14.2 From ac5cbecc2fe10642907c86138663a735b4926cd8 Mon Sep 17 00:00:00 2001 From: Hassaan El-Garem Date: Wed, 8 Nov 2023 14:10:22 +0200 Subject: [PATCH 26/26] Update Podfile.lock --- Podfile.lock | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 13ce1be48111..9d8e6552bac5 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -126,7 +126,7 @@ DEPENDENCIES: - SwiftLint (~> 0.50) - WordPress-Editor-iOS (~> 1.19.9) - WordPressAuthenticator (>= 7.2.1, ~> 7.2) - - WordPressKit (~> 8.10) + - WordPressKit (from `https://github.com/wordpress-mobile/WordPressKit-iOS.git`, branch `trunk`) - WordPressShared (~> 2.2) - WordPressUI (~> 1.15) - WPMediaPicker (>= 1.8.10, ~> 1.8) @@ -134,8 +134,6 @@ DEPENDENCIES: - ZIPFoundation (~> 0.9.8) SPEC REPOS: - https://github.com/wordpress-mobile/cocoapods-specs.git: - - WordPressKit trunk: - Alamofire - AlamofireImage @@ -185,11 +183,17 @@ EXTERNAL SOURCES: :tag: 0.2.0 Gutenberg: :podspec: https://cdn.a8c-ci.services/gutenberg-mobile/Gutenberg-v1.107.0.podspec + WordPressKit: + :branch: trunk + :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git CHECKOUT OPTIONS: FSInteractiveMap: :git: https://github.com/wordpress-mobile/FSInteractiveMap.git :tag: 0.2.0 + WordPressKit: + :commit: 1ed1cddc0d17d79be190a201ae645c525b874eb4 + :git: https://github.com/wordpress-mobile/WordPressKit-iOS.git SPEC CHECKSUMS: Alamofire: 3ec537f71edc9804815215393ae2b1a8ea33a844 @@ -223,7 +227,7 @@ SPEC CHECKSUMS: WordPress-Aztec-iOS: fbebd569c61baa252b3f5058c0a2a9a6ada686bb WordPress-Editor-iOS: bda9f7f942212589b890329a0cb22547311749ef WordPressAuthenticator: eb60491871a2b8819017deed2970b054d2678547 - WordPressKit: 30510174ad90a997acef42a5880bdda45c5c66e9 + WordPressKit: ef52a8d69434c0b81799999e8b19e68dc6a377b2 WordPressShared: 87f3ee89b0a3e83106106f13a8b71605fb8eb6d2 WordPressUI: a491454affda3b0fb812812e637dc5e8f8f6bd06 WPMediaPicker: 332812329cbdc672cdb385b8ac3a389f668d3012 @@ -237,6 +241,6 @@ SPEC CHECKSUMS: ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba ZIPFoundation: d170fa8e270b2a32bef9dcdcabff5b8f1a5deced -PODFILE CHECKSUM: 5a6208e4373a98b208f7e59607508adb19f4eb5f +PODFILE CHECKSUM: 946b818d64b969f6bab98fbac41a475970efa079 COCOAPODS: 1.14.2