Skip to content

Commit 4a80ce3

Browse files
committed
Update AppSettingsStore with coupon management feature switch
1 parent 2078b34 commit 4a80ce3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Yosemite/Yosemite/Stores/AppSettingsStore.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ public class AppSettingsStore: Store {
205205
setProductSKUInputScannerFeatureSwitchState(isEnabled: isEnabled, onCompletion: onCompletion)
206206
case .loadProductSKUInputScannerFeatureSwitchState(onCompletion: let onCompletion):
207207
loadProductSKUInputScannerFeatureSwitchState(onCompletion: onCompletion)
208+
case .setCouponManagementFeatureSwitchState(let isEnabled, let onCompletion):
209+
setCouponManagementFeatureSwitchState(isEnabled: isEnabled, onCompletion: onCompletion)
210+
case .loadCouponManagementFeatureSwitchState(let onCompletion):
211+
loadCouponManagementFeatureSwitchState(onCompletion: onCompletion)
208212
}
209213
}
210214
}
@@ -357,6 +361,25 @@ private extension AppSettingsStore {
357361
onCompletion(.success(settings.isProductSKUInputScannerSwitchEnabled))
358362
}
359363

364+
/// Sets the state for the Coupon Mangagement beta feature switch into `GeneralAppSettings`.
365+
///
366+
func setCouponManagementFeatureSwitchState(isEnabled: Bool, onCompletion: (Result<Void, Error>) -> Void) {
367+
do {
368+
let settings = loadOrCreateGeneralAppSettings().copy(isCouponManagementSwitchEnabled: isEnabled)
369+
try saveGeneralAppSettings(settings)
370+
onCompletion(.success(()))
371+
} catch {
372+
onCompletion(.failure(error))
373+
}
374+
}
375+
376+
/// Loads the most recent state for the Coupon Management beta feature switch from `GeneralAppSettings`.
377+
///
378+
func loadCouponManagementFeatureSwitchState(onCompletion: (Result<Bool, Error>) -> Void) {
379+
let settings = loadOrCreateGeneralAppSettings()
380+
onCompletion(.success(settings.isCouponManagementSwitchEnabled))
381+
}
382+
360383
/// Loads the last persisted eligibility error information from `GeneralAppSettings`
361384
///
362385
func loadEligibilityErrorInfo(onCompletion: (Result<EligibilityErrorInfo, Error>) -> Void) {
@@ -417,6 +440,7 @@ private extension AppSettingsStore {
417440
isStripeInPersonPaymentsSwitchEnabled: false,
418441
isCanadaInPersonPaymentsSwitchEnabled: false,
419442
isProductSKUInputScannerSwitchEnabled: false,
443+
isCouponManagementSwitchEnabled: false,
420444
knownCardReaders: [],
421445
lastEligibilityErrorInfo: nil)
422446
}

0 commit comments

Comments
 (0)