An advanced Ethereum/EVM mobile wallet
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
alpha-wallet-ios/Trust/Accounts/Coordinators/AccountsCoordinator.swift

87 lines
3.0 KiB

// Copyright SIX DAY LLC. All rights reserved.
7 years ago
import Foundation
import UIKit
protocol AccountsCoordinatorDelegate: class {
func didCancel(in coordinator: AccountsCoordinator)
func didSelectAccount(account: Account, in coordinator: AccountsCoordinator)
func didDeleteAccount(account: Account, in coordinator: AccountsCoordinator)
}
class AccountsCoordinator: Coordinator {
7 years ago
let navigationController: UINavigationController
var coordinators: [Coordinator] = []
7 years ago
lazy var accountsViewController: AccountsViewController = {
let controller = AccountsViewController()
controller.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(dismiss))
7 years ago
controller.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(add))
controller.allowsAccountDeletion = true
controller.delegate = self
return controller
}()
7 years ago
lazy var rootNavigationController: UINavigationController = {
let controller = self.accountsViewController
let nav = NavigationController(rootViewController: controller)
nav.modalPresentationStyle = .formSheet
7 years ago
return nav
}()
7 years ago
weak var delegate: AccountsCoordinatorDelegate?
7 years ago
init(navigationController: UINavigationController) {
self.navigationController = navigationController
}
7 years ago
func start() {
navigationController.present(rootNavigationController, animated: true, completion: nil)
}
7 years ago
@objc func dismiss() {
delegate?.didCancel(in: self)
}
7 years ago
@objc func add() {
showCreateWallet()
}
7 years ago
func showCreateWallet() {
let coordinator = WalletCoordinator()
coordinator.delegate = self
addCoordinator(coordinator)
coordinator.start(.welcome)
rootNavigationController.present(coordinator.navigationController, animated: true, completion: nil)
7 years ago
}
}
extension AccountsCoordinator: AccountsViewControllerDelegate {
func didSelectAccount(account: Account, in viewController: AccountsViewController) {
delegate?.didSelectAccount(account: account, in: self)
}
7 years ago
func didDeleteAccount(account: Account, in viewController: AccountsViewController) {
delegate?.didDeleteAccount(account: account, in: self)
}
}
extension AccountsCoordinator: WalletCoordinatorDelegate {
func didFinish(with account: Account, in coordinator: WalletCoordinator) {
accountsViewController.fetch()
coordinator.navigationController.dismiss(animated: true, completion: nil)
removeCoordinator(coordinator)
7 years ago
}
7 years ago
func didFail(with error: Error, in coordinator: WalletCoordinator) {
coordinator.navigationController.dismiss(animated: true, completion: nil)
removeCoordinator(coordinator)
7 years ago
}
7 years ago
func didCancel(in coordinator: WalletCoordinator) {
coordinator.navigationController.dismiss(animated: true, completion: nil)
removeCoordinator(coordinator)
7 years ago
}
}