-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡️[Feature] Add remote config [deconflicted] (#265)
* Added the remote config components - Testing FB client - Confirmed Firebase registered for remote config - Checking all params Signed-off-by: kcw-grunt <[email protected]> * Added tests Readd Remote Signed-off-by: kcw-grunt <[email protected]> * updated gitignore Signed-off-by: kcw-grunt <[email protected]> * update project version bump - Clean unused code - Readded test class Signed-off-by: kcw-grunt <[email protected]> --------- Signed-off-by: kcw-grunt <[email protected]>
- Loading branch information
Showing
11 changed files
with
187 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import Foundation | ||
import UIKit | ||
|
||
/// 14 Languages | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import FirebaseRemoteConfig | ||
import Foundation | ||
import KeychainAccess | ||
import UIKit | ||
|
||
enum RemoteConfigKeys: String { | ||
case KEY_FEATURE_MENU_HIDDEN_EXAMPLE = "feature_menu_hidden_example" | ||
case KEY_API_BASEURL_PROD_NEW_ENABLED = "key_api_baseurl_prod_new_enabled" | ||
case KEY_API_BASEURL_DEV_NEW_ENABLED = "key_api_baseurl_dev_new_enabled" | ||
case KEY_KEYSTORE_MANAGER_ENABLED = "key_keystore_manager_enabled" | ||
case KEY_PROD_API_BASEURL = "key_prod_api_baseurl" | ||
case KEY_DEV_API_BASEURL = "key_dev_api_baseurl" | ||
} | ||
|
||
class RemoteConfigHelper: NSObject { | ||
static let sharedInstance = RemoteConfigHelper() | ||
|
||
private var remoteConfig: RemoteConfig! | ||
private let settings = RemoteConfigSettings() | ||
private let keychainEnvironment = Keychain(service: "litewallet.environment") | ||
private let debugFetchInterval: TimeInterval = 0 // seconds | ||
private let productionFetchInterval: TimeInterval = 60 * 180 // seconds; Fetch every 3 hours in production mode | ||
override init() { | ||
super.init() | ||
remoteConfig = RemoteConfig.remoteConfig() | ||
setupRemoteConfig() | ||
} | ||
|
||
deinit {} | ||
|
||
private func setupRemoteConfig() { | ||
remoteConfig.setDefaults(fromPlist: "remote-config-defaults") | ||
#if DEBUG | ||
settings.minimumFetchInterval = debugFetchInterval | ||
#else | ||
settings.minimumFetchInterval = productionFetchInterval | ||
#endif | ||
|
||
remoteConfig.configSettings = settings | ||
|
||
/// Call the first time | ||
fetchAndActivateRemoteConfig() | ||
|
||
/// Update based on remote changes | ||
remoteConfig.addOnConfigUpdateListener { configUpdate, error in | ||
guard let configUpdate, error == nil else { | ||
let errorDict: [String: String] = ["error": error?.localizedDescription ?? ""] | ||
LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR, properties: errorDict) | ||
return | ||
} | ||
|
||
self.fetchAndActivateRemoteConfig() | ||
} | ||
} | ||
|
||
private func fetchAndActivateRemoteConfig() { | ||
remoteConfig.fetch { status, error in | ||
if status == .success { | ||
self.remoteConfig.activate { _, error in | ||
guard error == nil else { return } | ||
DispatchQueue.main.async { | ||
LWAnalytics.logEventWithParameters(itemName: ._20241213_RCC) | ||
} | ||
} | ||
} else { | ||
let errorDict: [String: String] = ["error": error?.localizedDescription ?? ""] | ||
LWAnalytics.logEventWithParameters(itemName: ._20200112_ERR, properties: errorDict) | ||
} | ||
} | ||
} | ||
|
||
func getString(key: String) -> String { | ||
return remoteConfig[key].stringValue ?? "value_not_found" | ||
} | ||
|
||
func getNumber(key: String) -> NSNumber { | ||
return remoteConfig[key].numberValue | ||
} | ||
|
||
func getBool(key: String) -> Bool { | ||
return remoteConfig[key].boolValue | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
@testable import litewallet | ||
import XCTest | ||
|
||
class APITests: XCTestCase { | ||
var apiServer: APIServer! | ||
var apiClient: BRAPIClient! | ||
|
||
override func setUpWithError() throws { | ||
apiServer = APIServer() | ||
apiClient = litewallet.BRAPIClient(authenticator: NoAuthAuthenticator()) | ||
} | ||
|
||
override func tearDownWithError() throws { | ||
apiServer = nil | ||
} | ||
|
||
func testfetchExchangeRates() throws { | ||
apiClient.exchangeRates { rates, _ in | ||
for rate in rates { | ||
if rate.code == "AFN" { | ||
XCTAssertEqual(rate.name, "Afghan Afghani") | ||
} | ||
if rate.code == "GBP" { | ||
XCTAssertEqual(rate.name, "British Pound Sterling") | ||
} | ||
if rate.code == "EUR" { | ||
XCTAssertEqual(rate.name, "Euro") | ||
} | ||
if rate.code == "USD" { | ||
XCTAssertEqual(rate.name, "US Dollar") | ||
} | ||
} | ||
} | ||
} | ||
|
||
func testfeePerKb() throws { | ||
apiClient.feePerKb { fees, _ in | ||
XCTAssertGreaterThan(fees.economy, 0) | ||
XCTAssertGreaterThan(fees.regular, 0) | ||
XCTAssertGreaterThan(fees.luxury, 0) | ||
} | ||
} | ||
} |