Files

47 lines
1.4 KiB
Swift

//
// Wallet.swift
// Wallet
//
// Created by Igor Danich on 30.08.2020.
// Copyright © 2020 List. All rights reserved.
//
import Foundation
enum P2P {
enum Service {
static private(set) var p2pTokenscollection = [Network.Model.TokenSmall]()
static var tokens: [Network.Model.Token] {
return Self.p2pTokenscollection.compactMap { small in
let balances = Wallet.Service.Tokens.shared.balances
return balances.collection.first(where: { $0 == small.asToken })
}
}
static let sell = Dashboard(kind: .sell)
static let buy = Dashboard(kind: .buy)
static func dashboard(kind: P2P.Model.Kind) -> Dashboard { kind == .sell ? sell : buy }
static func fetch(completion: (() -> Void)? = nil) {
struct Income: Codable {
let income: Network.Model.TokenSmall
}
Network.table.fetch(
code: ApplicationEnvironment.shared().current.contract(.p2p),
table: "swap",
scope: ApplicationEnvironment.shared().current.contract(.p2p),
type: Income.self) { rows in
Self.p2pTokenscollection = rows.map { $0.income }
completion?()
}
}
}
enum Model {}
}