Skip to content

Commit 55c09ed

Browse files
committed
Pass the onboarding use case to the flow so it can show the already retrieved error
1 parent bcd4a8f commit 55c09ed

File tree

2 files changed

+43
-34
lines changed

2 files changed

+43
-34
lines changed

WooCommerce/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/InPersonPaymentsMenuViewController.swift

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -75,41 +75,43 @@ private extension InPersonPaymentsMenuViewController {
7575
.debounce(for: .milliseconds(100), scheduler: DispatchQueue.main)
7676
.removeDuplicates()
7777
.sink(receiveValue: { [weak self] state in
78-
guard let self = self else { return }
79-
80-
self.pluginState = nil
81-
82-
guard state != .loading else {
83-
self.activityIndicator?.startAnimating()
84-
return
85-
}
86-
87-
switch state {
88-
case let .completed(newPluginState):
89-
self.pluginState = newPluginState
90-
self.dismissCardPresentPaymentsOnboardingNoticeIfPresent()
91-
case let .selectPlugin(pluginSelectionWasCleared):
92-
// If it was cleared it means that we triggered it manually (e.g by tapping in this view on the plugin selection row)
93-
// No need to show the onboarding notice
94-
if !pluginSelectionWasCleared {
95-
self.showCardPresentPaymentsOnboardingNotice()
96-
}
97-
default:
98-
self.showCardPresentPaymentsOnboardingNotice()
99-
}
100-
101-
self.activityIndicator?.stopAnimating()
102-
self.configureSections()
103-
self.tableView.reloadData()
78+
self?.refreshAfterNewOnboardingState(state)
10479
}).store(in: &cancellables)
10580
}
10681

82+
func refreshAfterNewOnboardingState(_ state: CardPresentPaymentOnboardingState) {
83+
self.pluginState = nil
84+
85+
guard state != .loading else {
86+
self.activityIndicator?.startAnimating()
87+
return
88+
}
89+
90+
switch state {
91+
case let .completed(newPluginState):
92+
self.pluginState = newPluginState
93+
self.dismissCardPresentPaymentsOnboardingNoticeIfPresent()
94+
case let .selectPlugin(pluginSelectionWasCleared):
95+
// If it was cleared it means that we triggered it manually (e.g by tapping in this view on the plugin selection row)
96+
// No need to show the onboarding notice
97+
if !pluginSelectionWasCleared {
98+
self.showCardPresentPaymentsOnboardingNotice()
99+
}
100+
default:
101+
self.showCardPresentPaymentsOnboardingNotice()
102+
}
103+
104+
self.activityIndicator?.stopAnimating()
105+
self.configureSections()
106+
self.tableView.reloadData()
107+
}
108+
107109
func showCardPresentPaymentsOnboardingNotice() {
108110
let permanentNotice = PermanentNotice(message: Localization.inPersonPaymentsSetupNotFinishedNotice,
109111
callToActionTitle: Localization.inPersonPaymentsSetupNotFinishedNoticeButtonTitle,
110112
callToActionHandler: { [weak self] in
111113
ServiceLocator.analytics.track(.paymentsMenuOnboardingErrorTapped)
112-
self?.showOnboardingIfRequired()
114+
self?.showOnboarding()
113115
})
114116

115117
permanentNoticePresenter.presentNotice(notice: permanentNotice, from: self)
@@ -119,18 +121,21 @@ private extension InPersonPaymentsMenuViewController {
119121
permanentNoticePresenter.dismiss()
120122
}
121123

122-
func showOnboardingIfRequired() {
124+
func showOnboarding() {
123125
guard let navigationController = self.navigationController else {
124126
return
125127
}
126128

127-
// Recreating it ensures that the readiness state is up to date.
128-
// Keeping a reference ensures that the callback closure is retained.
129-
cardPresentPaymentsOnboardingPresenter = CardPresentPaymentsOnboardingPresenter()
130-
131-
cardPresentPaymentsOnboardingPresenter?.showOnboardingIfRequired(from: navigationController) { [weak self] in
132-
self?.cardPresentPaymentsOnboardingUseCase.refresh()
129+
let onboardingViewModel = InPersonPaymentsViewModel(useCase: cardPresentPaymentsOnboardingUseCase, showMenuOnCompletion: false)
130+
onboardingViewModel.onOnboardingCompletion = { [weak self] plugin in
131+
self?.refreshAfterNewOnboardingState(.completed(plugin: plugin))
132+
if navigationController.visibleViewController is InPersonPaymentsViewController {
133+
navigationController.popViewController(animated: true)
134+
}
133135
}
136+
137+
let onboardingViewController = InPersonPaymentsViewController(viewModel: onboardingViewModel)
138+
show(onboardingViewController, sender: self)
134139
}
135140
}
136141

WooCommerce/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/InPersonPaymentsViewModel.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ final class InPersonPaymentsViewModel: ObservableObject {
88
var learnMoreURL: URL? = nil
99
let showMenuOnCompletion: Bool
1010
let gatewaySelectionAvailable: Bool
11+
var onOnboardingCompletion: ((CardPresentPaymentsPluginState) -> ())?
1112
private let useCase: CardPresentPaymentsOnboardingUseCase
1213
let stores: StoresManager
1314

@@ -29,6 +30,9 @@ final class InPersonPaymentsViewModel: ObservableObject {
2930
.debounce(for: .milliseconds(100), scheduler: DispatchQueue.main)
3031
.removeDuplicates()
3132
.handleEvents(receiveOutput: { [weak self] result in
33+
if case let .completed(plugin) = result {
34+
self?.onOnboardingCompletion?(plugin)
35+
}
3236
self?.updateLearnMoreURL(state: result)
3337
})
3438
.handleEvents(receiveOutput: trackState(_:))

0 commit comments

Comments
 (0)