Skip to content

Commit 3ce9638

Browse files
committed
Merge branch 'trunk' into issue/7745-remove-jetpackconnectionerrorviewmodel
2 parents af7b3c9 + c703aed commit 3ce9638

20 files changed

+401
-79
lines changed

Fakes/Fakes/Networking.generated.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,19 @@ extension DotcomError {
188188
.empty
189189
}
190190
}
191+
extension DotcomUser {
192+
/// Returns a "ready to use" type filled with fake values.
193+
///
194+
public static func fake() -> DotcomUser {
195+
.init(
196+
id: .fake(),
197+
username: .fake(),
198+
email: .fake(),
199+
displayName: .fake(),
200+
avatar: .fake()
201+
)
202+
}
203+
}
191204
extension InboxAction {
192205
/// Returns a "ready to use" type filled with fake values.
193206
///
@@ -220,6 +233,19 @@ extension InboxNote {
220233
)
221234
}
222235
}
236+
extension JetpackUser {
237+
/// Returns a "ready to use" type filled with fake values.
238+
///
239+
public static func fake() -> JetpackUser {
240+
.init(
241+
isConnected: .fake(),
242+
isPrimary: .fake(),
243+
username: .fake(),
244+
wpcomUser: .fake(),
245+
gravatar: .fake()
246+
)
247+
}
248+
}
223249
extension Leaderboard {
224250
/// Returns a "ready to use" type filled with fake values.
225251
///

Podfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ target 'WooCommerce' do
5252
pod 'Gridicons', '~> 1.2.0'
5353

5454
# To allow pod to pick up beta versions use -beta. E.g., 1.1.7-beta.1
55-
# pod 'WordPressAuthenticator', '~> 3.1.0'
56-
pod 'WordPressAuthenticator', :git => 'https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git', :commit => '6ddbf0aa1a2df30d1411bfe481a1119b79ea0bb5'
55+
pod 'WordPressAuthenticator', '~> 3.2.0-beta.1'
56+
# pod 'WordPressAuthenticator', :git => 'https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git', :commit => ''
5757
# pod 'WordPressAuthenticator', :git => 'https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git', :branch => ''
5858
# pod 'WordPressAuthenticator', :path => '../WordPressAuthenticator-iOS'
5959

Podfile.lock

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ PODS:
4242
- WordPress-Aztec-iOS (1.11.0)
4343
- WordPress-Editor-iOS (1.11.0):
4444
- WordPress-Aztec-iOS (= 1.11.0)
45-
- WordPressAuthenticator (3.2.0-beta.1):
45+
- WordPressAuthenticator (3.2.0-beta.2):
4646
- Alamofire (~> 4.8)
4747
- CocoaLumberjack (~> 3.5)
4848
- GoogleSignIn (~> 6.0.1)
@@ -92,7 +92,7 @@ DEPENDENCIES:
9292
- Sourcery (~> 1.0.3)
9393
- StripeTerminal (~> 2.7)
9494
- WordPress-Editor-iOS (~> 1.11.0)
95-
- WordPressAuthenticator (from `https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git`, commit `6ddbf0aa1a2df30d1411bfe481a1119b79ea0bb5`)
95+
- WordPressAuthenticator (~> 3.2.0-beta.1)
9696
- WordPressKit (~> 4.49.0)
9797
- WordPressShared (~> 1.15)
9898
- WordPressUI (~> 1.12.5)
@@ -102,6 +102,8 @@ DEPENDENCIES:
102102
- ZendeskSupportSDK (~> 5.0)
103103

104104
SPEC REPOS:
105+
https://github.com/wordpress-mobile/cocoapods-specs.git:
106+
- WordPressAuthenticator
105107
trunk:
106108
- Alamofire
107109
- AppAuth
@@ -139,16 +141,6 @@ SPEC REPOS:
139141
- ZendeskSupportProvidersSDK
140142
- ZendeskSupportSDK
141143

142-
EXTERNAL SOURCES:
143-
WordPressAuthenticator:
144-
:commit: 6ddbf0aa1a2df30d1411bfe481a1119b79ea0bb5
145-
:git: https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git
146-
147-
CHECKOUT OPTIONS:
148-
WordPressAuthenticator:
149-
:commit: 6ddbf0aa1a2df30d1411bfe481a1119b79ea0bb5
150-
:git: https://github.com/wordpress-mobile/WordPressAuthenticator-iOS.git
151-
152144
SPEC CHECKSUMS:
153145
Alamofire: 3ec537f71edc9804815215393ae2b1a8ea33a844
154146
AppAuth: 8fca6b5563a5baef2c04bee27538025e4ceb2add
@@ -171,7 +163,7 @@ SPEC CHECKSUMS:
171163
UIDeviceIdentifier: af4e11e25a2ea670078e2bd677bb0e8144f9f063
172164
WordPress-Aztec-iOS: 050b34d4c3adfb7c60363849049b13d60683b348
173165
WordPress-Editor-iOS: 304098424f1051cb271546c99f906aac296b1b81
174-
WordPressAuthenticator: 434bafe7338f9e52a86ef13f7a84e4da7c4f620f
166+
WordPressAuthenticator: 74f808d6cef4e261843f50d9378dc8bdb5ef1299
175167
WordPressKit: 96deb6ba37ea5eaec4ddcaa53eca04d653246152
176168
WordPressShared: 5477f179c7fe03b5d574f91adda66f67d131827e
177169
WordPressUI: c5be816f6c7b3392224ac21de9e521e89fa108ac
@@ -187,6 +179,6 @@ SPEC CHECKSUMS:
187179
ZendeskSupportProvidersSDK: 2bdf8544f7cd0fd4c002546f5704b813845beb2a
188180
ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba
189181

190-
PODFILE CHECKSUM: 2fcc754eb5ea18bdfafac83851133c65ec13a777
182+
PODFILE CHECKSUM: c8a3ba7544776c3fac1ba06550b2597fc5a03ba6
191183

192184
COCOAPODS: 1.11.3

RELEASE-NOTES.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
-----
55
- [**] Products: Now you can duplicate products from the More menu of the product detail screen. [https://github.com/woocommerce/woocommerce-ios/pull/7727]
66
- [**] Login: Added Jetpack connection support from the Account Mismatch error screen. [https://github.com/woocommerce/woocommerce-ios/pull/7748]
7-
7+
- [*] Orders: We are bringing back the ability to add/edit customer notes and addresses from the main order screen [https://github.com/woocommerce/woocommerce-ios/pull/7750]
8+
- [*] Help center: Added help center web page with FAQs for "Wrong WordPress.com account error" screen. [https://github.com/woocommerce/woocommerce-ios/pull/7747]
9+
- [*] Widgets: The Today's Stat Widget adds support for bigger fonts. [https://github.com/woocommerce/woocommerce-ios/pull/7752]
810

911
10.4
1012
-----

WooCommerce/Classes/Authentication/Navigation Exceptions/ULAccountMismatchViewController.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ final class ULAccountMismatchViewController: UIViewController {
5858
super.viewDidLoad()
5959

6060
configureAccountHeader()
61+
configureRightBarButtonItem()
6162
configureImageView()
6263
configureErrorMessage()
6364
configureExtraInfoButton()
@@ -85,6 +86,16 @@ final class ULAccountMismatchViewController: UIViewController {
8586

8687
// MARK: - View configuration
8788
private extension ULAccountMismatchViewController {
89+
func configureRightBarButtonItem() {
90+
guard let rightBarButtonTitle = viewModel.rightBarButtonItemTitle else {
91+
return
92+
}
93+
navigationItem.rightBarButtonItem = UIBarButtonItem(title: rightBarButtonTitle,
94+
style: .plain,
95+
target: self,
96+
action: #selector(didTapRightBarButtonItem))
97+
}
98+
8899
func configureAccountHeader() {
89100
configureGravatar()
90101
configureUserNameLabel()
@@ -231,6 +242,10 @@ private extension ULAccountMismatchViewController {
231242
func didTapLogOutButton() {
232243
viewModel.didTapLogOutButton(in: self)
233244
}
245+
246+
@objc func didTapRightBarButtonItem() {
247+
viewModel.didTapRightBarButtonItem(in: self)
248+
}
234249
}
235250

236251

WooCommerce/Classes/Authentication/Navigation Exceptions/ULAccountMismatchViewController.xib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@
144144
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
145145
<constraints>
146146
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="10Z-y1-ZQ6" secondAttribute="trailing" id="3Fe-tr-bmb"/>
147-
<constraint firstItem="jIt-xb-rrN" firstAttribute="top" relation="greaterThanOrEqual" secondItem="fnl-2z-Ty3" secondAttribute="top" id="4vu-ll-3S2"/>
148147
<constraint firstAttribute="trailing" secondItem="jIt-xb-rrN" secondAttribute="trailing" constant="34" id="Z7E-hC-lbB"/>
149148
<constraint firstItem="jIt-xb-rrN" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" constant="34" id="jMe-jj-6Bt"/>
150-
<constraint firstItem="10Z-y1-ZQ6" firstAttribute="top" secondItem="jIt-xb-rrN" secondAttribute="bottom" id="puI-lL-LT9"/>
151149
<constraint firstItem="10Z-y1-ZQ6" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" id="r9Z-y5-j3W"/>
152150
<constraint firstItem="fnl-2z-Ty3" firstAttribute="bottom" secondItem="10Z-y1-ZQ6" secondAttribute="bottom" id="rPP-rT-zVR"/>
151+
<constraint firstItem="10Z-y1-ZQ6" firstAttribute="top" relation="greaterThanOrEqual" secondItem="jIt-xb-rrN" secondAttribute="bottom" id="yet-32-SBz"/>
152+
<constraint firstItem="jIt-xb-rrN" firstAttribute="centerY" secondItem="fnl-2z-Ty3" secondAttribute="centerY" priority="250" constant="-20" id="z5R-69-jBg"/>
153153
</constraints>
154154
<point key="canvasLocation" x="137.68115942028987" y="86.383928571428569"/>
155155
</view>

WooCommerce/Classes/Authentication/Navigation Exceptions/ULAccountMismatchViewModel.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,27 @@ protocol ULAccountMismatchViewModel {
6565
/// Executes action associated to a tap in the view controller auxiliary button
6666
/// - Parameter viewController: usually the view controller sending the tap
6767
func didTapAuxiliaryButton(in viewController: UIViewController?)
68+
69+
// MARK: Navigation bar - right bar button item
70+
//
71+
72+
/// Title of the right bar button item in the navigation bar
73+
/// return `nil` if you don't want a `rightBarButtonItem`
74+
///
75+
var rightBarButtonItemTitle: String? { get }
76+
77+
/// Executes action associated to a tap on the right bar button item in the navigation bar
78+
/// - Parameter viewController: usually the view controller sending the tap
79+
///
80+
func didTapRightBarButtonItem(in viewController: UIViewController?)
81+
}
82+
83+
// MARK: Default implementation for optional right bar button item
84+
//
85+
extension ULAccountMismatchViewModel {
86+
var rightBarButtonItemTitle: String? { nil }
87+
88+
func didTapRightBarButtonItem(in viewController: UIViewController?) {
89+
// NO-OP
90+
}
6891
}

WooCommerce/Classes/Authentication/Navigation Exceptions/WrongAccountErrorViewModel.swift

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ final class WrongAccountErrorViewModel: ULAccountMismatchViewModel {
1616
private let storesManager: StoresManager
1717
private let analytics: Analytics
1818
private let jetpackSetupCompletionHandler: (_ email: String, _ xmlrpc: String) -> Void
19+
private let authentication: Authentication
1920

2021
private var storePickerCoordinator: StorePickerCoordinator?
2122
private var siteXMLRPC: String = ""
@@ -26,18 +27,22 @@ final class WrongAccountErrorViewModel: ULAccountMismatchViewModel {
2627
private let primaryButtonLoadingSubject = CurrentValueSubject<Bool, Never>(false)
2728
private let activityIndicatorLoadingSubject = CurrentValueSubject<Bool, Never>(false)
2829

30+
private var primaryButtonSubscription: AnyCancellable?
31+
2932
init(siteURL: String?,
3033
showsConnectedStores: Bool,
3134
siteCredentials: WordPressOrgCredentials?,
3235
sessionManager: SessionManagerProtocol = ServiceLocator.stores.sessionManager,
3336
storesManager: StoresManager = ServiceLocator.stores,
3437
analytics: Analytics = ServiceLocator.analytics,
38+
authentication: Authentication = ServiceLocator.authenticationManager,
3539
onJetpackSetupCompletion: @escaping (String, String) -> Void) {
3640
self.siteURL = siteURL ?? Localization.yourSite
3741
self.showsConnectedStores = showsConnectedStores
3842
self.defaultAccount = sessionManager.defaultAccount
3943
self.storesManager = storesManager
4044
self.analytics = analytics
45+
self.authentication = authentication
4146
self.jetpackSetupCompletionHandler = onJetpackSetupCompletion
4247

4348
if let credentials = siteCredentials {
@@ -50,15 +55,15 @@ final class WrongAccountErrorViewModel: ULAccountMismatchViewModel {
5055

5156
// MARK: - Data and configuration
5257
var userEmail: String {
53-
return defaultAccount?.email ?? ""
58+
defaultAccount?.email ?? ""
5459
}
5560

5661
var userName: String {
57-
return defaultAccount?.displayName ?? siteUsername
62+
defaultAccount?.displayName ?? siteUsername
5863
}
5964

6065
var signedInText: String {
61-
return String.localizedStringWithFormat(Localization.signedInMessageFormat,
66+
String.localizedStringWithFormat(Localization.signedInMessageFormat,
6267
defaultAccount?.username ?? siteUsername)
6368
}
6469

@@ -103,9 +108,19 @@ final class WrongAccountErrorViewModel: ULAccountMismatchViewModel {
103108
activityIndicatorLoadingSubject.eraseToAnyPublisher()
104109
}
105110

111+
// Configures `Help` button title
112+
var rightBarButtonItemTitle: String? {
113+
Localization.helpBarButtonItemTitle
114+
}
115+
106116
// MARK: - Actions
107117
func viewDidLoad(_ viewController: UIViewController?) {
108-
analytics.track(event: .LoginJetpackConnection.jetpackConnectionErrorShown(selfHostedSite: true))
118+
primaryButtonSubscription = primaryButtonHiddenSubject
119+
.dropFirst() // ignores first element
120+
.sink { [weak self] isHidden in
121+
// if the button is hidden, the site is not self-hosted.
122+
self?.analytics.track(event: .LoginJetpackConnection.jetpackConnectionErrorShown(selfHostedSite: !isHidden))
123+
}
109124

110125
// Fetches site info if we're not sure whether the site is self-hosted.
111126
if siteXMLRPC.isEmpty {
@@ -150,12 +165,19 @@ final class WrongAccountErrorViewModel: ULAccountMismatchViewModel {
150165
storesManager.deauthenticate()
151166
viewController?.navigationController?.popToRootViewController(animated: true)
152167
}
168+
169+
func didTapRightBarButtonItem(in viewController: UIViewController?) {
170+
guard let viewController = viewController else {
171+
return
172+
}
173+
authentication.presentSupport(from: viewController, screen: .wrongAccountError)
174+
}
153175
}
154176

155177
// MARK: - Private helpers
156178
private extension WrongAccountErrorViewModel {
157179
/// Fetches the site info and show the primary button if the site is self-hosted.
158-
/// This will enables Jetpack connection support for self-hosted sites.
180+
/// If the site is self-hosted, make the Connect Jetpack button visible.
159181
///
160182
func fetchSiteInfo() {
161183
activityIndicatorLoadingSubject.send(true)
@@ -167,6 +189,8 @@ private extension WrongAccountErrorViewModel {
167189
case .success(let siteInfo):
168190
if siteInfo.isWPCom == false {
169191
self.primaryButtonHiddenSubject.send(false)
192+
} else {
193+
self.primaryButtonHiddenSubject.send(true)
170194
}
171195
case .failure(let error):
172196
DDLogWarn("⚠️ Error fetching site info: \(error)")
@@ -344,6 +368,8 @@ private extension WrongAccountErrorViewModel {
344368
comment: "Error message displayed when failed to check for Jetpack connection."
345369
)
346370

371+
static let helpBarButtonItemTitle = NSLocalizedString("Help",
372+
comment: "Help button on account mismatch error screen.")
347373
}
348374

349375
enum Strings {

WooCommerce/Classes/Model/CustomHelpCenterContent.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ extension CustomHelpCenterContent {
6969
/// Store picker screen - `StorePickerViewController`
7070
///
7171
case storePicker
72+
73+
/// Account mismatch / Wrong WordPress.com account screen - `WrongAccountErrorViewModel`
74+
///
75+
case wrongAccountError
7276
}
7377

7478
init(screen: Screen, flow: AuthenticatorAnalyticsTracker.Flow) {
@@ -80,6 +84,9 @@ extension CustomHelpCenterContent {
8084
case .storePicker:
8185
step = "site_list" // Matching Android `Step` value
8286
url = WooConstants.URLs.helpCenterForStorePicker.asURL()
87+
case .wrongAccountError:
88+
step = "wrong_wordpress_account" // Matching Android `Step` value
89+
url = WooConstants.URLs.helpCenterForWrongAccountError.asURL()
8390
}
8491

8592
trackingProperties = [

WooCommerce/Classes/System/WooConstants.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ extension WooConstants {
123123
///
124124
case helpCenterForJetpackRequiredError = "https://woocommerce.com/document/android-ios-apps-login-help-faq/#jetpack-required"
125125

126+
/// Help Center for "Wrong Account error" screen
127+
///
128+
case helpCenterForWrongAccountError = "https://woocommerce.com/document/android-ios-apps-login-help-faq/#wrong-account"
129+
126130
/// Help Center for "Store picker" screen
127131
///
128132
case helpCenterForStorePicker = "https://woocommerce.com/document/android-ios-apps-login-help-faq/#pick-store-after-entering-password"

0 commit comments

Comments
 (0)