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

pull/894/head
Morgan Pretty 2 years ago
parent 87e9306054
commit 842ae25f14

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

@ -8,7 +8,8 @@ import Foundation
public extension FeatureStorage { public extension FeatureStorage {
static let serviceNetwork: FeatureConfig<ServiceNetwork> = Dependencies.create( 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( static let updatedGroups: FeatureConfig<Bool> = Dependencies.create(
identifier: "updatedGroups", identifier: "updatedGroups",
defaultOption: true,
automaticChangeBehaviour: Feature<Bool>.ChangeBehaviour( automaticChangeBehaviour: Feature<Bool>.ChangeBehaviour(
value: true, value: true,
condition: .after(timestamp: Features.legacyGroupDepricationDate.timeIntervalSince1970) condition: .after(timestamp: Features.legacyGroupDepricationDate.timeIntervalSince1970)
@ -124,8 +125,16 @@ public struct Feature<T: FeatureOption>: FeatureType {
// MARK: - Functions // MARK: - Functions
internal func currentValue(using dependencies: Dependencies) -> T { internal func currentValue(using dependencies: Dependencies) -> T {
let selectedOption: Int = dependencies[defaults: .appGroup].integer(forKey: identifier) let maybeSelectedOption: T? = {
let maybeSelectedOption: T? = T(rawValue: selectedOption) // `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 /// 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 /// `automaticChangeBehaviour` conditions have been met, and if so use the specified value

Loading…
Cancel
Save