Skip to content

Commit 7bdb033

Browse files
committed
7541 Save plugin selection on onboarding complete
Previously, the plugin selection a user made was only stored if the next onboarding state was `.complete`. Our original intention was to only save their selection when they reached `.complete`, so that if they returned to an unfinished onboarding flow they would start from the beginning, including the plugin selection. This change fixes the bug that we wouldn’t save if they saw another onboarding step before `.complete`, by deferring the save until `.complete` rather than only checking the very next state.
1 parent 0ee8622 commit 7bdb033

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ final class CardPresentPaymentsOnboardingUseCase: CardPresentPaymentsOnboardingU
4343
var statePublisher: Published<CardPresentPaymentOnboardingState>.Publisher {
4444
$state
4545
}
46+
private var cancellables: [AnyCancellable] = []
4647

4748
init(
4849
storageManager: StorageManagerType = ServiceLocator.storageManager,
@@ -103,11 +104,19 @@ final class CardPresentPaymentsOnboardingUseCase: CardPresentPaymentsOnboardingU
103104
assert(state.isSelectPlugin)
104105

105106
preferredPluginLocal = selectedPlugin
107+
deferredSaveSelectedPluginWhenOnboardingComplete(selectedPlugin: selectedPlugin)
108+
106109
updateState()
107-
if case .completed(let pluginState) = state,
108-
pluginState.preferred == selectedPlugin {
109-
savePreferredPlugin(selectedPlugin)
110+
}
111+
112+
private func deferredSaveSelectedPluginWhenOnboardingComplete(selectedPlugin: CardPresentPaymentsPlugin) {
113+
$state.share().sink { [weak self] newState in
114+
if case .completed(let pluginState) = newState,
115+
pluginState.preferred == selectedPlugin {
116+
self?.savePreferredPlugin(selectedPlugin)
117+
}
110118
}
119+
.store(in: &cancellables)
111120
}
112121

113122
func clearPluginSelection() {

0 commit comments

Comments
 (0)