Files
raspberry/iOS/Wallet/Sources/Network/Service/NetworkServiceServers.swift
T

127 lines
4.6 KiB
Swift

//
// NetworkServiceServers.swift
// Wallet
//
// Created by Igor on 08.10.2020.
// Copyright © 2020 List. All rights reserved.
//
import Foundation
import WalletFoundation
extension Network.Service.Servers {
typealias Model = Network.Model.Server
}
extension Network.Service {
class Servers: Common.Service.Provider {
private(set) var collection: [Model] = [
.init(
name: "malinkanet (prod)",
nodes: [
"https://eos.greymass.com",
"https://eos.list.family",
"https://eos.paycash.online"
],
listFamilySite: "https://list.family/search",
graphql: "https://api.list.family",
paycashGraphQl: "https://api.paycash.online",
paycashSwap: "https://api.paycashswap.com",
paycashSwapSite: "https://paycashswap.com",
malinkaGraphQL: "https://api.malinka.life",
freecpu: "https://api.paycash.online",
webSocket: "wss://api.paycash.online/ws",
contracts: [
.list: "token.list",
.cash: "token.pcash",
.eosioToken: "eosio.token",
.eosio: "eosio",
.chat: "mechatmechat",
.p2p: "p2p.pcash",
.freeCPU: "freetx.pcash",
.appSettings: "appsettings1", // "eidjk2adsmmu",
.swap: "swap.pcash",
.mlnk: "pcash.mlnk"
]
),
.init(
name: "malinkanet (preprod)",
nodes: [
"https://eos.greymass.com",
"https://eos.list.family",
"https://eos.paycash.online"
],
listFamilySite: "https://list.family/search",
graphql: "https://api.list.family",
paycashGraphQl: "https://api.paycash.online",
paycashSwap: "https://api.paycashswap.com",
paycashSwapSite: "https://paycashswap.com",
malinkaGraphQL: "https://api.preprod.malinka.life",
freecpu: "https://api.paycash.online",
webSocket: "wss://api.paycash.online/ws",
contracts: [
.list: "token.list",
.cash: "token.pcash",
.eosioToken: "eosio.token",
.eosio: "eosio",
.chat: "mechatmechat",
.p2p: "p2p.pcash",
.freeCPU: "freetx.pcash",
.appSettings: "appsettings1", // "eidjk2adsmmu",
.swap: "swap.pcash",
.mlnk: "pcash.mlnk"
]
),
]
}
}
extension Network.Service.Servers {
var current: Model {
get { collection.first(where: { $0.name == _current }) ?? collection.first! }
set { update(current: newValue) }
}
func update(nodes: [String], for server: String = Network.servers.current.name) {
collection[collection.firstIndex(where: { $0.name == server })!].nodes = nodes
}
func update(hyperions: [String], for server: String = Network.servers.current.name) {
collection[collection.firstIndex(where: { $0.name == server })!].hyperions = hyperions
}
}
extension Network.Service.Servers {
private var _current: String? {
get {
// First we read application settings
// if let value: String = Settings()[.current] { return value }
// Then we read from application settings
if let environment = ApplicationSettings.apiEnvironment,
!environment.trimCompact().isEmpty {
return environment
}
// finally we check predefined
if let server = Bundle.main.object(forInfoDictionaryKey: Key.current.rawValue) as? String {
return server
}
return nil
}
set { Settings()[.current] = newValue }
}
private func update(current: Model?) {
#warning("Decide something with push logic here")
// Notification.subscribe(name: .willChangeServer) { [unowned self]_ in
// removePush()
// }
_current = current?.name
delayed(2, { exit(0) })
// Notification.subscribe(name: .didChangeServer) { [unowned self]_ in
// updatePush()
// }
}
}
extension Common.Model.Key {
fileprivate static let current = Self("Network.Service.Servers.current")
}