Skip to content

Commit 30a6663

Browse files
committed
Use app setting instead of feature flag
1 parent e5f2034 commit 30a6663

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

Modules/Sources/Yosemite/Actions/AppSettingsAction.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,4 +356,14 @@ public enum AppSettingsAction: Action {
356356
/// Loads the favorite products.
357357
///
358358
case loadFavoriteProductIDs(siteID: Int64, onCompletion: ([Int64]) -> Void)
359+
360+
// MARK: - Application passwords Experiment feature
361+
362+
/// Sets the dismiss state for the Custom Fields top banner
363+
///
364+
case setAppPasswordsExperimentSwitchState(isOn: Bool, onCompletion: (Result<Void, Error>) -> Void)
365+
366+
/// Loads the dismiss state of the Custom Fields top banner
367+
///
368+
case getAppPasswordsExperimentSwitchState(onCompletion: (Bool) -> Void)
359369
}

Modules/Sources/Yosemite/Stores/AppSettingsStore.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ public class AppSettingsStore: Store {
289289
dismissCustomFieldsTopBanner(onCompletion: onCompletion)
290290
case .loadCustomFieldsTopBannerDismissState(let onCompletion):
291291
loadCustomFieldsTopBannerDismissState(onCompletion: onCompletion)
292+
case .setAppPasswordsExperimentSwitchState(let value, let onCompletion):
293+
setAppPasswordsExperimentSwitchEnabled(isOn: value, onCompletion: onCompletion)
294+
case .getAppPasswordsExperimentSwitchState(let onCompletion):
295+
getAppPasswordsExperimentSwitchEnabled(onCompletion: onCompletion)
292296
}
293297
}
294298
}
@@ -1269,6 +1273,24 @@ private extension AppSettingsStore {
12691273
}
12701274
}
12711275

1276+
// MARK: - Application Passwords Experiment Feature
1277+
//
1278+
private extension AppSettingsStore {
1279+
func setAppPasswordsExperimentSwitchEnabled(isOn: Bool, onCompletion: (Result<Void, Error>) -> Void) {
1280+
do {
1281+
try generalAppSettings.setValue(isOn, for: \.isApplicationPasswordsSwitchEnabled)
1282+
onCompletion(.success(()))
1283+
} catch {
1284+
onCompletion(.failure(error))
1285+
}
1286+
}
1287+
1288+
func getAppPasswordsExperimentSwitchEnabled(onCompletion: (Bool) -> Void) {
1289+
onCompletion(generalAppSettings.value(for: \.isApplicationPasswordsSwitchEnabled))
1290+
}
1291+
}
1292+
1293+
12721294
// MARK: - Errors
12731295

12741296
/// Errors

WooCommerce/Classes/Yosemite/AuthenticatedState.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ class AuthenticatedState: StoresManagerState {
137137
trackEventRequestNotificationHandler = TrackEventRequestNotificationHandler()
138138

139139
startListeningToNotifications()
140-
checkApplicationPasswordExperimentFeatureFlag()
140+
141+
DispatchQueue.main.async {
142+
self.checkApplicationPasswordExperimentFeatureState()
143+
}
141144
}
142145

143146
/// Convenience Initializer
@@ -192,11 +195,11 @@ private extension AuthenticatedState {
192195
ServiceLocator.analytics.track(.jetpackTunnelTimeout)
193196
}
194197

195-
/// Uses local feature flag for development phase.
196-
/// TODO: Switch to remote feature flag before release.
197-
func checkApplicationPasswordExperimentFeatureFlag() {
198-
let enabled = ServiceLocator.featureFlagService.isFeatureFlagEnabled(.applicationPasswordExperiment)
199-
network.updateAppPasswordSwitching(enabled: enabled)
198+
func checkApplicationPasswordExperimentFeatureState() {
199+
let action = AppSettingsAction.getAppPasswordsExperimentSwitchState { [weak self] isOn in
200+
self?.network.updateAppPasswordSwitching(enabled: isOn)
201+
}
202+
ServiceLocator.stores.dispatch(action)
200203
}
201204
}
202205

0 commit comments

Comments
 (0)