Extract prompt user backup wallet into a separate coordinator

pull/226/head
Hwee-Boon Yar 7 years ago
parent f47b04f653
commit 6f01dbcf78
  1. 4
      Trust.xcodeproj/project.pbxproj
  2. 52
      Trust/Export/Coordinators/PromptBackupCoordinator.swift
  3. 26
      Trust/Market/Coordinators/UniversalLinkCoordinator.swift

@ -331,6 +331,7 @@
5E7C776BE1B19F824954962D /* BaseTicketTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7F5C10E3895E805EA7E0 /* BaseTicketTableViewCell.swift */; };
5E7C776CF721EBBD43195926 /* GenerateSellMagicLinkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C79CF6150E4CD4A276FC0 /* GenerateSellMagicLinkViewController.swift */; };
5E7C7793AB6B577906F2BCA3 /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7AFE9AF9FE6B58C925D4 /* SettingsViewController.swift */; };
5E7C77A8425E0AFAB11F1FCD /* PromptBackupCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7ADD0FBE8708A6E98AF8 /* PromptBackupCoordinator.swift */; };
5E7C77AD9FAAC18211B6F355 /* TransferTicketsQuantitySelectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7419F47CC8B2996AA8F9 /* TransferTicketsQuantitySelectionViewController.swift */; };
5E7C77E844D710D7AFBC58D4 /* RequestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C74DCC21272EC231A20E2 /* RequestViewController.swift */; };
5E7C783B4784DE76971EEBB4 /* StatusViewControllerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7BD9B4BDAFC2D9EBD741 /* StatusViewControllerViewModel.swift */; };
@ -859,6 +860,7 @@
5E7C7A65F6033318F7C8AEB0 /* DateEntryField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateEntryField.swift; sourceTree = "<group>"; };
5E7C7AB3440C01136DF4F3E9 /* LockCreatePasscodeCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LockCreatePasscodeCoordinator.swift; sourceTree = "<group>"; };
5E7C7ACB94CEE493AC37487F /* TicketRowView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TicketRowView.swift; sourceTree = "<group>"; };
5E7C7ADD0FBE8708A6E98AF8 /* PromptBackupCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PromptBackupCoordinator.swift; sourceTree = "<group>"; };
5E7C7AE6FAE0DF969B4F52E9 /* ContactUsBannerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactUsBannerView.swift; sourceTree = "<group>"; };
5E7C7AF9A592D7224ED58016 /* OnboardingPageStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OnboardingPageStyle.swift; sourceTree = "<group>"; };
5E7C7AFE9AF9FE6B58C925D4 /* SettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; };
@ -1491,6 +1493,7 @@
isa = PBXGroup;
children = (
29DBF2A21F9DBFF400327C60 /* BackupCoordinator.swift */,
5E7C7ADD0FBE8708A6E98AF8 /* PromptBackupCoordinator.swift */,
);
path = Coordinators;
sourceTree = "<group>";
@ -3592,6 +3595,7 @@
5E7C75E5C64619ABFD246183 /* TransferTicketsViaWalletAddressViewController.swift in Sources */,
5E7C7EAEBB435F3909DA36FB /* TransferTicketsViaWalletAddressViewControllerViewModel.swift in Sources */,
5E7C7CCC8D376C6E5C245715 /* EthCurrencyHelper.swift in Sources */,
5E7C77A8425E0AFAB11F1FCD /* PromptBackupCoordinator.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

@ -0,0 +1,52 @@
// Copyright © 2018 Stormbird PTE. LTD.
import UIKit
protocol PromptBackupCoordinatorDelegate: class {
func viewControllerForPresenting(in coordinator: PromptBackupCoordinator) -> UIViewController?
func didFinish(in coordinator: PromptBackupCoordinator)
}
class PromptBackupCoordinator: Coordinator {
var coordinators: [Coordinator] = []
weak var delegate: PromptBackupCoordinatorDelegate?
func start() {
let keystore = try! EtherKeystore()
let coordinator = WalletCoordinator(keystore: keystore)
coordinator.delegate = self
let proceed = coordinator.start(.backupWallet)
guard proceed else {
finish()
return
}
if let vc = delegate?.viewControllerForPresenting(in: self) {
vc.present(coordinator.navigationController, animated: true, completion: nil)
}
addCoordinator(coordinator)
}
func finish() {
delegate?.didFinish(in: self)
}
}
extension PromptBackupCoordinator: WalletCoordinatorDelegate {
func didFinish(with account: Wallet, in coordinator: WalletCoordinator) {
coordinator.navigationController.dismiss(animated: true, completion: nil)
removeCoordinator(coordinator)
finish()
}
func didFail(with error: Error, in coordinator: WalletCoordinator) {
coordinator.navigationController.dismiss(animated: true, completion: nil)
removeCoordinator(coordinator)
finish()
}
func didCancel(in coordinator: WalletCoordinator) {
coordinator.navigationController.dismiss(animated: true, completion: nil)
removeCoordinator(coordinator)
finish()
}
}

@ -265,15 +265,10 @@ class UniversalLinkCoordinator: Coordinator {
}
private func promptBackupWallet() {
let keystore = try! EtherKeystore()
let coordinator = WalletCoordinator(keystore: keystore)
coordinator.delegate = self
let proceed = coordinator.start(.backupWallet)
guard proceed else { return }
if let vc = delegate?.viewControllerForPresenting(in: self) {
vc.present(coordinator.navigationController, animated: true, completion: nil)
}
let coordinator = PromptBackupCoordinator()
addCoordinator(coordinator)
coordinator.delegate = self
coordinator.start()
}
private func showImportError(errorMessage: String) {
@ -331,19 +326,12 @@ extension UniversalLinkCoordinator: ImportTicketViewControllerDelegate {
}
}
extension UniversalLinkCoordinator: WalletCoordinatorDelegate {
func didFinish(with account: Wallet, in coordinator: WalletCoordinator) {
coordinator.navigationController.dismiss(animated: true, completion: nil)
removeCoordinator(coordinator)
}
func didFail(with error: Error, in coordinator: WalletCoordinator) {
coordinator.navigationController.dismiss(animated: true, completion: nil)
removeCoordinator(coordinator)
extension UniversalLinkCoordinator: PromptBackupCoordinatorDelegate {
func viewControllerForPresenting(in coordinator: PromptBackupCoordinator) -> UIViewController? {
return delegate?.viewControllerForPresenting(in: self)
}
func didCancel(in coordinator: WalletCoordinator) {
coordinator.navigationController.dismiss(animated: true, completion: nil)
func didFinish(in coordinator: PromptBackupCoordinator) {
removeCoordinator(coordinator)
}
}

Loading…
Cancel
Save