79 lines
2.4 KiB
Swift
79 lines
2.4 KiB
Swift
//
|
|
// ResourcesControllerPopup.swift
|
|
// Wallet
|
|
//
|
|
// Created by Igor on 11.02.2021.
|
|
// Copyright © 2021 AM. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class ResourcesControllerPopup: UIViewController {
|
|
@IBOutlet private var quotasContainerStackView: UIStackView!
|
|
@IBOutlet private weak var quotaView: UIView!
|
|
@IBOutlet private weak var statisticsView: UIView!
|
|
@IBOutlet private weak var selectedResourcesRadioBattonsGroupView: CommonViewRadioGroup!
|
|
|
|
private let account = Accounts().current?.username
|
|
|
|
private var quota: ResourcesControllerPopupQuota { child()! }
|
|
private var statistics: ResourcesControllerPopupStatistics { child()! }
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
Notification.subscribe(bag: bag, name: .didUpdateAccountQuota) { [weak self]_ in
|
|
self?.selectRightQuota()
|
|
}
|
|
selectedResourcesRadioBattonsGroupView.collection = [L10n.Resources.Popup.Transactions.title,
|
|
L10n.Resources.Popup.Statistics.title]
|
|
|
|
|
|
self.selectRightQuota()
|
|
|
|
if let account = account {
|
|
quota.service = .init(account: account)
|
|
statistics.service = .init(account: account)
|
|
}
|
|
}
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
super.viewWillAppear(animated)
|
|
preload()
|
|
}
|
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
super.viewWillDisappear(animated)
|
|
bag.flush()
|
|
}
|
|
|
|
private func preload() {
|
|
Loader.show(in: self)
|
|
self.quotasContainerStackView.alpha = 0
|
|
let group = DispatchGroup()
|
|
group.enter()
|
|
quota.service.fetch { _ in
|
|
group.leave()
|
|
}
|
|
group.enter()
|
|
statistics.service.fetch { _ in
|
|
group.leave()
|
|
}
|
|
group.notify(queue: .main) {
|
|
Loader.hide(in: self)
|
|
self.selectRightQuota()
|
|
UIView.animate(withDuration: 0.3) {
|
|
self.quotasContainerStackView.alpha = 1
|
|
}
|
|
}
|
|
}
|
|
|
|
@IBAction func onResourcesSelect(_ sender: Any) {
|
|
let isEnabled = self.selectedResourcesRadioBattonsGroupView.selectedIndex == 0
|
|
Accounts().quota.isEnabled = isEnabled
|
|
}
|
|
|
|
func selectRightQuota() {
|
|
selectedResourcesRadioBattonsGroupView.selectedIndex = Accounts().quota.isEnabled ? 0 : 1
|
|
}
|
|
}
|