Files
raspberry/iOS/Wallet/Sources/DeFi/Controller/DeFiControllerMain.swift
T

85 lines
5.0 KiB
Swift

//
// DeFiControllerMain.swift
// Wallet
//
// Created by Saveliy Stavitsky on 3/1/21.
// Copyright © 2021 AM. All rights reserved.
//
import UIKit
import class Resolver.Resolver
class DeFiControllerMain: UIViewController {
@IBOutlet var inheritanceButton: CommonViewCard!
@IBOutlet var swapButton: CommonViewCard!
@IBOutlet var cccpButton: CommonViewCard!
@IBOutlet var cccpExchangeRequestsButton: CommonViewCard!
@IBOutlet var settingsButton: CommonViewCard!
private var requestsService: CCCP.Service.ExchangeRequests { Resolver.resolve() }
private let isSwapActive = Common.Service.Settings.shared.isSwapFunctionalActive
override func viewDidLoad() {
super.viewDidLoad()
// title = L10n.TabBar.more
// navigationItem.leftBarButtonItem = .pop(self)
navigationController?.interactivePopGestureRecognizer?.delegate = nil
// swiftlint:disable:next line_length
inheritanceButton.action = .action(icon: Asset.commonArrowRight.image, empty: .init(uuid: "", image: Asset.defiButtonInheritance.image, imageURLs: nil, title: L10n.Defi.Main.Button.Inheritance.title, text: L10n.Defi.Main.Button.Inheritance.description, details: "", badge: nil, action: {
self.navigationController?.pushViewController(StoryboardScene.Inheritance.initial.instantiate(), animated: true)
}), selected: nil) { [weak self] _ in
self?.navigationController?.pushViewController(StoryboardScene.Inheritance.initial.instantiate(), animated: true)
}
// swiftlint:disable:next line_length
swapButton.action = .action(icon: Asset.commonArrowRight.image, empty: .init(uuid: "", image: Asset.defiButtonSwap.image, imageURLs: nil, title: L10n.Defi.Main.Button.Swap.title, text: L10n.Defi.Main.Button.Swap.description, details: "", badge: nil, action: {
self.navigationController?.pushViewController(StoryboardScene.Swap.swapControllerInvestment.instantiate(), animated: true)
}), selected: nil) { [weak self] _ in
self?.navigationController?.pushViewController(StoryboardScene.Swap.swapControllerInvestment.instantiate(), animated: true)
}
swapButton.isHidden = !self.isSwapActive
// swiftlint:disable:next line_length
cccpButton.action = .action(icon: Asset.commonArrowRight.image, empty: .init(uuid: "", image: Asset.defiButtonCccp.image, imageURLs: nil, title: L10n.Defi.Main.Button.Cryptocash.title, text: L10n.Defi.Main.Button.Cryptocash.description, details: "", badge: nil, action: {
self.navigationController?.pushViewController(StoryboardScene.Cccp.menu.instantiate(), animated: true)
}), selected: nil) { [weak self] _ in
self?.navigationController?.pushViewController(StoryboardScene.Cccp.menu.instantiate(), animated: true)
}
// swiftlint:disable:next line_length
cccpExchangeRequestsButton.action = .action(icon: Asset.commonArrowRight.image, empty: .init(uuid: "", image: Asset.defiButtonCccpExchangeRequests.image, imageURLs: nil, title: L10n.Defi.Main.Button.CryptocashExchangeRequests.title, text: L10n.Defi.Main.Button.CryptocashExchangeRequests.description, details: "", badge: nil, action: {
self.navigationController?.pushViewController(CashExchangeRequestsViewController.loadFromNib(), animated: true)
}), selected: nil) { [weak self] _ in
self?.navigationController?.pushViewController(CashExchangeRequestsViewController.loadFromNib(), animated: true)
}
cccpExchangeRequestsButton.isHidden = !self.isSwapActive
// swiftlint:disable:next line_length
settingsButton.action = .action(icon: Asset.commonArrowRight.image, empty: .init(uuid: "", image: Asset.defiButtonSetttings.image, imageURLs: nil, title: L10n.Defi.Main.Button.Settings.title, text: L10n.Defi.Main.Button.Settings.description, details: "", badge: nil, action: {
self.navigationController?.pushViewController(SettingsViewController.loadFromNib(), animated: true)
}), selected: nil) { [weak self] _ in
self?.navigationController?.pushViewController(SettingsViewController.loadFromNib(), animated: true)
}
Notification.subscribe(name: .didUpdateCryptocashExchangeRequests) { [weak self] _ in
DispatchQueue.main.async {
self?.cccpExchangeRequestsButton.badge = nil
if let count = self?.requestsService.requests.count, count > 0 {
self?.cccpExchangeRequestsButton.badge = "\(count)"
self?.cccpExchangeRequestsButton.badgeColor = Asset.brick.color
}
}
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// navigationController?.setNavigationBarHidden(true, animated: true)
cccpExchangeRequestsButton.badge = nil
if requestsService.requests.count > 0 {
cccpExchangeRequestsButton.badge = "\(requestsService.requests.count)"
cccpExchangeRequestsButton.badgeColor = Asset.brick.color
}
}
}