67 lines
1.8 KiB
Swift
67 lines
1.8 KiB
Swift
//
|
|
// P2PDepositsGraphQLRequest.swift
|
|
// Wallet
|
|
//
|
|
// Created by Saveliy Stavitsky on 8/13/21.
|
|
// Copyright © 2021 AM. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
import class RealmSwift.Object
|
|
import struct RealmSwift.Persisted
|
|
import class RealmSwift.Decimal128
|
|
|
|
class P2PBalance: Object, Decodable {
|
|
@Persisted var amount: Decimal128
|
|
@Persisted(primaryKey: true) var symbol: String
|
|
@Persisted var precision: Int
|
|
@Persisted var blockedAmount: Decimal128
|
|
|
|
// swiftlint:disable identifier_name
|
|
enum CodingKeys: String, CodingKey {
|
|
case balance
|
|
case blocked_balance
|
|
}
|
|
|
|
override required init() { }
|
|
|
|
required init(from decoder: Decoder) throws {
|
|
super.init()
|
|
|
|
let values = try decoder.container(keyedBy: CodingKeys.self)
|
|
amount = try Decimal128(string: try values.decode(String.self, forKey: .balance).amount)
|
|
symbol = try values.decode(String.self, forKey: .balance).symbol
|
|
precision = try values.decode(String.self, forKey: .balance).amount.precision
|
|
blockedAmount = try Decimal128(string: try values.decode(String.self, forKey: .blocked_balance).amount)
|
|
}
|
|
}
|
|
|
|
struct P2PDepositsGraphQLRequest: Encodable {
|
|
|
|
struct ResponseData: Decodable { let p2pDeposits: Response? }
|
|
struct Response: Decodable { let deposits: [P2PBalance] }
|
|
|
|
struct Variables: Encodable {
|
|
let username: String
|
|
}
|
|
|
|
let variables: Variables
|
|
let operationName = "p2pDeposits"
|
|
let query: String = #"""
|
|
query p2pDeposits(
|
|
$username: String!
|
|
) {
|
|
p2pDeposits(
|
|
username: $username
|
|
) {
|
|
deposits {
|
|
balance
|
|
blocked_balance
|
|
}
|
|
errors
|
|
}
|
|
}
|
|
"""#
|
|
}
|