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.

147 lines
3.9 KiB

  1. //
  2. // PennyTestViewController.swift
  3. // GME Remit
  4. //
  5. // Created by Mac on 11/27/18.
  6. //Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class PennyTestViewController: UIViewController {
  10. struct StringConstants {
  11. let proceedText = "proceed_text".localized()
  12. let notNowText = "not_now_text".localized()
  13. }
  14. // MARK: Properties
  15. var presenter: PennyTestModuleInterface?
  16. var model: KYCResponse?
  17. var backGroundView: UIView?
  18. // MARK: IBOutlets
  19. @IBOutlet weak var dismissButton: UIButton!
  20. @IBOutlet weak var iconImageView: UIImageView!
  21. @IBOutlet weak var infoLabel: UILabel!
  22. @IBOutlet weak var proceedButton: UIButton!
  23. // MARK: VC's Life cycle
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. NotificationCenter.default.addObserver(
  27. self,
  28. selector: #selector(self.closePennyTest(sender:)),
  29. name: NSNotification.Name.init("closePennyTest"),
  30. object: nil
  31. )
  32. self.setup()
  33. }
  34. @objc private func closePennyTest(sender: Notification) {
  35. self.dismiss(animated: true, completion: nil)
  36. }
  37. override func viewWillAppear(_ animated: Bool) {
  38. super.viewWillAppear(animated)
  39. GMEDB.shared.user.set(true, .pennyTestPresentedOnce)
  40. self.navigationItem.title = "penny_test_title_text".localized()
  41. self.setupNormalNavigation()
  42. self.navigationItem.hidesBackButton = true
  43. }
  44. override func viewWillDisappear(_ animated: Bool) {
  45. super.viewWillDisappear(animated)
  46. self.navigationItem.title = ""
  47. GMEDB.shared.user.set(true, .pennyTestPresentedOnce)
  48. }
  49. // MARK: IBActions
  50. // MARK: Other Functions
  51. private func setup() {
  52. // all setup should be done here
  53. self.setupNormalNavigation()
  54. self.proceedButton.layer.cornerRadius = 5
  55. iconImageView.rounded()
  56. iconImageView.layer.borderColor = UIColor.themeRed.cgColor
  57. iconImageView.layer.borderWidth = 2
  58. iconImageView.layer.contentsScale = UIScreen.main.scale
  59. if let view = self.backGroundView {
  60. view.frame = self.view.frame
  61. self.view.addSubview(view)
  62. }
  63. GMEDB.shared.user.set(true, .pennyTestPresentedOnce)
  64. configureText()
  65. }
  66. private func configureText() {
  67. self.proceedButton.setTitle(StringConstants().proceedText, for: UIControl.State.normal)
  68. self.dismissButton.setTitle(StringConstants().notNowText, for: UIControl.State.normal)
  69. // penny_test_promt_description_text
  70. infoLabel.text = "penny_test_promt_description_text".localized()
  71. }
  72. @IBAction func proceed(_ sender: UIButton) {
  73. self.proceed()
  74. }
  75. @IBAction func dismiss(_ sender: UIButton) {
  76. self.updatePennyTestCancelledStatus()
  77. self.dismiss(animated: true, completion: nil)
  78. }
  79. private func proceed() {
  80. let userId = Utility.getMyUserName()
  81. self.showLoading()
  82. self.initiate(
  83. userId: userId,
  84. isResendRequest: "N",
  85. success: { result in
  86. self.hideLoading()
  87. GMEDB.shared.user.set(result.message, .pennyTestServerMessage)
  88. self.updatePennyTestRequestStatus()
  89. let wireframe = PennyTestSubmitWireframe()
  90. if let navigation = self.navigationController {
  91. wireframe.parentViewController = self
  92. wireframe.pushMainView(in: navigation)
  93. }
  94. },
  95. failure: { (error) in
  96. self.hideLoading()
  97. self.alert(type: .error, message: error.localizedDescription)
  98. }
  99. )
  100. }
  101. private func updatePennyTestRequestStatus() {
  102. GMEDB.shared.user.set(PennyTestStatusCode.requested.rawValue, .pennyTestStatusCode)
  103. }
  104. private func updatePennyTestCancelledStatus() {
  105. GMEDB.shared.user.set(PennyTestStatusCode.cancelled.rawValue, .pennyTestStatusCode)
  106. }
  107. func showLoading() {
  108. self.showProgressHud()
  109. }
  110. func hideLoading() {
  111. self.hideProgressHud()
  112. }
  113. }
  114. // MARK: PennyTestViewInterface
  115. extension PennyTestViewController: PennyTestViewInterface {
  116. }
  117. extension PennyTestViewController: InitiatePennyTestService {
  118. }