213 lines
5.7 KiB
Swift
213 lines
5.7 KiB
Swift
//
|
|
// P2PLists.swift
|
|
// Wallet
|
|
//
|
|
// Created by Saveliy Stavitsky on 10/7/21.
|
|
// Copyright © 2021 AM. All rights reserved.
|
|
//
|
|
|
|
import RealmSwift
|
|
|
|
class P2PCountry: Object, Decodable {
|
|
@Persisted(primaryKey: true) var id: Int
|
|
@Persisted(indexed: true) var name: String
|
|
|
|
// @Persisted(originProperty: "country") var cities: LinkingObjects<P2PCity>
|
|
// @Persisted(originProperty: "country") var banks: LinkingObjects<P2PBank>
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case id
|
|
case name
|
|
}
|
|
}
|
|
|
|
class P2PCity: Object, Decodable {
|
|
@Persisted(primaryKey: true) var id: Int
|
|
@Persisted(indexed: true) var name: String
|
|
|
|
@Persisted var country: P2PCountry?
|
|
}
|
|
|
|
class P2PBank: Object, Decodable {
|
|
@Persisted(primaryKey: true) var id: Int
|
|
@Persisted(indexed: true) var name: String
|
|
|
|
@Persisted var country: P2PCountry?
|
|
}
|
|
|
|
enum P2PCurrencyType: String, PersistableEnum, Codable {
|
|
case fiat = "FIAT"
|
|
case crypto = "CRYPTO"
|
|
case emoney = "EMONEY"
|
|
}
|
|
|
|
class P2PCurrency: Object, Decodable {
|
|
@Persisted(primaryKey: true) var id: Int
|
|
@Persisted(indexed: true) var name: String
|
|
@Persisted var precision: Int
|
|
@Persisted var descriptn: String?
|
|
@Persisted(indexed: true) var type: P2PCurrencyType
|
|
|
|
@Persisted var blockchains: List<P2PBlockchain>
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case id
|
|
case name
|
|
case precision
|
|
case descriptn = "description"
|
|
case type
|
|
case blockchains
|
|
}
|
|
|
|
override required init() { }
|
|
|
|
required init(from decoder: Decoder) throws {
|
|
super.init()
|
|
|
|
let values = try decoder.container(keyedBy: CodingKeys.self)
|
|
id = try values.decode(Int.self, forKey: .id)
|
|
name = try values.decode(String.self, forKey: .name)
|
|
precision = try values.decode(Int.self, forKey: .precision)
|
|
descriptn = try? values.decode(String.self, forKey: .descriptn)
|
|
type = try values.decode(P2PCurrencyType.self, forKey: .type)
|
|
|
|
blockchains = List<P2PBlockchain>()
|
|
blockchains.append(objectsIn: (try? values.decode([P2PBlockchain].self, forKey: .blockchains)) ?? [])
|
|
}
|
|
}
|
|
|
|
class P2PBlockchain: Object, Decodable {
|
|
@Persisted(primaryKey: true) var id: Int
|
|
@Persisted(indexed: true) var name: String
|
|
@Persisted var descriptn: String?
|
|
|
|
@Persisted(originProperty: "blockchains") var currencies: LinkingObjects<P2PCurrency>
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case id
|
|
case name
|
|
case descriptn = "description"
|
|
}
|
|
}
|
|
|
|
class P2PPaymentSystem: Object, Decodable {
|
|
@Persisted(primaryKey: true) var id: Int
|
|
@Persisted(indexed: true) var name: String
|
|
|
|
@Persisted var currencies: List<P2PCurrency>
|
|
}
|
|
|
|
struct P2PListsGraphQLRequest: Encodable {
|
|
|
|
struct ResponseData: Decodable {
|
|
let lastUpdate: LastUpdateResponse
|
|
let countries: CountriesResponse?
|
|
let cities: CitiesResponse?
|
|
let banks: BanksResponse?
|
|
let blockchains: BlockchainsResponse?
|
|
let paymentSystems: PaymentSystemsResponse?
|
|
let currencies: CurrenciesResponse?
|
|
|
|
}
|
|
struct LastUpdateResponse: Decodable { let lastUpdate: String }
|
|
struct CountriesResponse: Decodable { let countries: [P2PCountry] }
|
|
struct BanksResponse: Decodable { let banks: [P2PBank] }
|
|
struct CitiesResponse: Decodable { let cities: [P2PCity] }
|
|
struct BlockchainsResponse: Decodable { let blockchains: [P2PBlockchain] }
|
|
struct PaymentSystemsResponse: Decodable { let paymentSystems: [P2PPaymentSystem] }
|
|
struct CurrenciesResponse: Decodable { let currencies: [P2PCurrency] }
|
|
|
|
struct Variables: Encodable {
|
|
let lang: String
|
|
}
|
|
|
|
let variables: Variables
|
|
let operationName = "p2pLists"
|
|
static let queryShort: String = #"""
|
|
query p2pLists {
|
|
lastUpdate {
|
|
lastUpdate
|
|
errors
|
|
}
|
|
}
|
|
"""#
|
|
static let queryFull = #"""
|
|
query p2pLists(
|
|
$lang: Lang
|
|
) {
|
|
lastUpdate {
|
|
lastUpdate
|
|
errors
|
|
}
|
|
countries(
|
|
lang: $lang
|
|
) {
|
|
countries {
|
|
id
|
|
name
|
|
}
|
|
errors
|
|
}
|
|
cities(
|
|
lang: $lang
|
|
) {
|
|
cities{
|
|
id
|
|
name
|
|
country {
|
|
id
|
|
name
|
|
}
|
|
}
|
|
errors
|
|
}
|
|
banks(
|
|
lang: $lang
|
|
) {
|
|
banks {
|
|
id
|
|
name
|
|
country {
|
|
id
|
|
name
|
|
}
|
|
}
|
|
errors
|
|
}
|
|
paymentSystems(
|
|
lang: $lang
|
|
) {
|
|
paymentSystems{
|
|
id
|
|
name
|
|
currencies {
|
|
id
|
|
name
|
|
precision
|
|
description
|
|
type
|
|
}
|
|
}
|
|
errors
|
|
}
|
|
currencies(
|
|
lang: $lang
|
|
) {
|
|
currencies {
|
|
id
|
|
name
|
|
precision
|
|
description
|
|
type
|
|
blockchains {
|
|
id
|
|
name
|
|
description
|
|
}
|
|
}
|
|
}
|
|
}
|
|
"""#
|
|
var query: String
|
|
}
|