Skip to content

Commit e5f2034

Browse files
committed
Cache remote FF state in user defaults
1 parent e82a95b commit e5f2034

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

WooCommerce/Classes/Extensions/UserDefaults+Woo.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ extension UserDefaults {
6969

7070
// Hide stores from store picker
7171
case hiddenStoreIDs
72+
73+
// Application passwords experiment remote FF cached value
74+
case applicationPasswordsExperimentRemoteFFValue
7275
}
7376
}
7477

WooCommerce/Classes/ViewRelated/Dashboard/Settings/Beta features/ApplicationPasswordsExperimentAvailabilityChecker.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,30 @@ protocol ApplicationPasswordsExperimentAvailabilityCheckerProtocol {
66
}
77

88
final class ApplicationPasswordsExperimentAvailabilityChecker: ApplicationPasswordsExperimentAvailabilityCheckerProtocol {
9+
private let userDefaults: UserDefaults
10+
11+
init(userDefaults: UserDefaults = .standard) {
12+
self.userDefaults = userDefaults
13+
}
14+
915
var cachedValue: Bool {
10-
return false
16+
get {
17+
userDefaults[.applicationPasswordsExperimentRemoteFFValue] ?? false
18+
} set {
19+
userDefaults[.applicationPasswordsExperimentRemoteFFValue] = newValue
20+
}
1121
}
1222

1323
func fetchAvailability() async -> Bool {
1424
await withCheckedContinuation { continuation in
1525
//TODO: - put the remote FF checking here
26+
let mockResultValue = true
27+
1628
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
17-
continuation.resume(returning: true)
29+
continuation.resume(returning: mockResultValue)
1830
}
1931

20-
//TODO: - save fetched value to local cache
32+
cachedValue = mockResultValue
2133
}
2234
}
2335
}

0 commit comments

Comments
 (0)