63 lines
1.6 KiB
Swift
63 lines
1.6 KiB
Swift
//
|
|
// InheritanceService.swift
|
|
// PayCash
|
|
//
|
|
// Created by Igor on 11.03.2021.
|
|
// Copyright © 2021 AM. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension Network.Model.Contract {
|
|
var inheritanceMenu: String { "inheritance.menu.\(rawValue)".localized }
|
|
}
|
|
|
|
extension Inheritance {
|
|
class Service: Common.Service.Provider {
|
|
var didUpdate: ((NSError?, Bool) -> () )?
|
|
let information = Information()
|
|
let menus: [Contract] = [.cash, .list, .swap]
|
|
let records = Records()
|
|
}
|
|
}
|
|
|
|
extension Inheritance.Service {
|
|
|
|
func fetch() {
|
|
didUpdate?(nil, true)
|
|
information.fetch {
|
|
self.records.fetch { err in
|
|
self.didUpdate?(err, false)
|
|
}
|
|
}
|
|
}
|
|
|
|
func refresh(privateKey: String, completion: @escaping Completion.Network) {
|
|
guard canRefresh else { completion(nil);return }
|
|
let data = [
|
|
"owner" : information.object?.user_name ?? "",
|
|
"inactive_period" : "\(information.object?.inactive_period ?? 0)"
|
|
]
|
|
Network.Service.Blockchain.execute(contract: information.contract, action: .updinhdate, data: data, privateKeys: [privateKey]) {
|
|
completion(.error($0))
|
|
if case .success(_) = $0 { self.fetch() }
|
|
}
|
|
}
|
|
}
|
|
|
|
extension Inheritance.Service {
|
|
var canRefresh: Bool { information.object != nil }
|
|
var menu: Contract {
|
|
get { information.contract }
|
|
set {
|
|
information.contract = newValue
|
|
records.contract = newValue
|
|
fetch()
|
|
}
|
|
}
|
|
}
|
|
|
|
extension Inheritance.Service {
|
|
typealias Contract = Network.Model.Contract
|
|
}
|