Skip to content

Commit dc9cf5c

Browse files
authored
Jetpack Setup: Update connection step to use APIs where possible (#15983)
2 parents 79dead8 + 29929d7 commit dc9cf5c

File tree

9 files changed

+537
-161
lines changed

9 files changed

+537
-161
lines changed

Modules/Sources/Networking/Mapper/JetpackConnectionProvisionMapper.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,11 @@ public struct JetpackConnectionProvisionResponse: Decodable {
1818
public let userId: Int64
1919
public let scope: String
2020
public let secret: String
21+
22+
/// periphery: ignore - used in test module
23+
public init(userId: Int64, scope: String, secret: String) {
24+
self.userId = userId
25+
self.scope = scope
26+
self.secret = secret
27+
}
2128
}

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
23.1
55
-----
6+
- [*] Jetpack setup: Native experience for the connection step [https://github.com/woocommerce/woocommerce-ios/pull/15983]
67
- [*] Payments: Updated the In-Person Payments `Learn More` redirection to display the correct page based on the selected payment provider [https://github.com/woocommerce/woocommerce-ios/pull/15998]
78

89
23.0

WooCommerce/Classes/Authentication/Jetpack Setup/LoginJetpackSetupCoordinator.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ final class LoginJetpackSetupCoordinator: Coordinator {
4444
//
4545
private extension LoginJetpackSetupCoordinator {
4646
func showSetupSteps() {
47-
let setupUI = JetpackSetupHostingController(siteURL: siteURL, connectionOnly: connectionOnly, onStoreNavigation: { [weak self] connectedEmail in
47+
let setupUI = JetpackSetupHostingController(
48+
siteURL: siteURL,
49+
connectionOnly: connectionOnly,
50+
wpcomCredentials: stores.sessionManager.defaultCredentials,
51+
onStoreNavigation: { [weak self] connectedEmail in
4852
guard let self, let email = connectedEmail else { return }
4953
if email != self.stores.sessionManager.defaultAccount?.email {
5054
// if the user authorized Jetpack with a different account, support them to log in with that account.

WooCommerce/Classes/Authentication/Jetpack Setup/Native Jetpack Setup/JetpackSetupView.swift

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,23 @@ import protocol WooFoundation.Analytics
77
final class JetpackSetupHostingController: UIHostingController<JetpackSetupView> {
88
private let viewModel: JetpackSetupViewModel
99
private let authentication: Authentication
10-
private let connectionWebViewCredentials: Credentials?
10+
private let wpcomCredentials: Credentials?
1111

1212
init(siteURL: String,
1313
connectionOnly: Bool,
14-
connectionWebViewCredentials: Credentials? = nil,
14+
wpcomCredentials: Credentials?,
1515
stores: StoresManager = ServiceLocator.stores,
1616
authentication: Authentication = ServiceLocator.authenticationManager,
1717
analytics: Analytics = ServiceLocator.analytics,
1818
onStoreNavigation: @escaping (String?) -> Void) {
1919
self.viewModel = JetpackSetupViewModel(siteURL: siteURL,
2020
connectionOnly: connectionOnly,
21+
wpcomCredentials: wpcomCredentials,
2122
stores: stores,
2223
analytics: analytics,
2324
onStoreNavigation: onStoreNavigation)
2425
self.authentication = authentication
25-
self.connectionWebViewCredentials = connectionWebViewCredentials
26+
self.wpcomCredentials = wpcomCredentials
2627
super.init(rootView: JetpackSetupView(viewModel: viewModel))
2728

2829
rootView.webViewPresentationHandler = { [weak self] in
@@ -92,7 +93,7 @@ final class JetpackSetupHostingController: UIHostingController<JetpackSetupView>
9293
guard let self else { return }
9394
self.viewModel.jetpackConnectionInterrupted = true
9495
})
95-
let webView = AuthenticatedWebViewController(viewModel: webViewModel, extraCredentials: connectionWebViewCredentials)
96+
let webView = AuthenticatedWebViewController(viewModel: webViewModel, extraCredentials: wpcomCredentials)
9697
webView.navigationItem.leftBarButtonItem = UIBarButtonItem(title: Localization.cancel,
9798
style: .plain,
9899
target: self,
@@ -327,10 +328,3 @@ private extension JetpackSetupView {
327328
static let interruptedConnectionActionHandlerDelayTime: Double = 0.3
328329
}
329330
}
330-
331-
struct JetpackSetupView_Previews: PreviewProvider {
332-
static var previews: some View {
333-
JetpackSetupView(viewModel: JetpackSetupViewModel(siteURL: "https://test.com", connectionOnly: true))
334-
JetpackSetupView(viewModel: JetpackSetupViewModel(siteURL: "https://test.com", connectionOnly: false))
335-
}
336-
}

0 commit comments

Comments
 (0)