140 lines
4.9 KiB
Swift
140 lines
4.9 KiB
Swift
//
|
|
// ApplicationEnvironment.swift
|
|
// Malinka
|
|
//
|
|
// Created by Juraldinio on 10/23/22.
|
|
// Copyright © 2022 NUT.Tech. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import WalletFoundation
|
|
|
|
final class ApplicationEnvironment {
|
|
|
|
enum PayCashEnvironment: String {
|
|
case production = "paycash.prod"
|
|
case preprod = "paycash.preprod"
|
|
}
|
|
|
|
enum MalinkaEnvironment: String {
|
|
case production = "malinka.prod"
|
|
case preprod = "malinka.preprod"
|
|
}
|
|
|
|
private static var instance: ApplicationEnvironment?
|
|
|
|
static func shared() -> ApplicationEnvironment {
|
|
if let instance = Self.instance {
|
|
return instance
|
|
}
|
|
|
|
let instance = ApplicationEnvironment()
|
|
Self.instance = instance
|
|
return instance
|
|
}
|
|
|
|
// MARK: - Properties
|
|
|
|
private(set) var current: ApplicationEnvironmentRecord
|
|
|
|
// MARK: - Methods
|
|
|
|
// MARK: - Private
|
|
|
|
private init() {
|
|
|
|
let malinkaEnv = ApplicationSettings.apiEnvironment.orCreate(MalinkaEnvironment.production.rawValue)
|
|
let paycashEnv = ApplicationSettings.apiPaycashEnvironment.orCreate(PayCashEnvironment.production.rawValue)
|
|
|
|
guard let malinka = Self.malinkaRecords().first(where: { $0.name == malinkaEnv }),
|
|
let paycash = Self.paycashRecords().first(where: { $0.name == paycashEnv }) else {
|
|
fatalError("Environment not found")
|
|
}
|
|
|
|
self.current = ApplicationEnvironmentRecord(malinka: malinka,
|
|
paycash: paycash,
|
|
nodes: Self.eosNodes(),
|
|
hyperions: [])
|
|
}
|
|
|
|
// MARK: - Private Static
|
|
|
|
private static func paycashRecords() -> [ApplicationEnvironmentRecord.PayCash] {
|
|
[
|
|
// PREPROD
|
|
.init(name: PayCashEnvironment.preprod.rawValue,
|
|
listSite: "https://test.list.family/search",
|
|
listGraphQL: "https://api.test.list.family",
|
|
paycashGraphQl: "https://api.test.paycash.online",
|
|
paycashSwap: "https://api.dev.paycashswap.com",
|
|
paycashSwapSite: "https://paycashswap.com",
|
|
freecpu: "https://api.test.paycash.online",
|
|
webSocket: "wss://api.test.paycash.online/ws",
|
|
contracts: Self.contracts(value: .preprod)),
|
|
// PRODUCTION
|
|
.init(name: PayCashEnvironment.production.rawValue,
|
|
listSite: "https://list.family/search",
|
|
listGraphQL: "https://api.list.family",
|
|
paycashGraphQl: "https://api.paycash.online",
|
|
paycashSwap: "https://api.paycashswap.com",
|
|
paycashSwapSite: "https://paycashswap.com",
|
|
freecpu: "https://api.paycash.online",
|
|
webSocket: "wss://api.paycash.online/ws",
|
|
contracts: Self.contracts(value: .production))
|
|
]
|
|
}
|
|
|
|
private static func malinkaRecords() -> [ApplicationEnvironmentRecord.Malinka] {
|
|
[
|
|
.init(name: MalinkaEnvironment.preprod.rawValue, graphQL: "https://api.preprod.malinka.life"),
|
|
.init(name: MalinkaEnvironment.production.rawValue, graphQL: "https://api.malinka.life")
|
|
]
|
|
}
|
|
|
|
private static func eosNodes() -> [ApplicationEnvironmentRecord.UrlPath] {
|
|
[
|
|
"https://eos.greymass.com",
|
|
"https://eos.list.family",
|
|
"https://eos.paycash.online"
|
|
]
|
|
}
|
|
|
|
private static func contracts(value: PayCashEnvironment) -> [EOSContract: String] {
|
|
switch value {
|
|
case .production:
|
|
return [
|
|
.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"
|
|
]
|
|
case .preprod:
|
|
return [
|
|
.list: "jqpua4jqkqwz",
|
|
.cash: "cashescashes",
|
|
.eosioToken: "eosio.token",
|
|
.eosio: "eosio",
|
|
.chat: "mechatmechat",
|
|
.p2p: "aabw2r.pcash",
|
|
.freeCPU: "yp2acwnqldng",
|
|
.appSettings: "appsettings1", // "i4vkf1c32lkp",
|
|
.swap: "testnewswap1",
|
|
.mlnk: "rpspakdrh3eb"
|
|
]
|
|
}
|
|
}
|
|
|
|
static func contracts() -> [String] {
|
|
var contracts = [String]()
|
|
contracts.append(contentsOf: Self.contracts(value: .preprod).values)
|
|
contracts.append(contentsOf: Self.contracts(value: .production).values)
|
|
return contracts
|
|
}
|
|
}
|