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.

190 lines
5.6 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. //
  2. // DomesticRemitWireframe.swift
  3. // GME Remit
  4. //
  5. // Created by InKwon James Kim on 17/09/2019.
  6. //Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class DomesticRemitWireframe {
  10. weak var view: UIViewController!
  11. weak var output: DomesticRemitWireframeOutput?
  12. private var model: DomesticRemitRequestModel?
  13. }
  14. extension DomesticRemitWireframe: DomesticRemitWireframeInput {
  15. var storyboardName: String {return "DomesticRemit"}
  16. func getMainView() -> UIViewController {
  17. let service = DomesticRemitService()
  18. let interactor = DomesticRemitInteractor(service: service)
  19. let presenter = DomesticRemitPresenter()
  20. let viewModel = DomesticRemitViewModel()
  21. let viewController = viewControllerFromStoryboard(of: DomesticRemitViewController.self)
  22. output = presenter
  23. viewController.viewModel = viewModel
  24. interactor.output = presenter
  25. presenter.interactor = interactor
  26. presenter.wireframe = self
  27. presenter.viewModel = viewModel
  28. viewModel.presenter = presenter
  29. view = viewController
  30. return viewController
  31. }
  32. func open(on source: UIViewController) {
  33. let vc = getMainView()
  34. source.navigationController?.pushViewController(vc, animated: true)
  35. }
  36. func showTablePresenter(with model: [TablePresenterProtocol]?, type: DomesticRemitPresenter.ShowType) {
  37. TablePresenterWireframe().openWith(
  38. tag: type.rawValue,
  39. delegate: self,
  40. model: model,
  41. source: view
  42. )
  43. }
  44. func showPaymentMode(with model: [Account]?) {
  45. let wireframe = SelectPaymentWireframe()
  46. wireframe.delegate = self
  47. wireframe.openSelectPaymentUsingPanModal(with: model, in: view)
  48. }
  49. func showRecentHistories() {
  50. RecentHistoriesWireframe().open(delegate: self, on: view)
  51. }
  52. func showBiometricAuth(with model: DomesticRemitRequestModel?) {
  53. self.model = model
  54. BiometricAuthenticationWireframe().openWithDelegate(on: view, delegate: self)
  55. }
  56. func showOTP(with model: DomesticRemitRequestModel?) {
  57. self.model = model
  58. SendMoneyCodeWireframe().open(
  59. requestmodel: model,
  60. completion: { self.output?.setPassword($0) },
  61. source: view
  62. )
  63. }
  64. func showSecureKeypad(with model: DomesticRemitRequestModel?) {
  65. self.model = model
  66. let secureKeypad = SecureKeypad(target: view)
  67. secureKeypad.delegate = self
  68. secureKeypad.present(animated: true)
  69. }
  70. func goReceipt(with model: DomesticRemitResponseModel) {
  71. if let navigation = self.view.navigationController {
  72. SendMoneyReceiptWireframe().openReciept(
  73. type: .domestic,
  74. transactionId: model.transactionID ?? "",
  75. source: navigation
  76. )
  77. }
  78. }
  79. }
  80. extension DomesticRemitWireframe: TablePresenterDelegate {
  81. func tablePresenterView(_ viewController: TablePresenterViewController) -> TablePresenterConfiguration {
  82. return TablePresenterConfiguration(
  83. presenterTitle: "select_bank_text".localized(),
  84. closeButtonTitle: "penny_test_close_text".localized(),
  85. notFoundTitle: "no_bank_found_text".localized(),
  86. searchBarPlaceHolder: "search_bank_text".localized(),
  87. isUseSearchBar: false
  88. )
  89. }
  90. func tablePresenterView(
  91. _ viewController: TablePresenterViewController,
  92. didSelectModel model: TablePresenterProtocol?
  93. ) {
  94. guard let type = DomesticRemitPresenter.ShowType(rawValue: viewController.view.tag) else { return }
  95. output?.selectedData(with: model, type: type)
  96. }
  97. }
  98. extension DomesticRemitWireframe: RecentHistoriesDelegate {
  99. func recentHistories(
  100. _ viewController: RecentHistoriesViewController,
  101. didSelectHistory: RecentRecipientModel
  102. ) {
  103. output?.selectedData(with: didSelectHistory, type: .histories)
  104. }
  105. }
  106. extension DomesticRemitWireframe: BiometricAuthenticationViewControllerDelegate {
  107. func viewController(
  108. _ viewController: BiometricAuthenticationViewController,
  109. informationTitleLabel titleLabel: UILabel,
  110. authenticationButton button: UIButton) {
  111. titleLabel.text = "bio_sendmoney_intro_text".localized()
  112. button.setTitle("send_money_text".localized(), for: .normal)
  113. }
  114. func didComplete(_ viewController: BiometricAuthenticationViewController) {
  115. viewController.dismiss(animated: true) {
  116. guard let encryptedPW = KeyChain.shared.get(key: .password) else {
  117. MainWireframe.logoutWarningAlert(message: "To use biometrics authentication you have to login again.")
  118. return
  119. }
  120. self.output?.setPassword(encryptedPW)
  121. }
  122. }
  123. func viewController(
  124. _ viewController: BiometricAuthenticationViewController,
  125. didFailWithError error: BiometricAuthenticationError,
  126. errorMessage: String?
  127. ) {
  128. viewController.dismiss(animated: true) {
  129. switch error {
  130. case .userFallback:
  131. if self.model?.type == "autodebit" {
  132. self.showOTP(with: self.model)
  133. } else {
  134. self.showSecureKeypad(with: self.model)
  135. }
  136. case .biometryNotEnrolled, .notBeConfigured, .biometryNotAvailable:
  137. self.view.alert(type: .error, message: error.message)
  138. default:
  139. break
  140. }
  141. }
  142. }
  143. }
  144. extension DomesticRemitWireframe: SelectPaymentDelegate {
  145. func selectPayment(_ viewController: SelectPaymentViewController, selectedAccount: Account) {
  146. viewController.dismiss(animated: true) {
  147. self.output?.selectedData(with: selectedAccount, type: .autodebit)
  148. }
  149. }
  150. func selectPayment(_ viewController: SelectPaymentViewController, error: Error) {
  151. }
  152. }
  153. extension DomesticRemitWireframe: SecureKeypadDelegate {
  154. func didComplete(_ encryptedString: String, garbagePassword: String, length: Int) {
  155. if length > 0 {
  156. self.output?.setPassword(encryptedString)
  157. }
  158. }
  159. }