mirror of
https://github.com/lil-org/tokenary.git
synced 2024-12-02 09:33:49 +03:00
keep latest infura key
This commit is contained in:
parent
e1ac601a16
commit
6694536e0f
@ -10,6 +10,15 @@ struct ExtensionBridge {
|
||||
return String(id)
|
||||
}
|
||||
|
||||
static var defaultInfuraKeys: [String]? {
|
||||
get {
|
||||
return defaults?.array(forKey: "defaultInfuraKeys") as? [String]
|
||||
}
|
||||
set {
|
||||
defaults?.set(newValue, forKey: "defaultInfuraKeys")
|
||||
}
|
||||
}
|
||||
|
||||
private static var initiatedRequests: Set<Int> {
|
||||
get {
|
||||
Set(defaults?.array(forKey: "initiatedRequests") as? [Int] ?? [])
|
||||
|
@ -5,13 +5,14 @@ import Foundation
|
||||
struct Nodes {
|
||||
|
||||
private static let infuraKey: String = {
|
||||
if let path = Bundle.main.path(forResource: "shared", ofType: "plist"),
|
||||
if let latest = ExtensionBridge.defaultInfuraKeys?.first, !latest.isEmpty {
|
||||
return latest
|
||||
} else if let path = Bundle.main.path(forResource: "shared", ofType: "plist"),
|
||||
let dict = NSDictionary(contentsOfFile: path) as? [String: AnyObject],
|
||||
let infuraKey = dict["InfuraKey"] as? String, !infuraKey.isEmpty {
|
||||
return infuraKey
|
||||
} else {
|
||||
// TODO: hande infura key not being bundled
|
||||
return ""
|
||||
return "" // TODO: return nil instead
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -26,9 +26,8 @@ class ConfigurationService {
|
||||
if !shouldUpdateApp {
|
||||
getConfiguration()
|
||||
}
|
||||
getInfuraKeyFromCloudKit { infuraKey in
|
||||
// TODO: keep latest version in defaults and make it accessible to Nodes
|
||||
print(infuraKey)
|
||||
getInfuraKeysFromCloudKit { infuraKeys in
|
||||
ExtensionBridge.defaultInfuraKeys = infuraKeys
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,7 +49,7 @@ class ConfigurationService {
|
||||
dataTask.resume()
|
||||
}
|
||||
|
||||
private func getInfuraKeyFromCloudKit(completion: @escaping (String) -> Void) {
|
||||
private func getInfuraKeysFromCloudKit(completion: @escaping ([String]) -> Void) {
|
||||
let container = CKContainer(identifier: "iCloud.tokenary")
|
||||
let publicDatabase = container.publicCloudDatabase
|
||||
let predicate = NSPredicate(value: true)
|
||||
@ -58,10 +57,9 @@ class ConfigurationService {
|
||||
publicDatabase.fetch(withQuery: query) { result in
|
||||
if case .success(let success) = result,
|
||||
case let .success(record) = success.matchResults.first?.1,
|
||||
let infuraKeys = record["infuraKeys"] as? [String],
|
||||
let infuraKey = infuraKeys.first {
|
||||
let infuraKeys = record["infuraKeys"] as? [String], infuraKeys.first?.isEmpty == false {
|
||||
DispatchQueue.main.async {
|
||||
completion(infuraKey)
|
||||
completion(infuraKeys)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user