From eb22260b4481c85be2a2a226474645f199fa5c66 Mon Sep 17 00:00:00 2001 From: Michael Scoff Date: Tue, 31 Oct 2017 11:24:41 -0700 Subject: [PATCH] Remove lazy loading for settings coordinator Adding extra tests --- .../Coordinators/TransactionCoordinator.swift | 21 +++++++++---------- .../TransactionCoordinatorTests.swift | 4 ++++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Trust/Transactions/Coordinators/TransactionCoordinator.swift b/Trust/Transactions/Coordinators/TransactionCoordinator.swift index 7072f3810..d988bb6fb 100644 --- a/Trust/Transactions/Coordinators/TransactionCoordinator.swift +++ b/Trust/Transactions/Coordinators/TransactionCoordinator.swift @@ -14,9 +14,8 @@ class TransactionCoordinator: Coordinator { private let keystore: Keystore let storage: TransactionsStorage - lazy var rootViewController: TransactionsViewController = { - let controller = self.makeTransactionsController(with: self.session.account) - return controller + lazy var transactionsViewController: TransactionsViewController = { + return self.makeTransactionsController(with: self.session.account) }() lazy var dataCoordinator: TransactionDataCoordinator = { @@ -29,10 +28,6 @@ class TransactionCoordinator: Coordinator { weak var delegate: TransactionCoordinatorDelegate? - lazy var settingsCoordinator: SettingsCoordinator = { - return SettingsCoordinator() - }() - let session: WalletSession let navigationController: UINavigationController var coordinators: [Coordinator] = [] @@ -63,9 +58,11 @@ class TransactionCoordinator: Coordinator { } @objc func showSettings() { - settingsCoordinator.start() - settingsCoordinator.delegate = self - navigationController.present(settingsCoordinator.navigationController, animated: true, completion: nil) + let coordinator = SettingsCoordinator() + coordinator.start() + coordinator.delegate = self + addCoordinator(coordinator) + navigationController.present(coordinator.navigationController, animated: true, completion: nil) } func showTokens(for account: Account) { @@ -111,7 +108,7 @@ class TransactionCoordinator: Coordinator { } @objc func didEnterForeground() { - rootViewController.fetch() + transactionsViewController.fetch() } @objc func dismiss() { @@ -143,6 +140,7 @@ class TransactionCoordinator: Coordinator { extension TransactionCoordinator: SettingsCoordinatorDelegate { func didUpdate(action: SettingsAction, in coordinator: SettingsCoordinator) { + removeCoordinator(coordinator) switch action { case .RPCServer: restart(for: session.account) @@ -156,6 +154,7 @@ extension TransactionCoordinator: SettingsCoordinatorDelegate { } func didCancel(in coordinator: SettingsCoordinator) { + removeCoordinator(coordinator) coordinator.navigationController.dismiss(animated: true, completion: nil) } } diff --git a/TrustTests/Coordinators/TransactionCoordinatorTests.swift b/TrustTests/Coordinators/TransactionCoordinatorTests.swift index 5c74593ab..6e224de1f 100644 --- a/TrustTests/Coordinators/TransactionCoordinatorTests.swift +++ b/TrustTests/Coordinators/TransactionCoordinatorTests.swift @@ -26,6 +26,7 @@ class TransactionCoordinatorTests: XCTestCase { coordinator.showSettings() + XCTAssertTrue(coordinator.coordinators.first is SettingsCoordinator) XCTAssertTrue((coordinator.navigationController.presentedViewController as? UINavigationController)?.viewControllers[0] is SettingsViewController) } @@ -40,6 +41,7 @@ class TransactionCoordinatorTests: XCTestCase { let controller = (coordinator.navigationController.presentedViewController as? UINavigationController)?.viewControllers[0] + XCTAssertTrue(coordinator.coordinators.first is PaymentCoordinator) XCTAssertTrue(controller is SendViewController) } @@ -54,6 +56,7 @@ class TransactionCoordinatorTests: XCTestCase { let controller = (coordinator.navigationController.presentedViewController as? UINavigationController)?.viewControllers[0] + XCTAssertTrue(coordinator.coordinators.first is PaymentCoordinator) XCTAssertTrue(controller is RequestViewController) } @@ -66,6 +69,7 @@ class TransactionCoordinatorTests: XCTestCase { coordinator.showAccounts() + XCTAssertTrue(coordinator.coordinators.first is AccountsCoordinator) XCTAssertTrue((coordinator.navigationController.presentedViewController as? UINavigationController)?.viewControllers[0] is AccountsViewController) } }