|
@ -81,46 +81,83 @@ class ExchangeRatesViewController: UIViewController { |
|
|
|
|
|
|
|
|
var presenter: ExchangeRatesModuleInterface? |
|
|
var presenter: ExchangeRatesModuleInterface? |
|
|
var countryListTapGuesture: UITapGestureRecognizer? |
|
|
var countryListTapGuesture: UITapGestureRecognizer? |
|
|
var selectedPaymentIndex: IndexPath = IndexPath.init(row: 0, section: 0) |
|
|
|
|
|
|
|
|
var selectedPaymentModeIndex = 0 |
|
|
var translated: Bool = false |
|
|
var translated: Bool = false |
|
|
var nativeCountryCode: String? = "np" |
|
|
var nativeCountryCode: String? = "np" |
|
|
|
|
|
|
|
|
var calcBy = "" |
|
|
var calcBy = "" |
|
|
|
|
|
|
|
|
var exchangeRateModels: [ExchangeRateModel]? { |
|
|
|
|
|
|
|
|
private var exchangeRateModels: [ExchangeRateModel]? { |
|
|
didSet { |
|
|
didSet { |
|
|
if CountryInfo() |
|
|
|
|
|
.defaultCountryCodes |
|
|
|
|
|
.filter({$0.lowercased() == (self.nativeCountryCode ?? "").lowercased()}).first != nil { |
|
|
|
|
|
if let defaultExchangeRate = self.exchangeRateModels?.filter({ |
|
|
|
|
|
($0.countryCode ?? "").lowercased() == (self.nativeCountryCode ?? "").lowercased() |
|
|
|
|
|
}).first { |
|
|
|
|
|
// there is native country, defaultExchangeRate is the information for that country |
|
|
|
|
|
self.setCountryFlag(countryCode: defaultExchangeRate.countryCode ?? "") |
|
|
|
|
|
self.setCurrencyLabel(currency: defaultExchangeRate.currency ?? "") |
|
|
|
|
|
// set the default amount for this country. there are some default values in CountryInfo |
|
|
|
|
|
self.selectedExchageRateModel = defaultExchangeRate |
|
|
|
|
|
self.collectionView.reloadData() |
|
|
|
|
|
// showPaymentModeView() |
|
|
|
|
|
self.populateDefaultAmounts() |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
let countryCode = GMEDB.shared.user.string(.countryCode) |
|
|
|
|
|
|
|
|
|
|
|
if let defaultExchangeRate = exchangeRateModels?.filter({ |
|
|
|
|
|
($0.countryCode ?? "").lowercased() == countryCode?.lowercased() |
|
|
|
|
|
}).first { |
|
|
|
|
|
selectedExchangeRateModel = defaultExchangeRate |
|
|
} else { |
|
|
} else { |
|
|
self.setDefaultValuesForCountriesNotHavingDefaultValueFirsttime() |
|
|
|
|
|
showPaymentModeView() |
|
|
|
|
|
|
|
|
selectedExchangeRateModel = exchangeRateModels?.filter({ |
|
|
|
|
|
($0.countryCode ?? "").lowercased() == "az" |
|
|
|
|
|
}).first |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var selectedExchageRateModel: ExchangeRateModel? { |
|
|
|
|
|
|
|
|
private var selectedExchangeRateModel: ExchangeRateModel? { |
|
|
didSet { |
|
|
didSet { |
|
|
self.setCurrencyLabel(currency: self.selectedExchageRateModel?.currency ?? "") |
|
|
|
|
|
self.setCountryFlag(countryCode: self.selectedExchageRateModel?.countryCode ?? "") |
|
|
|
|
|
collectionView.reloadData() |
|
|
collectionView.reloadData() |
|
|
// DispatchQueue.main.async { |
|
|
|
|
|
// self.reciepientTextField.resignFirstResponder() |
|
|
|
|
|
// self.senderTextField.resignFirstResponder() |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let code = selectedExchangeRateModel?.countryCode?.lowercased() ?? "az" |
|
|
|
|
|
let codeEnum = CountryEnum(rawValue: code) |
|
|
|
|
|
|
|
|
|
|
|
countryFlagImage.image = codeEnum?.flag |
|
|
|
|
|
countryCodeLabel.text = selectedExchangeRateModel?.currency |
|
|
|
|
|
|
|
|
|
|
|
guard let defaultAmount = codeEnum?.getDefaultRecipientAcount( |
|
|
|
|
|
currency: selectedExchangeRateModel?.currency ?? "" |
|
|
|
|
|
) else { |
|
|
|
|
|
calcBy = "c" |
|
|
|
|
|
senderTextField.text = codeEnum?.defaultSenderAmount.likeCommaMoney() |
|
|
|
|
|
reciepientTextField.text = "" |
|
|
|
|
|
calculateExchangeRate() |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
calcBy = "p" |
|
|
|
|
|
senderTextField.text = "" |
|
|
|
|
|
reciepientTextField.text = defaultAmount.likeCommaMoney() |
|
|
|
|
|
|
|
|
|
|
|
calculateExchangeRate() |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private var exchangeRateDetailModel: ExchangeRateDetailModel? { |
|
|
|
|
|
didSet { |
|
|
|
|
|
guard let model = exchangeRateDetailModel else { |
|
|
|
|
|
showExchangeRateInfomation(isHidden: true) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
showExchangeRateInfomation(isHidden: false) |
|
|
|
|
|
|
|
|
|
|
|
reciepientTextField.text = Utility.getCommaSeperatedStringWithDecimal( |
|
|
|
|
|
numberString: model.recipientAmount ?? "" |
|
|
|
|
|
) |
|
|
|
|
|
senderTextField.text = Utility.getCommaSeperatedStringWithDecimal( |
|
|
|
|
|
numberString: model.senderAmount ?? "" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
let transferFee = model.transferFee ?? "" |
|
|
|
|
|
let currency = model.senderCurrency ?? "" |
|
|
|
|
|
|
|
|
|
|
|
transferFeeInfoLabel.text = |
|
|
|
|
|
"-\(transferFee) \(currency) (" + "transfer_fee_included_text".localized() + ")" |
|
|
|
|
|
|
|
|
|
|
|
let exchangeRate = model.exchangeRate ?? "" |
|
|
|
|
|
exchangeRateInfoLabel.text = "\(exchangeRate) " + "(" + "current_exchange_rate_text".localized() + ")" |
|
|
|
|
|
|
|
|
|
|
|
calculatedInfoView.isHidden = false |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -129,116 +166,40 @@ class ExchangeRatesViewController: UIViewController { |
|
|
super.viewDidLoad() |
|
|
super.viewDidLoad() |
|
|
setup() |
|
|
setup() |
|
|
setupDelegates() |
|
|
setupDelegates() |
|
|
setupTargets() |
|
|
|
|
|
setupNavigation() |
|
|
setupNavigation() |
|
|
setupDefaultCountryFlagandCurrency() |
|
|
|
|
|
// todo: show default native country and falg |
|
|
|
|
|
// Do any additional setup after loading the view. |
|
|
|
|
|
// populateDefaultAmounts() |
|
|
|
|
|
|
|
|
|
|
|
self.nativeCountryCode = GMEDB.shared.user.string(.countryCode) |
|
|
self.nativeCountryCode = GMEDB.shared.user.string(.countryCode) |
|
|
fetchExchangeRateInformation() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func setupDefaultCountryFlagandCurrency() { |
|
|
|
|
|
if let defaultExchangeRate = self.exchangeRateModels?.filter({ |
|
|
|
|
|
($0.country ?? "").lowercased() == (self.nativeCountryCode ?? "").lowercased() |
|
|
|
|
|
}).first { |
|
|
|
|
|
// there is native country, defaultExchangeRate is the information for that country |
|
|
|
|
|
self.setCountryFlag(countryCode: defaultExchangeRate.countryCode ?? "") |
|
|
|
|
|
self.setCurrencyLabel(currency: defaultExchangeRate.currency ?? "") |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override func viewWillAppear(_ animated: Bool) { |
|
|
override func viewWillAppear(_ animated: Bool) { |
|
|
super.viewWillAppear(animated) |
|
|
super.viewWillAppear(animated) |
|
|
self.title = Constants().title |
|
|
self.title = Constants().title |
|
|
|
|
|
presenter?.fetchExchangeRate() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// IBActions |
|
|
// IBActions |
|
|
|
|
|
|
|
|
@IBAction func calculateExchangeRate(_ sender: Any?) { |
|
|
@IBAction func calculateExchangeRate(_ sender: Any?) { |
|
|
let senderAmount = self.senderTextField.text! |
|
|
|
|
|
let reciepientAmount = self.reciepientTextField.text! |
|
|
|
|
|
let recipientCurrency = self.selectedExchageRateModel?.currency |
|
|
|
|
|
let reciepientCountryId = self.selectedExchageRateModel?.countryId |
|
|
|
|
|
let paymentMethod = self.selectedExchageRateModel?.availableServices?.elementAt( |
|
|
|
|
|
index: selectedPaymentIndex.row |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
let reciepientCountryName = self.selectedExchageRateModel?.country |
|
|
|
|
|
self.calculate( |
|
|
|
|
|
senderAmt: senderAmount, |
|
|
|
|
|
recieverAmt: reciepientAmount, |
|
|
|
|
|
recieverCurrency: recipientCurrency, |
|
|
|
|
|
recieverCountryName: reciepientCountryName, |
|
|
|
|
|
recieverCountryId: reciepientCountryId, |
|
|
|
|
|
paymentMethod: paymentMethod?.id, |
|
|
|
|
|
calcBy: self.calcBy |
|
|
|
|
|
) |
|
|
|
|
|
// call calculate( ... ) function |
|
|
|
|
|
// todo send to api for calculation |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
calculateExchangeRate() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func calculate( |
|
|
|
|
|
senderAmt: String?, |
|
|
|
|
|
senderCurrency: String? = "KRW", |
|
|
|
|
|
recieverAmt: String?, |
|
|
|
|
|
recieverCurrency: String?, |
|
|
|
|
|
recieverCountryName: String?, |
|
|
|
|
|
recieverCountryId: String?, |
|
|
|
|
|
paymentMethod: String?, |
|
|
|
|
|
calcBy: String?, |
|
|
|
|
|
senderCountryId: String? = "118", |
|
|
|
|
|
shouldShowLoading: Bool = true |
|
|
|
|
|
) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private func calculateExchangeRate() { |
|
|
let model = ExchangeRateRequestModel( |
|
|
let model = ExchangeRateRequestModel( |
|
|
senderAmount: (senderAmt ?? "").stringRemovingComma(), |
|
|
|
|
|
senderCurrency: (senderCurrency ?? ""), |
|
|
|
|
|
senderCountryID: senderCountryId ?? "", |
|
|
|
|
|
recipientAmount: (recieverAmt ?? "").stringRemovingComma(), |
|
|
|
|
|
recipientCurrency: recieverCurrency ?? "", |
|
|
|
|
|
recipientCountryID: recieverCountryId ?? "", |
|
|
|
|
|
recipientCountry: recieverCountryName ?? "", |
|
|
|
|
|
serviceType: paymentMethod ?? "", |
|
|
|
|
|
calcBy: calcBy ?? "" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if shouldShowLoading { self.showProgressHud() } |
|
|
|
|
|
self.getExchangeRateInformation( |
|
|
|
|
|
model: model, |
|
|
|
|
|
success: { (exchageRateDetail) in |
|
|
|
|
|
self.showExchangeRateInfomation(isHidden: false) |
|
|
|
|
|
|
|
|
|
|
|
self.reciepientTextField.text = Utility.getCommaSeperatedStringWithDecimal( |
|
|
|
|
|
numberString: exchageRateDetail?.recipientAmount ?? "" |
|
|
|
|
|
) |
|
|
|
|
|
self.senderTextField.text = Utility.getCommaSeperatedStringWithDecimal( |
|
|
|
|
|
numberString: exchageRateDetail?.senderAmount ?? "" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
let transferFee = exchageRateDetail?.transferFee ?? "" |
|
|
|
|
|
let currency = exchageRateDetail?.senderCurrency ?? "" |
|
|
|
|
|
|
|
|
|
|
|
self.transferFeeInfoLabel.text = |
|
|
|
|
|
"-\(transferFee) \(currency) (" + "transfer_fee_included_text".localized() + ")" |
|
|
|
|
|
|
|
|
|
|
|
let exchangeRate = exchageRateDetail?.exchangeRate ?? "" |
|
|
|
|
|
self.exchangeRateInfoLabel.text = |
|
|
|
|
|
"\(exchangeRate) " + "(" + "current_exchange_rate_text".localized() + ")" |
|
|
|
|
|
self.hideProgressHud() |
|
|
|
|
|
|
|
|
|
|
|
self.calculatedInfoView.isHidden = false |
|
|
|
|
|
}, |
|
|
|
|
|
failure: { (error) in |
|
|
|
|
|
self.showExchangeRateInfomation(isHidden: true) |
|
|
|
|
|
self.hideProgressHud() |
|
|
|
|
|
self.view.endEditing(true) |
|
|
|
|
|
self.alert(type: .error, message: error.localizedDescription) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
senderAmount: (senderTextField.text ?? "").stringRemovingComma(), |
|
|
|
|
|
senderCurrency: "KRW", |
|
|
|
|
|
senderCountryID: "118", |
|
|
|
|
|
recipientAmount: (reciepientTextField.text ?? "").stringRemovingComma(), |
|
|
|
|
|
recipientCurrency: selectedExchangeRateModel?.currency ?? "", |
|
|
|
|
|
recipientCountryID: selectedExchangeRateModel?.countryId ?? "", |
|
|
|
|
|
recipientCountry: selectedExchangeRateModel?.country ?? "", |
|
|
|
|
|
serviceType: selectedExchangeRateModel? |
|
|
|
|
|
.availableServices? |
|
|
|
|
|
.elementAt(index: selectedPaymentModeIndex)?.id ?? "", |
|
|
|
|
|
calcBy: calcBy |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
presenter?.exchangeCalculate(use: model) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@objc func showCountryList(_ sender: UITapGestureRecognizer) { |
|
|
@objc func showCountryList(_ sender: UITapGestureRecognizer) { |
|
@ -257,6 +218,27 @@ class ExchangeRatesViewController: UIViewController { |
|
|
|
|
|
|
|
|
// other function |
|
|
// other function |
|
|
|
|
|
|
|
|
|
|
|
private func setExchangeRateUI() { |
|
|
|
|
|
[backgroundViewCountryLabel1, backgroundViewCountryLabel2] |
|
|
|
|
|
.forEach { $0?.layer.cornerRadius = 5 } |
|
|
|
|
|
|
|
|
|
|
|
[exchangeBackground1, exchangeBackground2] |
|
|
|
|
|
.forEach { |
|
|
|
|
|
$0?.layer.borderWidth = 1 |
|
|
|
|
|
$0?.layer.borderColor = UIColor.init(hex: "#E0E0E0").cgColor |
|
|
|
|
|
$0?.layer.cornerRadius = 5 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let dropDownImage = #imageLiteral(resourceName: "dropdown_white").withRenderingMode(UIImage.RenderingMode.alwaysTemplate) |
|
|
|
|
|
let image = dropDownImage |
|
|
|
|
|
|
|
|
|
|
|
dropDownImageView.image = image |
|
|
|
|
|
dropDownImageView.tintColor = UIColor.white |
|
|
|
|
|
|
|
|
|
|
|
senderTextField.delegate = self |
|
|
|
|
|
reciepientTextField.delegate = self |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private func showExchangeRateInfomation(isHidden flag: Bool) { |
|
|
private func showExchangeRateInfomation(isHidden flag: Bool) { |
|
|
calculatedInfoView.isHidden = flag |
|
|
calculatedInfoView.isHidden = flag |
|
|
calculatedInfoView.alpha = flag ? 0.0 : 1.0 |
|
|
calculatedInfoView.alpha = flag ? 0.0 : 1.0 |
|
@ -293,310 +275,64 @@ class ExchangeRatesViewController: UIViewController { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func countrySelected(model: [ExchangeRateModel]) { |
|
|
|
|
|
if model.count == 0 { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
self.selectedExchageRateModel = model.first |
|
|
|
|
|
|
|
|
|
|
|
guard let exchangeModel = self.selectedExchageRateModel else {return} |
|
|
|
|
|
guard let recievingCountryId = exchangeModel.countryId else {return} |
|
|
|
|
|
guard let paymentMethod = exchangeModel.availableServices?.elementAt( |
|
|
|
|
|
index: selectedPaymentIndex.row |
|
|
|
|
|
) else {return} |
|
|
|
|
|
|
|
|
|
|
|
if CountryInfo() |
|
|
|
|
|
.defaultCountryCodes |
|
|
|
|
|
.filter({$0.lowercased() == (self.selectedExchageRateModel?.countryCode ?? "").lowercased()}) |
|
|
|
|
|
.first != nil { |
|
|
|
|
|
self.setDefaultValuesForCountriesNotHavingDefaultValueAfterCountrySelection() |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if let recievingAmount = CountryInfo().getDefaultSendingAmount( |
|
|
|
|
|
for: selectedExchageRateModel?.countryCode ?? "" |
|
|
|
|
|
) { |
|
|
|
|
|
if CountryInfo() |
|
|
|
|
|
.doesCountryCodeHasDefined( |
|
|
|
|
|
country: exchangeModel.countryCode ?? "", |
|
|
|
|
|
currency: exchangeModel.currency ?? "" |
|
|
|
|
|
) { |
|
|
|
|
|
if let recievingCurrency = CountryInfo() |
|
|
|
|
|
.getDefaultSendingCurrency(for: exchangeModel.countryCode ?? "") { |
|
|
|
|
|
// do something if you have to do |
|
|
|
|
|
self.calcBy = "p" |
|
|
|
|
|
self.reciepientTextField.text = Utility.getCommaSeperatedStringWithDecimal( |
|
|
|
|
|
numberString: recievingAmount |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
let reciepientCountryName = exchangeModel.country |
|
|
|
|
|
self.calculate( |
|
|
|
|
|
senderAmt: nil, |
|
|
|
|
|
senderCurrency: "KRW", |
|
|
|
|
|
recieverAmt: recievingAmount, |
|
|
|
|
|
recieverCurrency: recievingCurrency, |
|
|
|
|
|
recieverCountryName: reciepientCountryName, |
|
|
|
|
|
recieverCountryId: recievingCountryId, |
|
|
|
|
|
paymentMethod: paymentMethod.id, |
|
|
|
|
|
calcBy: calcBy, |
|
|
|
|
|
shouldShowLoading: false |
|
|
|
|
|
) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// for countries having two currency like vn "VND" and "USD", mongolia, mn nad srilanka, lk |
|
|
|
|
|
if let recievingAmount = CountryInfo().getSecondarySendingAmount(for: exchangeModel.countryCode ?? "") { |
|
|
|
|
|
let recievingCurrency = exchangeModel.currency ?? "" |
|
|
|
|
|
if CountryInfo() |
|
|
|
|
|
.doesSecondaryOptiopsHasDefined( |
|
|
|
|
|
country: exchangeModel.countryCode ?? "" , |
|
|
|
|
|
currency: recievingCurrency |
|
|
|
|
|
) { |
|
|
|
|
|
// do something if you have to do |
|
|
|
|
|
|
|
|
|
|
|
self.calcBy = "p" |
|
|
|
|
|
self.reciepientTextField.text = Utility.getCommaSeperatedStringWithDecimal( |
|
|
|
|
|
numberString: recievingAmount |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
let reciepientCountryName = exchangeModel.country |
|
|
|
|
|
self.calculate( |
|
|
|
|
|
senderAmt: nil, |
|
|
|
|
|
senderCurrency: "KRW", |
|
|
|
|
|
recieverAmt: recievingAmount, |
|
|
|
|
|
recieverCurrency: recievingCurrency, |
|
|
|
|
|
recieverCountryName: reciepientCountryName, |
|
|
|
|
|
recieverCountryId: recievingCountryId, |
|
|
|
|
|
paymentMethod: paymentMethod.id, |
|
|
|
|
|
calcBy: calcBy, |
|
|
|
|
|
shouldShowLoading: false |
|
|
|
|
|
) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
self.calculateExchangeRate(nil) |
|
|
|
|
|
// show country with flag. |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@objc private func textChanged(sender: UITextField) { |
|
|
|
|
|
switch sender { |
|
|
|
|
|
case senderTextField: |
|
|
|
|
|
self.reciepientTextField.text = "" |
|
|
|
|
|
self.calcBy = "c" |
|
|
|
|
|
senderTextField.text = Utility.getCommaSeperatedString(numberString: senderTextField.text!) |
|
|
|
|
|
case reciepientTextField: |
|
|
|
|
|
|
|
|
|
|
|
self.senderTextField.text = "" |
|
|
|
|
|
self.calcBy = "p" |
|
|
|
|
|
reciepientTextField.text = Utility.getCommaSeperatedString(numberString: reciepientTextField.text!) |
|
|
|
|
|
default: |
|
|
|
|
|
break |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func setCountryFlag(countryCode: String) { |
|
|
|
|
|
let flag = CountryInfo().getFlag(for: countryCode) |
|
|
|
|
|
self.countryFlagImage.image = flag |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func setCurrencyLabel(currency: String) { |
|
|
|
|
|
self.countryCodeLabel.text = currency.uppercased() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func populateDefaultAmounts() { |
|
|
|
|
|
guard let nativeCountry = self.nativeCountryCode else {return} |
|
|
|
|
|
guard let exchangeModel = self.exchangeRateModels?.filter({ |
|
|
|
|
|
$0.countryCode?.lowercased() == nativeCountry.lowercased() // countryCode |
|
|
|
|
|
}).first else {return} |
|
|
|
|
|
|
|
|
|
|
|
if let recievingAmount = CountryInfo().getDefaultSendingAmount(for: exchangeModel.countryCode ?? "") { |
|
|
|
|
|
self.setDefaultValuesForCountriesHavingDefaultValue( |
|
|
|
|
|
recievingAmount: recievingAmount, |
|
|
|
|
|
exchangeModel: exchangeModel |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func setDefaultValuesForCountriesNotHavingDefaultValueAfterCountrySelection() { |
|
|
|
|
|
// self.selectedExchageRateModel = self.exchangeRateModels?.first |
|
|
|
|
|
let senderAmount = CountryInfo().getDefaultSendingMoneyInKoreanWon() |
|
|
|
|
|
self.senderTextField.text = Utility.getCommaSeperatedStringWithDecimal(numberString: senderAmount ?? "") |
|
|
|
|
|
let senderCurrency = "KWR" |
|
|
|
|
|
let recieverCurrency = self.selectedExchageRateModel?.currency |
|
|
|
|
|
let recieverCountryId = self.selectedExchageRateModel?.countryId |
|
|
|
|
|
let paymentMethod = self.selectedExchageRateModel?.availableServices?.elementAt( |
|
|
|
|
|
index: selectedPaymentIndex.row |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
let reciepientCountryName = self.selectedExchageRateModel?.country ?? "" |
|
|
|
|
|
let calcBy = "c" |
|
|
|
|
|
|
|
|
|
|
|
self.calculate( |
|
|
|
|
|
senderAmt: senderAmount, |
|
|
|
|
|
senderCurrency: senderCurrency, |
|
|
|
|
|
recieverAmt: nil, |
|
|
|
|
|
recieverCurrency: recieverCurrency, |
|
|
|
|
|
recieverCountryName: reciepientCountryName, |
|
|
|
|
|
recieverCountryId: recieverCountryId, |
|
|
|
|
|
paymentMethod: paymentMethod?.id, |
|
|
|
|
|
calcBy: calcBy, |
|
|
|
|
|
shouldShowLoading: true |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func setDefaultValuesForCountriesNotHavingDefaultValueFirsttime() { |
|
|
|
|
|
self.selectedExchageRateModel = self.exchangeRateModels?.first |
|
|
|
|
|
let senderAmount = CountryInfo().getDefaultSendingMoneyInKoreanWon() |
|
|
|
|
|
self.senderTextField.text = Utility.getCommaSeperatedStringWithDecimal(numberString: senderAmount ?? "") |
|
|
|
|
|
let senderCurrency = "KWR" |
|
|
|
|
|
let recieverCurrency = self.selectedExchageRateModel?.currency |
|
|
|
|
|
let recieverCountryId = self.selectedExchageRateModel?.countryId |
|
|
|
|
|
let paymentMethod = self.selectedExchageRateModel?.availableServices?.elementAt( |
|
|
|
|
|
index: selectedPaymentIndex.row |
|
|
|
|
|
) |
|
|
|
|
|
let reciepientCountryName = self.selectedExchageRateModel?.country ?? "" |
|
|
|
|
|
let calcBy = "c" |
|
|
|
|
|
|
|
|
|
|
|
self.calculate( |
|
|
|
|
|
senderAmt: senderAmount, |
|
|
|
|
|
senderCurrency: senderCurrency, |
|
|
|
|
|
recieverAmt: nil, |
|
|
|
|
|
recieverCurrency: recieverCurrency, |
|
|
|
|
|
recieverCountryName: reciepientCountryName, |
|
|
|
|
|
recieverCountryId: recieverCountryId, |
|
|
|
|
|
paymentMethod: paymentMethod?.id, |
|
|
|
|
|
calcBy: calcBy, |
|
|
|
|
|
shouldShowLoading: false |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func setDefaultValuesForCountriesHavingDefaultValue( |
|
|
|
|
|
recievingAmount: String, |
|
|
|
|
|
exchangeModel: ExchangeRateModel |
|
|
|
|
|
) { |
|
|
|
|
|
guard let recievingCurrency = CountryInfo().getDefaultSendingCurrency( |
|
|
|
|
|
for: exchangeModel.countryCode ?? "" |
|
|
|
|
|
), |
|
|
|
|
|
let recievingCountryId = exchangeModel.countryId, |
|
|
|
|
|
let paymentMethod = exchangeModel.availableServices?.elementAt(index: selectedPaymentIndex.row) |
|
|
|
|
|
else { |
|
|
|
|
|
// do something if you have to do |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
self.calcBy = "p" |
|
|
|
|
|
self.reciepientTextField.text = Utility.getCommaSeperatedStringWithDecimal(numberString: recievingAmount) |
|
|
|
|
|
let reciepientCountryName = exchangeModel.country |
|
|
|
|
|
self.calculate( |
|
|
|
|
|
senderAmt: nil, |
|
|
|
|
|
senderCurrency: "KRW", |
|
|
|
|
|
recieverAmt: recievingAmount, |
|
|
|
|
|
recieverCurrency: recievingCurrency, |
|
|
|
|
|
recieverCountryName: reciepientCountryName, |
|
|
|
|
|
recieverCountryId: recievingCountryId, |
|
|
|
|
|
paymentMethod: paymentMethod.id, |
|
|
|
|
|
calcBy: calcBy, |
|
|
|
|
|
shouldShowLoading: false |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func fetchExchangeRateInformation() { |
|
|
|
|
|
self.showProgressHud() |
|
|
|
|
|
self.fetchCountryCurrencyInfo( |
|
|
|
|
|
success: { (models) in |
|
|
|
|
|
self.exchangeRateModels = models |
|
|
|
|
|
}, |
|
|
|
|
|
failure: { (error) in |
|
|
|
|
|
self.hideProgressHud() |
|
|
|
|
|
self.view.endEditing(true) |
|
|
|
|
|
self.alert(type: .error, message: error.localizedDescription) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func setupTargets() { |
|
|
private func setupTargets() { |
|
|
let tapGuesture = UITapGestureRecognizer(target: self, action: #selector(self.showCountryList(_:))) |
|
|
|
|
|
self.countryListTapGuesture = tapGuesture |
|
|
|
|
|
self.countryListStackView.addGestureRecognizer(self.countryListTapGuesture!) |
|
|
|
|
|
self.reciepientTextField.addTarget( |
|
|
|
|
|
|
|
|
let tapGuesture = UITapGestureRecognizer(target: self, action: #selector(showCurrencyCountryPickerview)) |
|
|
|
|
|
countryListStackView.addGestureRecognizer(tapGuesture) |
|
|
|
|
|
|
|
|
|
|
|
reciepientTextField.addTarget( |
|
|
self, |
|
|
self, |
|
|
action: #selector(self.textChanged(sender:)), |
|
|
action: #selector(self.textChanged(sender:)), |
|
|
for: UIControl.Event.editingChanged |
|
|
for: UIControl.Event.editingChanged |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
self.senderTextField.addTarget( |
|
|
|
|
|
|
|
|
senderTextField.addTarget( |
|
|
self, |
|
|
self, |
|
|
action: #selector(self.textChanged(sender:)), |
|
|
action: #selector(self.textChanged(sender:)), |
|
|
for: UIControl.Event.editingChanged |
|
|
for: UIControl.Event.editingChanged |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
self.reciepientTextField.addTarget( |
|
|
|
|
|
self, |
|
|
|
|
|
action: #selector(self.textFieldSelected(sender:)), |
|
|
|
|
|
for: UIControl.Event.editingDidBegin |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
self.senderTextField.addTarget( |
|
|
|
|
|
self, |
|
|
|
|
|
action: #selector(self.textFieldSelected(sender:)), |
|
|
|
|
|
for: UIControl.Event.editingDidBegin |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@objc private func textFieldSelected(sender: UITextField) { |
|
|
|
|
|
|
|
|
@objc private func textChanged(sender: UITextField) { |
|
|
switch sender { |
|
|
switch sender { |
|
|
case senderTextField: |
|
|
case senderTextField: |
|
|
if Utility.getDeviceModel() == .iphone678 { |
|
|
|
|
|
let x = self.scrollView.contentOffset.x |
|
|
|
|
|
let y = self.scrollView.contentOffset.y |
|
|
|
|
|
let newOffset = CGPoint.init(x: x, y: y + 100) |
|
|
|
|
|
scrollView.setContentOffset(newOffset, animated: true) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if Utility.getDeviceModel() == .iphone5 { |
|
|
|
|
|
let x = self.scrollView.contentOffset.x |
|
|
|
|
|
let y = self.scrollView.contentOffset.y |
|
|
|
|
|
let newOffset = CGPoint.init(x: x, y: y + 150) |
|
|
|
|
|
scrollView.setContentOffset(newOffset, animated: true) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reciepientTextField.text = "" |
|
|
|
|
|
calcBy = "c" |
|
|
|
|
|
senderTextField.text = Utility.getCommaSeperatedString(numberString: senderTextField.text!) |
|
|
case reciepientTextField: |
|
|
case reciepientTextField: |
|
|
break |
|
|
|
|
|
|
|
|
senderTextField.text = "" |
|
|
|
|
|
calcBy = "p" |
|
|
|
|
|
reciepientTextField.text = Utility.getCommaSeperatedString(numberString: reciepientTextField.text!) |
|
|
default: |
|
|
default: |
|
|
break |
|
|
break |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@objc private func showCurrencyCountryPickerview() { |
|
|
|
|
|
DispatchQueue.main.async { |
|
|
|
|
|
self.reciepientTextField.resignFirstResponder() |
|
|
|
|
|
self.senderTextField.resignFirstResponder() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TablePresenterWireframe().openWith( |
|
|
|
|
|
tag: 1, |
|
|
|
|
|
delegate: self, |
|
|
|
|
|
model: exchangeRateModels, |
|
|
|
|
|
source: self |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private func setupDelegates() { |
|
|
private func setupDelegates() { |
|
|
self.collectionView.delegate = self |
|
|
self.collectionView.delegate = self |
|
|
self.collectionView.dataSource = self |
|
|
self.collectionView.dataSource = self |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private func setup() { |
|
|
private func setup() { |
|
|
let dropDownImage = #imageLiteral(resourceName: "dropdown_white").withRenderingMode(UIImage.RenderingMode.alwaysTemplate) |
|
|
|
|
|
let image = dropDownImage |
|
|
|
|
|
self.dropDownImageView.image = image |
|
|
|
|
|
self.dropDownImageView.tintColor = UIColor.white |
|
|
|
|
|
// self.paymentModeStackViewConstraint.constant = 0 |
|
|
|
|
|
// self.paymentModeStackView.alpha = 0 |
|
|
|
|
|
self.senderTextField.delegate = self |
|
|
|
|
|
self.reciepientTextField.delegate = self |
|
|
|
|
|
// corner Radius |
|
|
|
|
|
[backgroundViewCountryLabel1, backgroundViewCountryLabel2].forEach({ |
|
|
|
|
|
$0?.layer.cornerRadius = 5 |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
setupLanguage() |
|
|
|
|
|
|
|
|
[exchangeBackground1, exchangeBackground2].forEach({ |
|
|
|
|
|
$0?.layer.borderWidth = 1 |
|
|
|
|
|
$0?.layer.borderColor = UIColor.init(hex: "#E0E0E0").cgColor |
|
|
|
|
|
$0?.layer.cornerRadius = 5 |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
setupTargets() |
|
|
|
|
|
setExchangeRateUI() |
|
|
|
|
|
showExchangeRateInfomation(isHidden: true) |
|
|
|
|
|
|
|
|
setupLanguage() |
|
|
|
|
|
executeButton.layer.cornerRadius = 5 |
|
|
executeButton.layer.cornerRadius = 5 |
|
|
executeButton.backgroundColor = .themeRed |
|
|
executeButton.backgroundColor = .themeRed |
|
|
senderTextField.textColor = .themeRed |
|
|
senderTextField.textColor = .themeRed |
|
@ -614,26 +350,13 @@ class ExchangeRatesViewController: UIViewController { |
|
|
self.executeButton.setTitle(constant.calculate, for: UIControl.State.normal) |
|
|
self.executeButton.setTitle(constant.calculate, for: UIControl.State.normal) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func show(error: String) { |
|
|
|
|
|
self.view.endEditing(true) |
|
|
|
|
|
self.alert(type: .error, message: error) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func showLoading() { |
|
|
|
|
|
self.showProgressHud() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func hideLoading() { |
|
|
|
|
|
self.hideProgressHud() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func setupNavigation() { |
|
|
private func setupNavigation() { |
|
|
self.setupNormalNavigation() |
|
|
self.setupNormalNavigation() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
extension ExchangeRatesViewController: UICollectionViewDelegate { |
|
|
extension ExchangeRatesViewController: UICollectionViewDelegate { |
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
|
|
self.selectedPaymentIndex = indexPath |
|
|
|
|
|
|
|
|
self.selectedPaymentModeIndex = indexPath.row |
|
|
self.collectionView.reloadData() |
|
|
self.collectionView.reloadData() |
|
|
self.calculateExchangeRate(nil) |
|
|
self.calculateExchangeRate(nil) |
|
|
} |
|
|
} |
|
@ -641,14 +364,14 @@ extension ExchangeRatesViewController: UICollectionViewDelegate { |
|
|
|
|
|
|
|
|
extension ExchangeRatesViewController: UICollectionViewDataSource { |
|
|
extension ExchangeRatesViewController: UICollectionViewDataSource { |
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { |
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { |
|
|
return self.selectedExchageRateModel?.availableServices?.count ?? 0 |
|
|
|
|
|
|
|
|
return self.selectedExchangeRateModel?.availableServices?.count ?? 0 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func collectionView( |
|
|
func collectionView( |
|
|
_ collectionView: UICollectionView, |
|
|
_ collectionView: UICollectionView, |
|
|
cellForItemAt indexPath: IndexPath |
|
|
cellForItemAt indexPath: IndexPath |
|
|
) -> UICollectionViewCell { |
|
|
) -> UICollectionViewCell { |
|
|
let service = self.selectedExchageRateModel?.availableServices?.elementAt(index: indexPath.row) |
|
|
|
|
|
|
|
|
let service = self.selectedExchangeRateModel?.availableServices?.elementAt(index: indexPath.row) |
|
|
guard let index = PaymentMode.init(rawValue: service?.id ?? "") else { |
|
|
guard let index = PaymentMode.init(rawValue: service?.id ?? "") else { |
|
|
return UICollectionViewCell() |
|
|
return UICollectionViewCell() |
|
|
|
|
|
|
|
@ -679,8 +402,8 @@ extension ExchangeRatesViewController: UICollectionViewDataSource { |
|
|
return UICollectionViewCell() |
|
|
return UICollectionViewCell() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cell.cellSelected = self.selectedPaymentIndex == indexPath |
|
|
|
|
|
cell.paymentServiceMethod = self.selectedExchageRateModel?.availableServices?.elementAt( |
|
|
|
|
|
|
|
|
cell.cellSelected = self.selectedPaymentModeIndex == indexPath.row |
|
|
|
|
|
cell.paymentServiceMethod = self.selectedExchangeRateModel?.availableServices?.elementAt( |
|
|
index: indexPath.row |
|
|
index: indexPath.row |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
@ -700,8 +423,8 @@ extension ExchangeRatesViewController: UICollectionViewDataSource { |
|
|
return UICollectionViewCell() |
|
|
return UICollectionViewCell() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cell.cellSelected = self.selectedPaymentIndex == indexPath |
|
|
|
|
|
cell.paymentServiceMethod = self.selectedExchageRateModel?.availableServices?.elementAt( |
|
|
|
|
|
|
|
|
cell.cellSelected = self.selectedPaymentModeIndex == indexPath.row |
|
|
|
|
|
cell.paymentServiceMethod = self.selectedExchangeRateModel?.availableServices?.elementAt( |
|
|
index: indexPath.row |
|
|
index: indexPath.row |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
@ -721,8 +444,8 @@ extension ExchangeRatesViewController: UICollectionViewDataSource { |
|
|
return UICollectionViewCell() |
|
|
return UICollectionViewCell() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cell.cellSelected = self.selectedPaymentIndex == indexPath |
|
|
|
|
|
cell.paymentServiceMethod = self.selectedExchageRateModel?.availableServices?.elementAt( |
|
|
|
|
|
|
|
|
cell.cellSelected = self.selectedPaymentModeIndex == indexPath.row |
|
|
|
|
|
cell.paymentServiceMethod = self.selectedExchangeRateModel?.availableServices?.elementAt( |
|
|
index: indexPath.row |
|
|
index: indexPath.row |
|
|
) |
|
|
) |
|
|
cell.image = #imageLiteral(resourceName: "ic_cash") |
|
|
cell.image = #imageLiteral(resourceName: "ic_cash") |
|
@ -740,8 +463,8 @@ extension ExchangeRatesViewController: UICollectionViewDataSource { |
|
|
) as? ExchangeRateCollectionViewCell else { |
|
|
) as? ExchangeRateCollectionViewCell else { |
|
|
return UICollectionViewCell() |
|
|
return UICollectionViewCell() |
|
|
} |
|
|
} |
|
|
cell.cellSelected = self.selectedPaymentIndex == indexPath |
|
|
|
|
|
cell.paymentServiceMethod = self.selectedExchageRateModel?.availableServices?.elementAt( |
|
|
|
|
|
|
|
|
cell.cellSelected = self.selectedPaymentModeIndex == indexPath.row |
|
|
|
|
|
cell.paymentServiceMethod = self.selectedExchangeRateModel?.availableServices?.elementAt( |
|
|
index: indexPath.row |
|
|
index: indexPath.row |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
@ -760,7 +483,39 @@ extension ExchangeRatesViewController: UITextFieldDelegate { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// MARK: ExchangeRatesViewInterface |
|
|
// MARK: ExchangeRatesViewInterface |
|
|
extension ExchangeRatesViewController: ExchangeRatesViewInterface {} |
|
|
|
|
|
|
|
|
extension ExchangeRatesViewController: ExchangeRatesViewInterface { |
|
|
|
|
|
func setModel(with model: [ExchangeRateModel]?) { |
|
|
|
|
|
exchangeRateModels = model |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func setModel(with model: ExchangeRateDetailModel?) { |
|
|
|
|
|
exchangeRateDetailModel = model |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func setError(with error: Error) { |
|
|
|
|
|
if (error as NSError).code == -99 { |
|
|
|
|
|
alert( |
|
|
|
|
|
type: .error, |
|
|
|
|
|
message: error.localizedDescription, |
|
|
|
|
|
rightButtomTitle: "retry_text".localized(), |
|
|
|
|
|
okAction: { |
|
|
|
|
|
self.presenter?.fetchExchangeRate() |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
alert(message: error.localizedDescription) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func showLoading() { |
|
|
|
|
|
showProgressHud() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func hideLoading() { |
|
|
|
|
|
hideProgressHud() |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// MARK: - TablePresenterDelegate |
|
|
// MARK: - TablePresenterDelegate |
|
|
extension ExchangeRatesViewController: TablePresenterDelegate { |
|
|
extension ExchangeRatesViewController: TablePresenterDelegate { |
|
@ -778,10 +533,7 @@ extension ExchangeRatesViewController: TablePresenterDelegate { |
|
|
_ viewController: TablePresenterViewController, |
|
|
_ viewController: TablePresenterViewController, |
|
|
didSelectModel model: TablePresenterProtocol? |
|
|
didSelectModel model: TablePresenterProtocol? |
|
|
) { |
|
|
) { |
|
|
guard let model = model as? ExchangeRateModel else { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
countrySelected(model: [ model ]) |
|
|
|
|
|
|
|
|
showExchangeRateInfomation(isHidden: true) |
|
|
|
|
|
selectedExchangeRateModel = model as? ExchangeRateModel |
|
|
} |
|
|
} |
|
|
} |
|
|
} |