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.

104 lines
3.0 KiB

  1. //
  2. // WithdrawFromWalletViewController.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 WithdrawFromWalletViewController: UIViewController {
  10. struct StringConstants {
  11. let titleText = "bank_deposit_text".localized()
  12. let proceedText = "proceed_text".localized()
  13. let withdrawSubtitle = "withdraw_description".localized()
  14. let amountPlaceholder = "enter_amount_text".localized()
  15. let amountError = "enter_amount_text".localized()
  16. }
  17. // MARK: Properties
  18. var presenter: WithdrawFromWalletModuleInterface?
  19. // MARK: IBOutlets
  20. @IBOutlet weak var subtitileLabel: UILabel!
  21. @IBOutlet weak var amount: ValidationTextField!
  22. @IBOutlet weak var proceedBtn: UIButton!
  23. private var isValid = false {
  24. didSet {
  25. // proceedBtn.isEnabled = isValid
  26. // proceedBtn.backgroundColor = isValid ? .themeRed : .themeText
  27. proceedBtn.isEnabled = true
  28. proceedBtn.backgroundColor = isValid ? .themeRed : .themeRed
  29. }
  30. }
  31. // MARK: VC's Life cycle
  32. override func viewDidLoad() {
  33. super.viewDidLoad()
  34. self.setup()
  35. }
  36. override func viewWillAppear(_ animated: Bool) {
  37. super.viewWillAppear(animated)
  38. self.title = StringConstants().titleText
  39. self.setupNormalNavigation()
  40. }
  41. // MARK: IBActions
  42. @IBAction func proceed(_ sender: Any) {
  43. self.presenter?.makeApiRequest(amount: self.amount.text ?? "")
  44. }
  45. // MARK: Other Functions
  46. private func setup() {
  47. // all setup should be done here
  48. self.isValid = false
  49. self.configureLanguage()
  50. }
  51. private func configureLanguage() {
  52. subtitileLabel.text = StringConstants().withdrawSubtitle
  53. amount.titleText = StringConstants().amountPlaceholder
  54. amount.placeholder = StringConstants().amountPlaceholder
  55. amount.errorMessage = StringConstants().amountError
  56. amount.addTarget(self, action: #selector(editingChanged(_:)), for: .editingChanged)
  57. proceedBtn.setTitle(StringConstants().proceedText, for: .normal)
  58. }
  59. @objc private func editingChanged(_ textField: UITextField) {
  60. guard let tf = textField as? ValidationTextField else {return}
  61. isValid = tf.text != ""
  62. }
  63. }
  64. // MARK: WithdrawFromWalletViewInterface
  65. extension WithdrawFromWalletViewController: WithdrawFromWalletViewInterface {
  66. func showLoading() {
  67. self.showProgressHud()
  68. }
  69. func hideLoading() {
  70. self.hideProgressHud()
  71. }
  72. func show(error: String) {
  73. self.alert(type: .error, message: error)
  74. }
  75. func show(message: String) {
  76. self.alertWithOk(
  77. type: .success,
  78. message: message,
  79. title: "success_text".localized(),
  80. okTitle: "Ok"
  81. ) {
  82. }
  83. }
  84. }