// // MainControllerAccountsPopup.swift // List // // Created by Saveliy Stavitsky on 7/16/20. // Copyright © 2020 Igor Danich. All rights reserved. // import UIKit import WalletFoundation final class AccountsSelectionViewController: UIViewController { @IBOutlet weak var mainStackView: UIStackView! @IBOutlet var scrollView: UIScrollView! @IBOutlet var stackView: UIStackView! @IBOutlet var addAccountButton: UIButton! override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) Accounts().isLocked = true self.navigationController >>- { $0.setNavigationBarHidden(false, animated: true) $0.navigationBar.isTranslucent = true $0.navigationBar.backgroundColor = Asset.snow.color } self.configureView() } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) Accounts().isLocked = false } override func viewDidLoad() { super.viewDidLoad() self.title = L10n.Main.Account.title self.navigationItem.leftBarButtonItem = .pop(self, { vc in vc.dismiss(animated: true) }) } func configureView() { self.stackView.arrangedSubviews.forEach { $0.removeFromSuperview() } for account in Accounts().collection { let accountButton = AccountViewSelect() accountButton.title = account.name accountButton.keyType = "@\(account.keyType)" accountButton.didTapRemove = { [weak self]_ in guard let self else { return } Alert.system( text: L10n.Main.Account.remove, actions: [ .yes { Accounts().remove(wallet: account) self.configureView() // PAYCASH-NEW if !Accounts().current.isExist { self.mainController.showWalletBoarding() } }, .no ], in: self ) } accountButton.didTapReveal = { [weak self]_ in guard let self else { return } AccountController.showPrivateKeyPopup(in: self, wallet: account) } accountButton.completion = { [weak self] accountButton in guard let self else { return } UIView.animate(withDuration: .slowest) { self.stackView.arrangedSubviews .compactMap({ $0 as? AccountViewSelect }) .forEach({ $0.isActive = false }) accountButton.isActive = true self.view.layoutIfNeeded() } Accounts().current = account self.mainController.content.pop(animated: true) } accountButton.isActive = account.name == Accounts().current?.name self.stackView.addArrangedSubview(accountButton) let currentAccount = Accounts().current let isActiveAccount = account.name == currentAccount?.name && account.keyType == currentAccount?.keyType accountButton.isActive = isActiveAccount } self.scrollView.layoutIfNeeded() } @IBAction func addAccountPressed(_ sender: Any) { AccountController.showPopup(in: self) } }