Push target view controller for payments coordinator to appropriate navigation view controller #2785

pull/2786/head
Vladyslav shepitko 3 years ago
parent 78d924e117
commit 48c7614ed7
  1. 2
      AlphaWallet/AppCoordinator.swift
  2. 15
      AlphaWallet/InCoordinator.swift
  3. 22
      AlphaWallet/Transfer/Coordinators/PaymentCoordinator.swift
  4. 2
      AlphaWallet/Transfer/Coordinators/RequestCoordinator.swift
  5. 3
      AlphaWallet/Transfer/Coordinators/SendCoordinator.swift
  6. 4
      AlphaWalletTests/Coordinators/InCoordinatorTests.swift

@ -366,7 +366,7 @@ extension AppCoordinator: UniversalLinkInPasteboardCoordinatorDelegate {
extension AppCoordinator: CustomUrlSchemeCoordinatorResolver {
func openSendPaymentFlow(_ paymentFlow: PaymentFlow, server: RPCServer, inCoordinator coordinator: CustomUrlSchemeCoordinator) {
inCoordinator?.showPaymentFlow(for: paymentFlow, server: server)
inCoordinator?.showPaymentFlow(for: paymentFlow, server: server, navigationController: navigationController)
}
}

@ -597,7 +597,7 @@ class InCoordinator: NSObject, Coordinator {
addCoordinator(deviceChecker)
}
func showPaymentFlow(for type: PaymentFlow, server: RPCServer) {
func showPaymentFlow(for type: PaymentFlow, server: RPCServer, navigationController: UINavigationController) {
let session = walletSessions[server]
let tokenStorage = tokensStorages[server]
@ -819,7 +819,7 @@ extension InCoordinator: SettingsCoordinatorDelegate {
func didPressShowWallet(in coordinator: SettingsCoordinator) {
//We are only showing the QR code and some text for this address. Maybe have to rework graphic design so that server isn't necessary
showPaymentFlow(for: .request, server: config.anyEnabledServer())
showPaymentFlow(for: .request, server: config.anyEnabledServer(), navigationController: coordinator.navigationController)
delegate?.didShowWallet(in: self)
}
@ -888,7 +888,7 @@ extension InCoordinator: TokensCoordinatorDelegate {
}
func didPress(for type: PaymentFlow, server: RPCServer, in coordinator: TokensCoordinator) {
showPaymentFlow(for: type, server: server)
showPaymentFlow(for: type, server: server, navigationController: coordinator.navigationController)
}
func didTap(transaction: TransactionInstance, inViewController viewController: UIViewController, in coordinator: TokensCoordinator) {
@ -911,12 +911,12 @@ extension InCoordinator: TokensCoordinatorDelegate {
extension InCoordinator: PaymentCoordinatorDelegate {
func didFinish(_ result: ConfirmResult, in coordinator: PaymentCoordinator) {
removeCoordinator(coordinator)
switch result {
case .sentTransaction(let transaction):
handlePendingTransaction(transaction: transaction)
coordinator.navigationController.setNavigationBarHidden(true, animated: false)
coordinator.navigationController.popToRootViewController(animated: true)
coordinator.dismiss(animated: false)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) {
self.showTransactionSent(transaction: transaction)
@ -927,8 +927,7 @@ extension InCoordinator: PaymentCoordinatorDelegate {
}
func didCancel(in coordinator: PaymentCoordinator) {
coordinator.navigationController.setNavigationBarHidden(true, animated: false)
coordinator.navigationController.popToRootViewController(animated: true)
coordinator.dismiss(animated: true)
removeCoordinator(coordinator)
}
@ -1081,4 +1080,4 @@ extension InCoordinator: TokensDataStorePriceDelegate {
fetchTokenPrices()
}
}
// swiftlint:enable file_length
// swiftlint:enable file_length

@ -22,6 +22,9 @@ class PaymentCoordinator: Coordinator {
var coordinators: [Coordinator] = []
let navigationController: UINavigationController
private var shouldRestoreNavigationBarIsHiddenState: Bool
private var latestNavigationStackViewController: UIViewController?
init(
navigationController: UINavigationController,
flow: PaymentFlow,
@ -42,9 +45,16 @@ class PaymentCoordinator: Coordinator {
self.tokenHolders = tokenHolders
self.assetDefinitionStore = assetDefinitionStore
self.analyticsCoordinator = analyticsCoordinator
shouldRestoreNavigationBarIsHiddenState = navigationController.navigationBar.isHidden
latestNavigationStackViewController = navigationController.viewControllers.last
}
func start() {
if shouldRestoreNavigationBarIsHiddenState {
self.navigationController.setNavigationBarHidden(false, animated: true)
}
switch (flow, session.account.type) {
case (.send(let type), .real(let account)):
let coordinator = SendCoordinator(
@ -80,6 +90,18 @@ class PaymentCoordinator: Coordinator {
func cancel() {
delegate?.didCancel(in: self)
}
func dismiss(animated: Bool) {
if shouldRestoreNavigationBarIsHiddenState {
navigationController.setNavigationBarHidden(true, animated: animated)
}
if let viewController = latestNavigationStackViewController {
navigationController.popToViewController(viewController, animated: animated)
} else {
navigationController.popToRootViewController(animated: animated)
}
}
}
extension PaymentCoordinator: SendCoordinatorDelegate {

@ -13,6 +13,7 @@ class RequestCoordinator: Coordinator {
private lazy var requestViewController: RequestViewController = {
let viewModel: RequestViewModel = .init(account: account)
let controller = RequestViewController(viewModel: viewModel)
controller.navigationItem.largeTitleDisplayMode = .never
controller.navigationItem.leftBarButtonItem = UIBarButtonItem.backBarButton(self, selector: #selector(dismiss))
return controller
@ -24,7 +25,6 @@ class RequestCoordinator: Coordinator {
init(navigationController: UINavigationController, account: Wallet) {
self.navigationController = navigationController
self.navigationController.setNavigationBarHidden(false, animated: true)
self.account = account
}

@ -52,8 +52,7 @@ class SendCoordinator: Coordinator {
self.ethPrice = ethPrice
self.tokenHolders = tokenHolders
self.assetDefinitionStore = assetDefinitionStore
self.analyticsCoordinator = analyticsCoordinator
self.navigationController.setNavigationBarHidden(false, animated: true)
self.analyticsCoordinator = analyticsCoordinator
}
func start() {

@ -90,7 +90,7 @@ class InCoordinatorTests: XCTestCase {
)
coordinator.showTabBar(for: .make())
coordinator.showPaymentFlow(for: .send(type: .nativeCryptocurrency(TokenObject(), destination: .none, amount: nil)), server: .main)
coordinator.showPaymentFlow(for: .send(type: .nativeCryptocurrency(TokenObject(), destination: .none, amount: nil)), server: .main, navigationController: coordinator.navigationController)
XCTAssertTrue(coordinator.coordinators.last is PaymentCoordinator)
XCTAssertTrue(coordinator.navigationController.viewControllers.last is SendViewController)
@ -109,7 +109,7 @@ class InCoordinatorTests: XCTestCase {
)
coordinator.showTabBar(for: .make())
coordinator.showPaymentFlow(for: .request, server: .main)
coordinator.showPaymentFlow(for: .request, server: .main, navigationController: coordinator.navigationController)
XCTAssertTrue(coordinator.coordinators.last is PaymentCoordinator)
XCTAssertTrue(coordinator.navigationController.viewControllers.last is RequestViewController)

Loading…
Cancel
Save