From f36eeccbfb0e4eb4a51e3efe189bc872cd4f4879 Mon Sep 17 00:00:00 2001 From: gme_2 Date: Thu, 7 Feb 2019 14:10:18 +0900 Subject: [PATCH] buf fixed --- GMERemittance/Library/CountryInfo.swift | 70 ++++++++++++++++--- .../View/ExchangeRatesViewController.swift | 56 +++++++++++---- 2 files changed, 103 insertions(+), 23 deletions(-) diff --git a/GMERemittance/Library/CountryInfo.swift b/GMERemittance/Library/CountryInfo.swift index 1e4d8b46..3081d1de 100644 --- a/GMERemittance/Library/CountryInfo.swift +++ b/GMERemittance/Library/CountryInfo.swift @@ -13,9 +13,33 @@ import Foundation return R.drawable.flag_belarus; */ - - -//Mongolia(MNT) 2,000,000, not possible this time, may be next version, +//Country Default Receiving Amount +//azerbaijan 1,000 +//Bangladesh 100,000 +//Belarus 1,000 +//Cambodia 500 +//Georgia 1,000 +//India 100,000 +//Indonesia 15,000,000 +//Kazakhstan 1,000 +//Kyrgyzstan 1,000 +//Malaysia 10,000 +//Moldova 1,000 +//Mongolia(USD) 1,000 +//Mongolia(MNT) 2,000,000 +//Myanmar 1,500,000 +//Nepal 100,000 +//Pakistan 100,000 +//Philippines 500 +//Russian Federation 1,000 +//Singapore 2,000 +//Sri Lanka(LKR) 100,000 +//Sri Lanka(USD) 1,000 +//Tajikistan 1,000 +//Thailand(THB) 30,000 +//Uzbekistan 1,000 +//Vietnam(VND) 50,000,000 +//Vietnam(USD) 2,000 class CountryInfo { @@ -51,8 +75,8 @@ class CountryInfo { "mn" : #imageLiteral(resourceName: "flag_mongolia") // Mongolia ] - var defaultCountries = ["Nepal", "Cambodia", "Philipinnes", "Sri Lanka", "Vietnam", "India", "Pakistan", "azerbaijan", "Bangladesh", "Belarus", "Georgia", "Indonesia", "Kazakhstan", "Kyrgyzstan", "Malaysia", "Moldova", "Mongolia", "Myanmar", "Philippines", "Russian Federation", "Singapore", "Tajikistan", "Thailand", "Uzbekistan", "Vietnam"] - var defaultCountryCodes = ["np", "kh", "ph", "lk", "vn", "in", "pk", "az", "bd", "by", "ge", "id", "kz", "kg", "my", "md", "mn", "mm", "ph", "ru", "sg", "tj", "th", "uz", "vn"] + var defaultCountries = ["Nepal", "Cambodia", "Philipinnes", "Sri Lanka", "Vietnam", "India", "Pakistan", "azerbaijan", "Bangladesh", "Belarus", "Georgia", "Indonesia", "Kazakhstan", "Kyrgyzstan", "Malaysia", "Moldova", "Mongolia", "Myanmar", "Russian Federation", "Singapore", "Tajikistan", "Thailand", "Uzbekistan"] + var defaultCountryCodes = ["np", "kh", "ph", "lk", "vn", "in", "pk", "az", "bd", "by", "ge", "id", "kz", "kg", "my", "md", "mn", "mm", "ru", "sg", "tj", "th", "uz"] private var defaultSendingAmount: [String: String] = [ @@ -60,7 +84,7 @@ class CountryInfo { "kh" : "500", // cambodia "ph" : "50000", // philipines "lk" : "100,000", // sri lanka - "vn" : "20000000", // vietnam + "vn" : "50000000", // Vietnam "in" : "50000", // india "pk" : "100000", // pakistan "az" : "1000", // azerbaijan @@ -74,13 +98,11 @@ class CountryInfo { "md" : "1000", // Moldova "mn" : "1000", // Mongolia "mm" : "1500000", // Myanmar - "ph" : "500", // Philippines "ru" : "1000", // Russian Federation "sg" : "2000", // Singapore "tj" : "1000", // Tajikistan "th" : "30000", // Thailand "uz" : "1000", // Uzbekistan - "vn" : "50000000", // Vietnam "default": "1000000" ] @@ -93,8 +115,9 @@ class CountryInfo { "vn" : "VND", // vietnam "in" : "INR", // india "pk" : "PKR", // pakistan - "az" : "USD", // azerbaijan + "az" : "USD", // azerbaijan "bd" : "USD", // Bangladesh + "by" : "USD", // Belarus "ge" : "USD", // Georgia "id" : "IDR", // Indonesia "kz" : "USD", // Kazakhstan @@ -103,15 +126,28 @@ class CountryInfo { "md" : "USD", // Moldova "mn" : "USD", // Mongolia "mm" : "MMK", // Myanmar - "ph" : "PHP", // Philippines "ru" : "USD", // Russian Federation "sg" : "SGD", // Singapore "tj" : "USD", // Tajikistan "th" : "THB", // Thailand "uz" : "USD", // Uzbekistan - "vn" : "VND", // Vietnam "default": "KRW" ] + + + private var secondarySendingCurrency: [String: String] = + [ + "vn" : "USD", // vietnam + "mn" : "MNT", // Mongolia + "lk" : "USD", // sri lanka + ] + + private var secondarySendingAmount: [String: String] = + [ + "vn" : "2000", // Vietnam + "lk" : "1000", // sri lanka + "mn" : "2000000", // Mongolia + ] func getFlag(for countryCode: String) -> UIImage? { @@ -129,6 +165,18 @@ class CountryInfo { func getDefaultSendingMoneyInKoreanWon() -> String? { return defaultSendingAmount["default"] } + + func doesCountryCodeHasDefined(country: String, currency: String) -> Bool { + return defaultSendingCurrency[country.lowercased()]?.contains(currency) ?? false + } + + func doesSecondaryOptiopsHasDefined(country: String, currency: String) -> Bool { + return secondarySendingCurrency[country.lowercased()]?.contains(currency) ?? false + } + + func getSecondarySendingAmount(for countryCode: String) -> String? { + return secondarySendingAmount[countryCode.lowercased()] + } } diff --git a/GMERemittance/Module/ExchangeRates/User Interface/View/ExchangeRatesViewController.swift b/GMERemittance/Module/ExchangeRates/User Interface/View/ExchangeRatesViewController.swift index cd78e3ee..375dd5e4 100644 --- a/GMERemittance/Module/ExchangeRates/User Interface/View/ExchangeRatesViewController.swift +++ b/GMERemittance/Module/ExchangeRates/User Interface/View/ExchangeRatesViewController.swift @@ -117,8 +117,6 @@ class ExchangeRatesViewController: UIViewController { didSet { self.setCurrencyLabel(currency: self.selectedExchageRateModel?.currency ?? "") self.setCountryFlag(countryCode: self.selectedExchageRateModel?.countryCode ?? "") -// self.reciepientTextField.text = "" -// calcBy = "c" collectionView.reloadData() DispatchQueue.main.async { self.reciepientTextField.resignFirstResponder() @@ -128,6 +126,7 @@ class ExchangeRatesViewController: UIViewController { } + // MARK: VC's Life cycle override func viewDidLoad() { super.viewDidLoad() @@ -188,7 +187,7 @@ class ExchangeRatesViewController: UIViewController { ApiConstants.senderCountryId : senderCountryId ?? "", ApiConstants.recieverCountryName: recieverCountryName ?? "" ] -// print(param) + // print(param) // todo if shouldShowLoading { self.showProgressHud() } @@ -241,7 +240,42 @@ class ExchangeRatesViewController: UIViewController { func countrySelected(model: [ExchangeRateModel]) { self.selectedExchageRateModel = model.first - self.calculateExchangeRate(nil) + + 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 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. } @@ -253,7 +287,7 @@ class ExchangeRatesViewController: UIViewController { 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!) @@ -262,7 +296,7 @@ class ExchangeRatesViewController: UIViewController { } } - + private func setCountryFlag(countryCode: String) { let flag = CountryInfo().getFlag(for: countryCode) @@ -292,9 +326,7 @@ class ExchangeRatesViewController: UIViewController { if let recievingAmount = CountryInfo().getDefaultSendingAmount(for: exchangeModel.countryCode ?? "") { self.setDefaultValuesForCountriesHavingDefaultValue(recievingAmount: recievingAmount, exchangeModel: exchangeModel) } - // else { - // setDefaultValuesForCountriesNotHavingDefaultValue() - // } + } @@ -367,7 +399,7 @@ class ExchangeRatesViewController: UIViewController { let newOffset = CGPoint.init(x: x, y: y + 150) scrollView.setContentOffset(newOffset, animated: true) } - + case reciepientTextField: break default: @@ -423,7 +455,7 @@ class ExchangeRatesViewController: UIViewController { func hideLoading() { self.hideProgressHud() } - + private func setupNavigation() { @@ -509,7 +541,7 @@ extension ExchangeRatesViewController: FetchCountryCurrencyInformation, getExcha extension ExchangeRatesViewController: UITextFieldDelegate { func textFieldDidEndEditing(_ textField: UITextField) { - self.calculateExchangeRate(nil) + self.calculateExchangeRate(nil) } }