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.

86 lines
3.2 KiB

  1. //
  2. // SendMoneyExchangeRatePresenter.swift
  3. // GMERemittance
  4. //
  5. // Created by gme_2 on 28/08/2018.
  6. //Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. class SendMoneyExchangeRatePresenter {
  10. struct ApiConstants {
  11. static let senderAmount = "cAmount"
  12. static let senderCurrency = "sCurrency"
  13. static let recieverAmount = "pAmount"
  14. static let recieverCurrency = "pCurrency"
  15. static let recieverCountryId = "pCountry"
  16. static let paymentMethod = "paymentType"
  17. static let paymentMethodId = "serviceType"
  18. static let calcBy = "calcBy"
  19. static let recieverCountryName = "pCountryName"
  20. static let senderCountryId = "sCountry"
  21. static let bankId = "pAgent"
  22. static let payOutPartner = "payOutPartner"
  23. static let userId = "userId"
  24. }
  25. // MARK: Properties
  26. weak var view: SendMoneyExchangeRateViewInterface?
  27. var interactor: SendMoneyExchangeRateInteractorInput?
  28. var wireframe: SendMoneyExchangeRateWireframeInput?
  29. // MARK: Converting entities
  30. }
  31. // MARK: SendMoneyExchangeRate module interface
  32. extension SendMoneyExchangeRatePresenter: SendMoneyExchangeRateModuleInterface {
  33. func calculate(senderAmt: String?, senderCurrency: String?, recieverAmt: String?, recieverCurrency: String?, recieverCountryName: String?, recieverCountryId: String?, paymentMethod: String?, paymentMethodId: String?, calcBy: String?, senderCountryId: String?, payoutPartner: String?, userId: String?, bankId: String?) {
  34. let _senderAmt = senderAmt ?? ""
  35. let _recieverAmt = recieverAmt ?? ""
  36. if _senderAmt.isEmpty && _recieverAmt.isEmpty {
  37. let message = "please provide amount to calculate"
  38. self.view?.show(error: message)
  39. return
  40. }
  41. self.view?.showLoading()
  42. let param: [String: String] =
  43. [
  44. ApiConstants.senderAmount : senderAmt ?? "",
  45. ApiConstants.senderCurrency : senderCurrency ?? "",
  46. ApiConstants.recieverAmount : recieverAmt ?? "",
  47. ApiConstants.recieverCurrency : recieverCurrency ?? "",
  48. ApiConstants.recieverCountryName: recieverCountryName ?? "",
  49. ApiConstants.recieverCountryId : recieverCountryId ?? "",
  50. ApiConstants.paymentMethod: paymentMethod ?? "",
  51. ApiConstants.paymentMethodId: paymentMethodId ?? "",
  52. ApiConstants.calcBy : calcBy ?? "",
  53. ApiConstants.senderCountryId : senderCountryId ?? "",
  54. ApiConstants.payOutPartner : payoutPartner ?? "",
  55. ApiConstants.userId : userId ?? "",
  56. ApiConstants.bankId : bankId ?? ""
  57. ]
  58. self.interactor?.calculate(params: param)
  59. }
  60. func viewIsReady() {
  61. }
  62. }
  63. // MARK: SendMoneyExchangeRate interactor output interface
  64. extension SendMoneyExchangeRatePresenter: SendMoneyExchangeRateInteractorOutput {
  65. func show(model: SendMoneyExchangeRateModel) {
  66. self.view?.hideLoading()
  67. self.view?.show(model: model)
  68. }
  69. func show(error: Error) {
  70. self.view?.hideLoading()
  71. self.view?.show(error: error.localizedDescription)
  72. }
  73. }