From 1798d82bbc87144878cf350d323cb248a93e8bd7 Mon Sep 17 00:00:00 2001 From: Hwee-Boon Yar Date: Wed, 4 Jul 2018 17:16:48 +0800 Subject: [PATCH] Add token immediately upon successful import with universal link --- AlphaWallet/AppCoordinator.swift | 4 ++++ AlphaWallet/AppDelegate.swift | 4 ++++ AlphaWallet/InCoordinator.swift | 5 +++++ .../Market/Coordinators/UniversalLinkCoordinator.swift | 9 +++++++++ AlphaWallet/Tokens/Coordinators/TokensCoordinator.swift | 6 ++++++ 5 files changed, 28 insertions(+) diff --git a/AlphaWallet/AppCoordinator.swift b/AlphaWallet/AppCoordinator.swift index d5127b89a..4eecdcb19 100644 --- a/AlphaWallet/AppCoordinator.swift +++ b/AlphaWallet/AppCoordinator.swift @@ -124,6 +124,10 @@ class AppCoordinator: NSObject, Coordinator { } } + func addImported(contract: String) { + inCoordinator?.addImported(contract: contract) + } + func showInitialWalletCoordinator(entryPoint: WalletEntryPoint) { let coordinator = InitialWalletCreationCoordinator( navigationController: navigationController, diff --git a/AlphaWallet/AppDelegate.swift b/AlphaWallet/AppDelegate.swift index a4e74e6f2..f8da34737 100644 --- a/AlphaWallet/AppDelegate.swift +++ b/AlphaWallet/AppDelegate.swift @@ -108,6 +108,10 @@ extension AppDelegate: UniversalLinkCoordinatorDelegate { func completed(in coordinator: UniversalLinkCoordinator) { universalLinkCoordinator = nil } + + func didImported(contract: String, in coordinator: UniversalLinkCoordinator) { + appCoordinator.addImported(contract: contract) + } } extension AppDelegate: UniversalLinkInPasteboardCoordinatorDelegate { diff --git a/AlphaWallet/InCoordinator.swift b/AlphaWallet/InCoordinator.swift index dceaf5987..a8b0ee682 100644 --- a/AlphaWallet/InCoordinator.swift +++ b/AlphaWallet/InCoordinator.swift @@ -569,6 +569,11 @@ extension InCoordinator: TokensCoordinatorDelegate { } } } + + func addImported(contract: String) { + let tokensCoordinator = coordinators.first { $0 is TokensCoordinator } as? TokensCoordinator + tokensCoordinator?.addToken(for: contract) + } } extension InCoordinator: PaymentCoordinatorDelegate { diff --git a/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift b/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift index 1423ac9bb..6c71e4b42 100644 --- a/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift +++ b/AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift @@ -11,6 +11,7 @@ protocol UniversalLinkCoordinatorDelegate: class { func viewControllerForPresenting(in coordinator: UniversalLinkCoordinator) -> UIViewController? func completed(in coordinator: UniversalLinkCoordinator) func importPaidSignedOrder(signedOrder: SignedOrder, tokenObject: TokenObject, completion: @escaping (Bool) -> Void) + func didImported(contract: String, in coordinator: UniversalLinkCoordinator) } class UniversalLinkCoordinator: Coordinator { @@ -319,6 +320,7 @@ class UniversalLinkCoordinator: Coordinator { if self.importTicketViewController != nil { if let vc = self.importTicketViewController, var _ = vc.viewModel { if successful { + self.delegate?.didImported(contract: signedOrder.order.contractAddress, in: self) self.showImportSuccessful() } else { //TODO Pass in error message @@ -344,6 +346,9 @@ class UniversalLinkCoordinator: Coordinator { if let response = result.response { if response.statusCode < 300 { successful = true + if let contract = parameters["contractAddress"] as? String { + self.delegate?.didImported(contract: contract, in: self) + } } } @@ -382,6 +387,10 @@ extension UniversalLinkCoordinator: ImportTicketViewControllerDelegate { } func didPressImport(in viewController: ImportTicketViewController) { + if let signedOrder = viewController.signedOrder, let tokenObj = viewController.tokenObject { + self.delegate?.didImported(contract: signedOrder.order.contractAddress, in: self) + } + if let query = viewController.query, let parameters = viewController.parameters { importUniversalLink(query: query, parameters: parameters) } else { diff --git a/AlphaWallet/Tokens/Coordinators/TokensCoordinator.swift b/AlphaWallet/Tokens/Coordinators/TokensCoordinator.swift index a8f212bd1..9de9a087f 100644 --- a/AlphaWallet/Tokens/Coordinators/TokensCoordinator.swift +++ b/AlphaWallet/Tokens/Coordinators/TokensCoordinator.swift @@ -139,6 +139,12 @@ class TokensCoordinator: Coordinator { } } + func addToken(for contract: String) { + addToken(for: contract) { + self.tokensViewController.fetch() + } + } + func newTokenViewController() -> NewTokenViewController { let controller = NewTokenViewController() controller.delegate = self