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/AppCoordinator.swift

140 lines
4.1 KiB

// Copyright SIX DAY LLC. All rights reserved.
7 years ago
import Foundation
import UIKit
class AppCoordinator: NSObject, Coordinator {
let navigationController: UINavigationController
7 years ago
lazy var welcomeViewController: WelcomeViewController = {
let controller = WelcomeViewController()
controller.delegate = self
return controller
7 years ago
}()
lazy var touchRegistrar: TouchRegistrar = {
return TouchRegistrar(keystore: self.keystore)
}()
let pushNotificationRegistrar = PushNotificationsRegistrar()
private var keystore: Keystore
var coordinators: [Coordinator] = []
init(
window: UIWindow,
keystore: Keystore = EtherKeystore(),
navigationController: UINavigationController = NavigationController()
) {
self.keystore = keystore
self.navigationController = navigationController
super.init()
window.rootViewController = navigationController
window.makeKeyAndVisible()
7 years ago
}
7 years ago
func start() {
performMigration()
inializers()
handleNotifications()
applyStyle()
resetToWelcomeScreen()
7 years ago
if keystore.hasAccounts {
showTransactions(for: keystore.recentlyUsedAccount ?? keystore.accounts.first!)
7 years ago
}
pushNotificationRegistrar.reRegister()
7 years ago
}
func showTransactions(for account: Account) {
let coordinator = InCoordinator(
navigationController: navigationController,
account: account,
keystore: keystore
)
coordinator.delegate = self
coordinator.start()
addCoordinator(coordinator)
}
func performMigration() {
MigrationInitializer().perform()
LokaliseInitializer().perform()
}
func inializers() {
touchRegistrar.register()
}
func handleNotifications() {
UIApplication.shared.applicationIconBadgeNumber = 0
}
func resetToWelcomeScreen() {
navigationController.setNavigationBarHidden(true, animated: false)
navigationController.viewControllers = [welcomeViewController]
7 years ago
}
7 years ago
@objc func reset() {
touchRegistrar.unregister()
pushNotificationRegistrar.unregister()
coordinators.removeAll()
navigationController.dismiss(animated: true, completion: nil)
resetToWelcomeScreen()
7 years ago
}
func didRegisterForRemoteNotificationsWithDeviceToken(deviceToken: Data) {
pushNotificationRegistrar.didRegister(
with: deviceToken,
addresses: keystore.accounts.map { $0.address }
)
}
func showInitialWalletCoordinator(entryPoint: WalletEntryPoint) {
let coordinator = InitialWalletCreationCoordinator(
navigationController: navigationController,
entryPoint: entryPoint
)
coordinator.delegate = self
coordinator.start()
addCoordinator(coordinator)
}
7 years ago
}
extension AppCoordinator: WelcomeViewControllerDelegate {
func didPressCreateWallet(in viewController: WelcomeViewController) {
showInitialWalletCoordinator(entryPoint: .createInstantWallet)
}
func didPressImportWallet(in viewController: WelcomeViewController) {
showInitialWalletCoordinator(entryPoint: .importWallet)
7 years ago
}
}
extension AppCoordinator: InitialWalletCreationCoordinatorDelegate {
func didCancel(in coordinator: InitialWalletCreationCoordinator) {
coordinator.navigationController.dismiss(animated: true, completion: nil)
removeCoordinator(coordinator)
7 years ago
}
func didAddAccount(_ account: Account, in coordinator: InitialWalletCreationCoordinator) {
coordinator.navigationController.dismiss(animated: true, completion: nil)
removeCoordinator(coordinator)
showTransactions(for: account)
7 years ago
}
}
extension AppCoordinator: InCoordinatorDelegate {
func didCancel(in coordinator: InCoordinator) {
removeCoordinator(coordinator)
pushNotificationRegistrar.reRegister()
reset()
}
func didUpdateAccounts(in coordinator: InCoordinator) {
pushNotificationRegistrar.reRegister()
}
}