Switch to new/selected account when creating or importing new account

pull/259/head
Hwee-Boon Yar 7 years ago
parent 3ed81bb83a
commit 98bf83fe0d
  1. 20
      Trust/Accounts/Coordinators/AccountsCoordinator.swift
  2. 6
      Trust/Wallet/Coordinators/WalletCoordinator.swift

@ -68,10 +68,15 @@ class AccountsCoordinator: Coordinator {
func importOrCreateWallet(entryPoint: WalletEntryPoint) { func importOrCreateWallet(entryPoint: WalletEntryPoint) {
let coordinator = WalletCoordinator(keystore: keystore) let coordinator = WalletCoordinator(keystore: keystore)
if entryPoint == .createInstantWallet {
coordinator.navigationController = navigationController
}
coordinator.delegate = self coordinator.delegate = self
addCoordinator(coordinator) addCoordinator(coordinator)
coordinator.start(entryPoint) let showUI = coordinator.start(entryPoint)
navigationController.present(coordinator.navigationController, animated: true, completion: nil) if showUI {
navigationController.present(coordinator.navigationController, animated: true, completion: nil)
}
} }
func showCreateWallet() { func showCreateWallet() {
@ -136,9 +141,14 @@ extension AccountsCoordinator: AccountsViewControllerDelegate {
extension AccountsCoordinator: WalletCoordinatorDelegate { extension AccountsCoordinator: WalletCoordinatorDelegate {
func didFinish(with account: Wallet, in coordinator: WalletCoordinator) { func didFinish(with account: Wallet, in coordinator: WalletCoordinator) {
delegate?.didAddAccount(account: account, in: self) delegate?.didAddAccount(account: account, in: self)
accountsViewController.fetch() if let delegate = delegate {
coordinator.navigationController.dismiss(animated: true, completion: nil) self.removeCoordinator(coordinator)
removeCoordinator(coordinator) self.delegate?.didSelectAccount(account: account, in: self)
} else {
accountsViewController.fetch()
coordinator.navigationController.dismiss(animated: true, completion: nil)
self.removeCoordinator(coordinator)
}
} }
func didFail(with error: Error, in coordinator: WalletCoordinator) { func didFail(with error: Error, in coordinator: WalletCoordinator) {

@ -11,7 +11,7 @@ protocol WalletCoordinatorDelegate: class {
class WalletCoordinator: Coordinator { class WalletCoordinator: Coordinator {
let navigationController: UINavigationController var navigationController: UINavigationController
weak var delegate: WalletCoordinatorDelegate? weak var delegate: WalletCoordinatorDelegate?
var entryPoint: WalletEntryPoint? var entryPoint: WalletEntryPoint?
let keystore: Keystore let keystore: Keystore
@ -26,7 +26,7 @@ class WalletCoordinator: Coordinator {
self.keystore = keystore self.keystore = keystore
} }
//Return true if proceed ///Return true if caller should proceed to show UI (`navigationController`)
func start(_ entryPoint: WalletEntryPoint) -> Bool { func start(_ entryPoint: WalletEntryPoint) -> Bool {
self.entryPoint = entryPoint self.entryPoint = entryPoint
switch entryPoint { switch entryPoint {
@ -42,6 +42,7 @@ class WalletCoordinator: Coordinator {
navigationController.viewControllers = [controller] navigationController.viewControllers = [controller]
case .createInstantWallet: case .createInstantWallet:
createInstantWallet() createInstantWallet()
return false
case .backupWallet: case .backupWallet:
if let type = keystore.recentlyUsedWallet?.type, case let .real(account) = type { if let type = keystore.recentlyUsedWallet?.type, case let .real(account) = type {
guard !Config().isWalletAddresseAlreadyPromptedForBackUp(address: account.address.eip55String) else { return false } guard !Config().isWalletAddresseAlreadyPromptedForBackUp(address: account.address.eip55String) else { return false }
@ -69,6 +70,7 @@ class WalletCoordinator: Coordinator {
let wallet = Wallet(type: WalletType.real(account)) let wallet = Wallet(type: WalletType.real(account))
self.delegate?.didFinish(with: wallet, in: self) self.delegate?.didFinish(with: wallet, in: self)
case .failure(let error): case .failure(let error):
//TODO this wouldn't work since navigationController isn't shown anymore
self.navigationController.displayError(error: error) self.navigationController.displayError(error: error)
} }
self.navigationController.hideLoading(animated: false) self.navigationController.hideLoading(animated: false)

Loading…
Cancel
Save