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.

174 lines
5.8 KiB

  1. //
  2. // WithdrawFromWalletDetailViewController.swift
  3. // GME Remit
  4. //
  5. // Created by Amrit Giri on 7/6/20.
  6. //Copyright © 2020 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class WithdrawFromWalletDetailViewController: UIViewController {
  10. struct StringConstants {
  11. let titleText = "bank_deposit_text".localized()
  12. let descText = "bank_deposit_detail_text".localized()
  13. let bankText = "bank_text".localized()
  14. let accountNumberText = "account_number_text".localized()
  15. let amountText = "amount_text".localized()
  16. let serviceChargeText = "service_charge_text".localized()
  17. let confirmText = "confirm_text".localized()
  18. }
  19. // MARK: Properties
  20. var presenter: WithdrawFromWalletDetailModuleInterface?
  21. var password: String = ""{
  22. didSet{
  23. if password != ""{
  24. self.presenter?.makeApiRequest(password: self.password)
  25. }
  26. }
  27. }
  28. // MARK: IBOutlets
  29. @IBOutlet private weak var confirmBtn: UIButton!
  30. @IBOutlet private weak var desc: UILabel!
  31. @IBOutlet private weak var bankTitleLabel: UILabel!
  32. @IBOutlet private weak var bankContentLabel: UILabel!
  33. @IBOutlet private weak var acNumberTitleLabel: UILabel!
  34. @IBOutlet private weak var acNumberContentLabel: UILabel!
  35. @IBOutlet private weak var amountTitleLabel: UILabel!
  36. @IBOutlet private weak var amountContentLabel: UILabel!
  37. @IBOutlet private weak var serviceChargeTitleLabel: UILabel!
  38. @IBOutlet private weak var serviceChargeContentLabel: UILabel!
  39. // MARK: VC's Life cycle
  40. override func viewDidLoad() {
  41. super.viewDidLoad()
  42. self.setup()
  43. self.presenter?.fetchModel()
  44. }
  45. override func viewWillAppear(_ animated: Bool) {
  46. super.viewWillAppear(animated)
  47. self.title = StringConstants().titleText
  48. self.setupNormalNavigation()
  49. }
  50. // MARK: IBActions
  51. @IBAction func confirm(_ sender: Any) {
  52. if let isUseBiometric = KeyChain.shared.get(key: .biometricAuth), isUseBiometric == "1" {
  53. let biometricAuthenticationWireframe = BiometricAuthenticationWireframe()
  54. biometricAuthenticationWireframe.openWithDelegate(on: self, delegate: self)
  55. } else {
  56. showSecureKeyPad()
  57. }
  58. }
  59. // MARK: Other Functions
  60. private func setup() {
  61. // all setup should be done here
  62. self.configureLanguage()
  63. }
  64. private func configureLanguage() {
  65. desc.text = StringConstants().descText
  66. bankTitleLabel.text = StringConstants().bankText
  67. acNumberTitleLabel.text = StringConstants().accountNumberText
  68. amountTitleLabel.text = StringConstants().amountText
  69. serviceChargeTitleLabel.text = StringConstants().serviceChargeText
  70. confirmBtn.setTitle(StringConstants().confirmText, for: .normal)
  71. }
  72. private func showSecureKeyPad() {
  73. self.openPasswordInput { (value) in
  74. self.password = value
  75. }
  76. }
  77. }
  78. // MARK: WithdrawFromWalletDetailViewInterface
  79. extension WithdrawFromWalletDetailViewController: WithdrawFromWalletDetailViewInterface {
  80. func showLoading() {
  81. self.showProgressHud()
  82. }
  83. func hideLoading() {
  84. self.hideProgressHud()
  85. }
  86. func show(error: String) {
  87. self.alert(type: .error, message: error)
  88. }
  89. func show(message: String) {
  90. self.alertWithOk(
  91. type: .success,
  92. message: message,
  93. title: "Success",
  94. okTitle: "Ok"
  95. ) {
  96. self.navigationController?.popToRootViewController(animated: true)
  97. }
  98. }
  99. func setModel(model: WithdrawInformation){
  100. self.bankContentLabel.text = model.bankName ?? ""
  101. self.acNumberContentLabel.text = model.accountNo ?? ""
  102. self.amountContentLabel.text = (model.amount ?? "") + " MNT"
  103. self.serviceChargeContentLabel.text = (model.serviceCharge ?? "") + " MNT"
  104. }
  105. }
  106. // MARK: - BiometricAuthenticationViewControllerDelegate
  107. extension WithdrawFromWalletDetailViewController: BiometricAuthenticationViewControllerDelegate {
  108. func viewController(
  109. _ viewController: BiometricAuthenticationViewController,
  110. didFailWithError error: BiometricAuthenticationError, errorMessage: String?) {
  111. print("BiometricAuthenticationWireframe Error: \(errorMessage ?? "")")
  112. viewController.dismiss(animated: true) {
  113. switch error {
  114. case .userFallback:
  115. self.showSecureKeyPad()
  116. case .authenticationFailed, .userCancel, .biometryNotAvailable,
  117. .biometryNotEnrolled, .biometryLockout, .notBeConfigured:
  118. self.alert(type: .error, message: error.message)
  119. }
  120. }
  121. }
  122. func doSelectLocalAuthenticationPolicy(
  123. _ viewController: BiometricAuthenticationViewController
  124. ) -> BiometricAuthenticationPolicy {
  125. return .deviceOwnerAuthenticationWithBiometrics
  126. }
  127. func didComplete(_ viewController: BiometricAuthenticationViewController) {
  128. viewController.dismiss(animated: true) {
  129. guard let encryptedPW = KeyChain.shared.get(key: .password) else {
  130. MainWireframe.logoutWarningAlert(message: "To use biometrics authentication you have to login again.")
  131. return
  132. }
  133. self.password = encryptedPW
  134. }
  135. }
  136. func viewController(
  137. _ viewController: BiometricAuthenticationViewController,
  138. informationTitleLabel titleLabel: UILabel,
  139. authenticationButton button: UIButton
  140. ) {
  141. titleLabel.text = "use_biometric_authentication_text".localized()
  142. button.setTitle("verify_account_button_text".localized(), for: .normal)
  143. }
  144. }