[TEST] Updated defaults to use Testnet and have updated groups enabled

pull/894/head
Morgan Pretty 1 year ago
parent 87e9306054
commit 842ae25f14

@ -15,6 +15,7 @@ public class FeatureConfig<T: FeatureOption>: FeatureStorage {
/// `fileprivate` to hide when accessing via `dependencies[feature: ]`
fileprivate init(
identifier: String,
defaultOption: T,
automaticChangeBehaviour: Feature<T>.ChangeBehaviour?
) {
self.identifier = identifier
@ -22,7 +23,7 @@ public class FeatureConfig<T: FeatureOption>: FeatureStorage {
Feature<T>(
identifier: identifier,
options: Array(T.allCases),
defaultOption: T.defaultOption,
defaultOption: defaultOption,
automaticChangeBehaviour: automaticChangeBehaviour
)
}
@ -34,10 +35,12 @@ public class FeatureConfig<T: FeatureOption>: FeatureStorage {
public extension Dependencies {
static func create<T: FeatureOption>(
identifier: String,
defaultOption: T = T.defaultOption,
automaticChangeBehaviour: Feature<T>.ChangeBehaviour? = nil
) -> FeatureConfig<T> {
return FeatureConfig(
identifier: identifier,
defaultOption: defaultOption,
automaticChangeBehaviour: automaticChangeBehaviour
)
}

@ -8,7 +8,8 @@ import Foundation
public extension FeatureStorage {
static let serviceNetwork: FeatureConfig<ServiceNetwork> = Dependencies.create(
identifier: "serviceNetwork"
identifier: "serviceNetwork",
defaultOption: .testnet
)
}

@ -23,6 +23,7 @@ public extension FeatureStorage {
static let updatedGroups: FeatureConfig<Bool> = Dependencies.create(
identifier: "updatedGroups",
defaultOption: true,
automaticChangeBehaviour: Feature<Bool>.ChangeBehaviour(
value: true,
condition: .after(timestamp: Features.legacyGroupDepricationDate.timeIntervalSince1970)
@ -124,8 +125,16 @@ public struct Feature<T: FeatureOption>: FeatureType {
// MARK: - Functions
internal func currentValue(using dependencies: Dependencies) -> T {
let selectedOption: Int = dependencies[defaults: .appGroup].integer(forKey: identifier)
let maybeSelectedOption: T? = T(rawValue: selectedOption)
let maybeSelectedOption: T? = {
// `Int` defaults to `0` and `Bool` defaults to `false` so rather than those (in case we want
// a default value that isn't `0` or `false` which might be considered valid cases) we check
// if an entry exists and return `nil` if not before retrieving an `Int` representation of
// the value and converting to the desired type
guard dependencies[defaults: .appGroup].object(forKey: identifier) != nil else { return nil }
let selectedOption: Int = dependencies[defaults: .appGroup].integer(forKey: identifier)
return T(rawValue: selectedOption)
}()
/// If we have an explicitly set `selectedOption` then we should use that, otherwise we should check if any of the
/// `automaticChangeBehaviour` conditions have been met, and if so use the specified value

Loading…
Cancel
Save