blockchainethereumblockchain-walleterc20erc721walletxdaidappdecentralizederc1155erc875iosswifttokens
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.
101 lines
3.3 KiB
101 lines
3.3 KiB
// Copyright SIX DAY LLC. All rights reserved.
|
|
|
|
import Foundation
|
|
import UIKit
|
|
|
|
protocol InCoordinatorDelegate: class {
|
|
func didCancel(in coordinator: InCoordinator)
|
|
func didUpdateAccounts(in coordinator: InCoordinator)
|
|
}
|
|
|
|
class InCoordinator: Coordinator {
|
|
|
|
let navigationController: UINavigationController
|
|
var coordinators: [Coordinator] = []
|
|
let account: Account
|
|
var keystore: Keystore
|
|
let config = Config()
|
|
weak var delegate: InCoordinatorDelegate?
|
|
|
|
init(
|
|
navigationController: UINavigationController = NavigationController(),
|
|
account: Account,
|
|
keystore: Keystore
|
|
) {
|
|
self.navigationController = navigationController
|
|
self.account = account
|
|
self.keystore = keystore
|
|
}
|
|
|
|
func start() {
|
|
showTabBar(for: account)
|
|
}
|
|
|
|
func showTabBar(for account: Account) {
|
|
let session = WalletSession(
|
|
account: account,
|
|
config: config
|
|
)
|
|
let transactionCoordinator = TransactionCoordinator(
|
|
session: session,
|
|
storage: TransactionsStorage(
|
|
current: account,
|
|
chainID: config.chainID
|
|
),
|
|
keystore: keystore
|
|
)
|
|
transactionCoordinator.rootViewController.tabBarItem = UITabBarItem(title: "Transactions", image: R.image.feed(), selectedImage: nil)
|
|
transactionCoordinator.delegate = self
|
|
transactionCoordinator.start()
|
|
addCoordinator(transactionCoordinator)
|
|
|
|
let tokenCoordinator = TokensCoordinator(
|
|
session: session
|
|
)
|
|
tokenCoordinator.rootViewController.tabBarItem = UITabBarItem(title: "Tokens", image: R.image.coins(), selectedImage: nil)
|
|
tokenCoordinator.start()
|
|
addCoordinator(tokenCoordinator)
|
|
|
|
let tabBarController = UITabBarController()
|
|
tabBarController.viewControllers = [
|
|
transactionCoordinator.navigationController,
|
|
tokenCoordinator.navigationController,
|
|
]
|
|
|
|
if isDebug {
|
|
let exchangeCoordinator = ExchangeCoordinator()
|
|
exchangeCoordinator.rootViewController.tabBarItem = UITabBarItem(title: "Exchange", image: R.image.exchange(), selectedImage: nil)
|
|
exchangeCoordinator.start()
|
|
tabBarController.viewControllers?.append(exchangeCoordinator.navigationController)
|
|
}
|
|
|
|
navigationController.setViewControllers(
|
|
[tabBarController],
|
|
animated: false
|
|
)
|
|
navigationController.setNavigationBarHidden(true, animated: false)
|
|
addCoordinator(transactionCoordinator)
|
|
|
|
keystore.recentlyUsedAccount = account
|
|
}
|
|
}
|
|
|
|
extension InCoordinator: TransactionCoordinatorDelegate {
|
|
func didCancel(in coordinator: TransactionCoordinator) {
|
|
delegate?.didCancel(in: self)
|
|
coordinator.navigationController.dismiss(animated: true, completion: nil)
|
|
coordinator.stop()
|
|
removeAllCoordinators()
|
|
}
|
|
|
|
func didRestart(with account: Account, in coordinator: TransactionCoordinator) {
|
|
coordinator.navigationController.dismiss(animated: true, completion: nil)
|
|
coordinator.stop()
|
|
removeCoordinator(coordinator)
|
|
showTabBar(for: account)
|
|
}
|
|
|
|
func didUpdateAccounts(in coordinator: TransactionCoordinator) {
|
|
delegate?.didUpdateAccounts(in: self)
|
|
}
|
|
}
|
|
|