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.

101 lines
3.0 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(
  34. senderAmt: String?,
  35. senderCurrency: String?,
  36. recieverAmt: String?,
  37. recieverCurrency: String?,
  38. recieverCountryName: String?,
  39. recieverCountryId: String?,
  40. paymentMethod: String?,
  41. paymentMethodId: String?,
  42. calcBy: String?,
  43. senderCountryId: String?,
  44. payoutPartner: String?,
  45. userId: String?,
  46. bankId: String?
  47. ) {
  48. let senderAmt = senderAmt ?? ""
  49. let recieverAmt = recieverAmt ?? ""
  50. if senderAmt.isEmpty && recieverAmt.isEmpty {
  51. let message = "please provide amount to calculate"
  52. self.view?.show(error: message)
  53. return
  54. }
  55. self.view?.showLoading()
  56. let param: [String: String] =
  57. [
  58. ApiConstants.senderAmount : senderAmt,
  59. ApiConstants.senderCurrency : senderCurrency ?? "",
  60. ApiConstants.recieverAmount : recieverAmt,
  61. ApiConstants.recieverCurrency : recieverCurrency ?? "",
  62. ApiConstants.recieverCountryName: recieverCountryName ?? "",
  63. ApiConstants.recieverCountryId : recieverCountryId ?? "",
  64. ApiConstants.paymentMethod: paymentMethod ?? "",
  65. ApiConstants.paymentMethodId: paymentMethodId ?? "",
  66. ApiConstants.calcBy : calcBy ?? "",
  67. ApiConstants.senderCountryId : senderCountryId ?? "",
  68. ApiConstants.payOutPartner : payoutPartner ?? "",
  69. ApiConstants.userId : userId ?? "",
  70. ApiConstants.bankId : bankId ?? ""
  71. ]
  72. self.interactor?.calculate(params: param)
  73. }
  74. }
  75. // MARK: SendMoneyExchangeRate interactor output interface
  76. extension SendMoneyExchangeRatePresenter: SendMoneyExchangeRateInteractorOutput {
  77. func setError(with error: Error) {
  78. view?.setError(with: error)
  79. }
  80. func show(model: SendMoneyExchangeRateModel) {
  81. self.view?.hideLoading()
  82. self.view?.show(model: model)
  83. }
  84. func show(error: Error) {
  85. self.view?.hideLoading()
  86. self.view?.show(error: error.localizedDescription)
  87. }
  88. }