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.

440 lines
16 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. //
  2. // WalletViewController.swift
  3. // GMERemittance
  4. //
  5. // Created by Sujal on 2/3/18.
  6. // Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. class WalletViewController: UIViewController, UIScrollViewDelegate {
  10. @IBOutlet weak var segmentedControl: UISegmentedControl!
  11. @IBOutlet weak var stackView: UIStackView!
  12. @IBOutlet weak var scrollView: UIScrollView!
  13. @IBOutlet weak var contentView: UIView!
  14. @IBOutlet weak var labelID: UILabel!
  15. @IBOutlet weak var textFieldID: UITextField!
  16. @IBOutlet weak var textFieldAmount: UITextField!
  17. @IBOutlet weak var textFieldMessage: UITextField!
  18. @IBOutlet weak var buttonSubmit: UIButton!
  19. @IBOutlet weak var buttonMoneyRequestCount: UIButton!
  20. private var activeTextField: UITextField?
  21. private var walletviewmodel = WalletViewModel()
  22. // private var profileviewmodel = ProfileViewModel()
  23. private var tracktransactionviewmodel = TrackTransactionViewModel()
  24. public var transaction: Transaction?
  25. private var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
  26. private var moneyRequestAccepted: Bool = false
  27. public static var notificationCode: String = ""
  28. private var isScrolled: Bool = false
  29. public static var walletConnectionTimeOutCheck = 0
  30. @objc func appMovedToForeground() {
  31. activeTextField?.resignFirstResponder()
  32. if isScrolled {
  33. isScrolled = !isScrolled
  34. }
  35. }
  36. override func viewDidAppear(_ animated: Bool) {
  37. setUpAnotherLoginListener(genericviewmodel: walletviewmodel)
  38. setUpAnotherLoginListener(genericviewmodel: tracktransactionviewmodel)
  39. // setUpAnotherLoginListener(genericviewmodel: profileviewmodel)
  40. // profileviewmodel.profileConnectionTimeOut.value = nil
  41. /**
  42. connection timeout
  43. */
  44. // profileviewmodel.profileConnectionTimeOut.bind { [unowned self] in
  45. // guard $0 != nil else {
  46. // return
  47. // }
  48. // self.stopLoading()
  49. // if WalletViewController.walletConnectionTimeOutCheck == 0{
  50. // WalletViewController.walletConnectionTimeOutCheck = WalletViewController.walletConnectionTimeOutCheck+1
  51. // self.popUpMessage(value: 31)
  52. // }
  53. // }
  54. //
  55. // tracktransactionviewmodel.transactionListConnectionTimeOut.value = nil
  56. /**
  57. connection timeout
  58. */
  59. // tracktransactionviewmodel.transactionListConnectionTimeOut.bind { [unowned self] in
  60. // guard $0 != nil else {
  61. // return
  62. // }
  63. // self.stopLoading()
  64. // if WalletViewController.walletConnectionTimeOutCheck == 0{
  65. // WalletViewController.walletConnectionTimeOutCheck = WalletViewController.walletConnectionTimeOutCheck+1
  66. // self.popUpMessage(value: 31)
  67. // }
  68. // }
  69. // walletviewmodel.walletConnectionTimeOut.value = nil
  70. // /**
  71. // connection timeout
  72. // */
  73. // walletviewmodel.walletConnectionTimeOut.bind { [unowned self] in
  74. // guard $0 != nil else {
  75. // return
  76. // }
  77. // self.stopLoading()
  78. // if WalletViewController.walletConnectionTimeOutCheck == 0{
  79. // WalletViewController.walletConnectionTimeOutCheck = WalletViewController.walletConnectionTimeOutCheck+1
  80. // self.popUpMessage(value: 31)
  81. // }
  82. // }
  83. // setUpNetworkListener()
  84. // setUpNetworkListenerForProfile()
  85. // setUpProfileListener()
  86. // setUpTransactionListener()
  87. // setUpWalletDetailsListener()
  88. //
  89. // /*so that the value is reset and no error message is seen when going back and froth in error case*/
  90. // self.walletviewmodel.walletActionPerformed.value = nil
  91. //
  92. // self.buttonMoneyRequestCount.setTitle("", for: .normal)
  93. // self.buttonMoneyRequestCount.isUserInteractionEnabled = false
  94. //
  95. // tracktransactionviewmodel.fetchTransactionListForTrackAndWallet(recipientId: "", recipientName: "", transactionType: "moneyRequest", startDate: nil, endDate: nil, txPage: nil, txSize: nil)
  96. // }
  97. //
  98. // override func viewDidLoad() {
  99. // super.viewDidLoad()
  100. //
  101. // setUpNavBar(id: 201, title: "Wallet to Wallet Transfer")
  102. //
  103. // NotificationCenter.default.addObserver(self, selector: #selector(appMovedToForeground), name: Notification.Name.UIApplicationWillEnterForeground, object: nil)
  104. //
  105. // registerTapListener()
  106. //
  107. //
  108. // self.startLoading()
  109. // walletviewmodel.getTransactionInfo()
  110. //
  111. // scrollView.delegate = self
  112. // scrollView.addSubview(contentView)
  113. // scrollView.contentSize = CGSize(width: 2000, height:2000)
  114. //
  115. // if transaction != nil {
  116. // moneyRequestAccepted = true
  117. // segmentedControl.isUserInteractionEnabled = false
  118. // walletviewmodel.setMode(segmentIndex: 2)
  119. // walletviewmodel.setMoneyRequestTransactionID(id: transaction!.transactionId)
  120. //
  121. // textFieldID.text = transaction!.receiverId
  122. // textFieldAmount.text = transaction!.payoutAmountOriginal
  123. //
  124. //
  125. // textFieldID.isUserInteractionEnabled = false
  126. // }
  127. // textFieldID.delegate = self
  128. // textFieldAmount.delegate = self
  129. // textFieldMessage.delegate = self
  130. //
  131. //
  132. // segmentedControl.selectedSegmentIndex = 0
  133. // segmentedControl.addTarget(self, action: #selector(modeChanged(_:)), for: .valueChanged)
  134. //
  135. // walletviewmodel.setMode(segmentIndex: 0)
  136. // }
  137. //
  138. // /**
  139. // Disable user interaction while fetching data from api
  140. // */
  141. // func startLoading(){
  142. // self.showActivityIndicator(activityIndicator: self.activityIndicator)
  143. // self.disableUserInteractions()
  144. // }
  145. //
  146. // /**
  147. // Enable user interaction while fetching data from api
  148. // */
  149. // func stopLoading(){
  150. // self.dismissActivityIndicator(activityIndicator: self.activityIndicator)
  151. // self.enableUserInteractions()
  152. // }
  153. //
  154. // /**
  155. // Check internet connection
  156. // */
  157. // func setUpNetworkListener() {
  158. // walletviewmodel.internetConnection.bind { [unowned self] in
  159. // guard $0 != nil else {
  160. // return
  161. // }
  162. // self.walletviewmodel.internetConnection.value = nil
  163. // self.stopLoading()
  164. // self.popUpMessage(value: 15)
  165. // }
  166. // }
  167. //
  168. // func setUpNetworkListenerForProfile() {
  169. // profileviewmodel.internetConnection.bind { [unowned self] in
  170. // guard $0 != nil else {
  171. // return
  172. // }
  173. // self.profileviewmodel.internetConnection.value = nil
  174. // self.stopLoading()
  175. // self.popUpMessage(value: 15)
  176. // }
  177. // }
  178. //
  179. // /**
  180. // Set GMEUser name
  181. // */
  182. // func setUpProfileListener() {
  183. // profileviewmodel.userDataAvailable.bind { [unowned self] in
  184. // guard $0 != nil else {
  185. // return
  186. // }
  187. // self.stopLoading()
  188. // if !($0!) {
  189. // if WalletViewController.walletConnectionTimeOutCheck == 0{
  190. // WalletViewController.walletConnectionTimeOutCheck = WalletViewController.walletConnectionTimeOutCheck+1
  191. // self.popUpMessageError(value: 10, message: self.profileviewmodel.getErrorMessage())
  192. // }
  193. // } else {
  194. // if !self.profileviewmodel.hasFilledKYC() {
  195. // self.popUpMessageError(value: 11, message: "User has not filled KYC form")
  196. // } else {
  197. // self.walletviewmodel.setGMEUsername(fullName: self.profileviewmodel.getFullName())
  198. // self.performSegue(withIdentifier: "walletReview", sender: nil)
  199. // }
  200. // }
  201. // self.profileviewmodel.userDataAvailable.value = nil
  202. // }
  203. // }
  204. //
  205. // /**
  206. // Update the view with the transaction count
  207. // */
  208. // func setUpTransactionListener() {
  209. // tracktransactionviewmodel.transactionListObtained.bind{ [weak self] in
  210. // guard $0 != nil else {
  211. // return
  212. // }
  213. // guard $0! else {
  214. // return
  215. // }
  216. // let requestCount = self?.tracktransactionviewmodel.getCount()
  217. // self?.buttonMoneyRequestCount.setTitle(String(requestCount!), for: .normal)
  218. //
  219. // if requestCount != nil {
  220. // if requestCount! > 0 {
  221. // self?.buttonMoneyRequestCount.isUserInteractionEnabled = true
  222. // }
  223. // }
  224. // }
  225. // }
  226. //
  227. // /**
  228. // Set maximum amount
  229. // */
  230. // func setUpWalletDetailsListener() {
  231. // walletviewmodel.walletLimitsFetched.bind{ [unowned self] in
  232. // guard $0 != nil else {
  233. // return
  234. // }
  235. // self.stopLoading()
  236. // guard $0! else {
  237. // if WalletViewController.walletConnectionTimeOutCheck == 0{
  238. // WalletViewController.walletConnectionTimeOutCheck = WalletViewController.walletConnectionTimeOutCheck+1
  239. // self.popUpMessageError(value: 10, message: self.walletviewmodel.getErrorMessage())
  240. // }
  241. // self.walletviewmodel.walletLimitsFetched.value = nil
  242. // self.buttonSubmit.isUserInteractionEnabled = false
  243. // return
  244. // }
  245. // self.textFieldAmount.placeholder = "Maximum Amount" + " " + self.walletviewmodel.getMaximumTransferLimit() + " " + "KRW"
  246. // self.walletviewmodel.walletLimitsFetched.value = nil
  247. // }
  248. // }
  249. //
  250. // @objc func modeChanged(_ segControl: UISegmentedControl) {
  251. //
  252. // textFieldID.text = ""
  253. // textFieldMessage.text = ""
  254. // textFieldAmount.text = ""
  255. //
  256. // switch segControl.selectedSegmentIndex {
  257. // case 0:
  258. // labelID.text = "GME User ID of Receiver"
  259. // buttonSubmit.setTitle("Transfer", for: .normal)
  260. // walletviewmodel.setMode(segmentIndex: 0)
  261. // case 1:
  262. // labelID.text = "GME User ID of Sender"
  263. // buttonSubmit.setTitle("Request", for: .normal)
  264. // walletviewmodel.setMode(segmentIndex: 1)
  265. // default:
  266. // break
  267. // }
  268. // }
  269. //
  270. //
  271. // @IBAction func reviewTransferDetails(_ sender: Any) {
  272. // activeTextField?.resignFirstResponder()
  273. //
  274. // walletviewmodel.setParam(amount: textFieldAmount.text!,
  275. // gmeID: textFieldID.text!,
  276. // message: textFieldMessage.text!)
  277. //
  278. // switch walletviewmodel.validateFields() {
  279. // case .Valid:
  280. // self.startLoading()
  281. // profileviewmodel.fetchUserInfo(userId: walletviewmodel.getGMEID())
  282. // case .InValid(let validationError):
  283. // self.popUpMessageError(value: 11, message: validationError)
  284. // }
  285. // }
  286. //
  287. // override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  288. // switch segue.identifier {
  289. // case "walletReview"?:
  290. // let walletReviewViewController
  291. // = segue.destination as! WalletReviewViewController
  292. // walletReviewViewController.walletviewmodel = self.walletviewmodel
  293. // walletReviewViewController.moneyRequestAccepted = self.moneyRequestAccepted
  294. // case "walletTransfer"?:
  295. // activeTextField?.resignFirstResponder()
  296. // let walletTransactionListViewController
  297. // = segue.destination as! WalletTransactionListViewController
  298. // walletTransactionListViewController.walletStatus = "walletTransfer"
  299. // case "walletBorrow"?:
  300. // activeTextField?.resignFirstResponder()
  301. // let walletTransactionListViewController
  302. // = segue.destination as! WalletTransactionListViewController
  303. // walletTransactionListViewController.walletStatus = "walletBorrow"
  304. // case "moneyRequest"?:
  305. // activeTextField?.resignFirstResponder()
  306. // let moneyRequestViewController
  307. // = segue.destination as! MoneyRequestViewController
  308. // moneyRequestViewController.moneyRequests = tracktransactionviewmodel.getTransactions()
  309. // default:
  310. // return
  311. // }
  312. //
  313. // }
  314. //}
  315. //
  316. //extension WalletViewController: UITextFieldDelegate {
  317. //
  318. //
  319. // func textFieldDidBeginEditing(_ textField: UITextField) {
  320. //
  321. // activeTextField = textField
  322. //
  323. // checkScroll()
  324. //
  325. // if textField == textFieldAmount {
  326. // if textField.text!.contains("KRW") {
  327. // textField.text = textField.text!.replacingOccurrences(of: " KRW", with: "", options: NSString.CompareOptions.literal, range: nil)
  328. // }
  329. // }
  330. // }
  331. //
  332. // func textFieldDidEndEditing(_ textField: UITextField) {
  333. //
  334. // checkScroll()
  335. //
  336. // if textField == textFieldAmount {
  337. // if textField.text != "" && !textField.text!.contains("KRW") {
  338. // textField.text!.append(" KRW")
  339. // }
  340. // }
  341. // }
  342. //
  343. // func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
  344. //
  345. // let inputText = (textField.text! as NSString).replacingCharacters(in: range, with: string)
  346. // if textField == textFieldAmount {
  347. // //^[0-9]+$
  348. // if NSPredicate(format:"SELF MATCHES %@", "[0-9]*$").evaluate(with: inputText) {
  349. // return true
  350. // }
  351. // return false
  352. // }
  353. // return true
  354. // }
  355. //
  356. // func textFieldShouldReturn(_ textField: UITextField) -> Bool {
  357. // switch textField {
  358. // case textFieldID:
  359. // textFieldAmount.becomeFirstResponder()
  360. // case textFieldMessage:
  361. // textFieldMessage.resignFirstResponder()
  362. // default:
  363. // return false
  364. // }
  365. // return true
  366. // }
  367. //}
  368. //
  369. //extension WalletViewController: ScrollableProtocol {
  370. // var offset: CGFloat {
  371. // get {
  372. // return stackView.frame.origin.y - 20
  373. // }
  374. // }
  375. //
  376. // var viewScrolled: Bool {
  377. // get {
  378. // return isScrolled
  379. // }
  380. // }
  381. //
  382. // /**
  383. // Scroll logic
  384. // */
  385. // func checkScroll() {
  386. // if !viewScrolled {
  387. // performScroll(direction: 0)
  388. // isScrolled = !isScrolled
  389. // } else {
  390. // performScroll(direction: 1)
  391. // isScrolled = !isScrolled
  392. // }
  393. // }
  394. //
  395. // func registerTapListener() {
  396. // let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(clearKeyboard))
  397. // view.addGestureRecognizer(tap)
  398. // }
  399. //
  400. // /**
  401. // Dismiss keypad
  402. // */
  403. // @objc func clearKeyboard() {
  404. // activeTextField?.resignFirstResponder()
  405. // if viewScrolled {
  406. // performScroll(direction: 1)
  407. // isScrolled = !isScrolled
  408. // }
  409. // }
  410. //
  411. // /**
  412. // Active keypad if direction is equal to 0
  413. // - parameter direction: display keypad if direction is equal to 0
  414. // */
  415. // func performScroll(direction: Int) {
  416. // if direction == 0 {
  417. // UIView.animate(withDuration: 0.3, animations: {
  418. // self.view.frame = self.view.frame.offsetBy(dx: 0, dy: self.offset * -1)
  419. // })
  420. // } else if direction == 1 {
  421. // UIView.animate(withDuration: 0.3, animations: {
  422. // self.view.frame = self.view.frame.offsetBy(dx: 0, dy: self.offset)
  423. // })
  424. // }
  425. }
  426. }