|
|
@ -17,8 +17,21 @@ enum PaymentMode: String { |
|
|
|
case homeDelivery = "home" |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ExchangeRateViewControllerV2: UIViewController { |
|
|
|
|
|
|
|
struct ApiConstants { |
|
|
|
static let recieverCountryId = "pCountry" |
|
|
|
static let senderCurrency = "sCurrency" |
|
|
|
static let recieverCurrency = "pCurrency" |
|
|
|
static let senderAmount = "cAmount" |
|
|
|
static let recieverAmount = "pAmount" |
|
|
|
static let paymentMethod = "serviceType" |
|
|
|
static let calcBy = "calcBy" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@IBOutlet weak var collectionView: UICollectionView! |
|
|
|
@IBOutlet weak var exchangeBackground1: UIView! |
|
|
|
@IBOutlet weak var exchangeBackground2: UIView! |
|
|
@ -37,39 +50,35 @@ class ExchangeRateViewControllerV2: UIViewController { |
|
|
|
|
|
|
|
|
|
|
|
var countryListTapGuesture: UITapGestureRecognizer? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var selectedPaymentIndex: IndexPath = IndexPath.init(row: 0, section: 0) |
|
|
|
var nativeCountry: String? = "Vietnam" |
|
|
|
var calcBy = "" |
|
|
|
|
|
|
|
var nativeCountry: String? = "Nepal" |
|
|
|
|
|
|
|
var exchangeRateModels: [ExchangeRateModel] = [] { |
|
|
|
var exchangeRateModels: [ExchangeRateModel]? { |
|
|
|
didSet { |
|
|
|
// added default values |
|
|
|
if let defaultExchangeRate = self.exchangeRateModels.filter({ |
|
|
|
// added default label if there is native country |
|
|
|
if let defaultExchangeRate = self.exchangeRateModels?.filter({ |
|
|
|
($0.country ?? "").lowercased() == (self.nativeCountry ?? "").lowercased() |
|
|
|
}).first { |
|
|
|
// there is native country and defaultExchangeRate is the information for that country |
|
|
|
let currency = defaultExchangeRate.currency |
|
|
|
let flag = CountryInfo().getFlag(for: defaultExchangeRate.countryCode ?? "") |
|
|
|
self.countryCodeLabel.text = currency?.uppercased() |
|
|
|
self.countryFlagImage.image = flag |
|
|
|
// 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.populateDefaultAmounts() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var selectedExchageRateModel: ExchangeRateModel? { |
|
|
|
didSet { |
|
|
|
self.countryCodeLabel.text = (self.selectedExchageRateModel?.currency ?? "").uppercased() |
|
|
|
if let flag = CountryInfo().getFlag(for: self.selectedExchageRateModel?.countryCode ?? "") { |
|
|
|
self.countryFlagImage.image = flag |
|
|
|
} |
|
|
|
self.setCurrencyLabel(currency: self.selectedExchageRateModel?.currency ?? "") |
|
|
|
self.setCountryFlag(countryCode: self.selectedExchageRateModel?.countryCode ?? "") |
|
|
|
self.collectionView.reloadData() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Life Cycle |
|
|
|
override func viewDidLoad() { |
|
|
|
super.viewDidLoad() |
|
|
@ -80,7 +89,7 @@ class ExchangeRateViewControllerV2: UIViewController { |
|
|
|
createTestModel() |
|
|
|
// todo: show default native country and falg |
|
|
|
// Do any additional setup after loading the view. |
|
|
|
populateDefaultAmounts() |
|
|
|
// populateDefaultAmounts() |
|
|
|
|
|
|
|
fetchExchangeRateInformation() |
|
|
|
} |
|
|
@ -99,25 +108,35 @@ class ExchangeRateViewControllerV2: UIViewController { |
|
|
|
let reciepientAmount = self.reciepientTextField.text! |
|
|
|
print("sender textfield \(senderAmount)") |
|
|
|
print("reciepientTextfield \(reciepientAmount)") |
|
|
|
let recipientCurrency = self.selectedExchageRateModel?.currency ?? "" |
|
|
|
|
|
|
|
let param: [String: Any] = |
|
|
|
[ |
|
|
|
"cAmt" : senderAmount, |
|
|
|
"pAmt" : reciepientAmount, |
|
|
|
"cCurrency" : "KRW", |
|
|
|
"pCurrency" : recipientCurrency |
|
|
|
] |
|
|
|
let recipientCurrency = self.selectedExchageRateModel?.currency |
|
|
|
|
|
|
|
// call calculate( ... ) function |
|
|
|
// todo send to api for calculation |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func calculate(senderAmt: String?, senderCurrency: String?, recieverAmt: String?, recieverCurrency: String?, recieverCountryId: String?, paymentMethod: String?, calcBy: String? ) { |
|
|
|
|
|
|
|
let param: [String: String] = |
|
|
|
[ |
|
|
|
ApiConstants.senderAmount : senderAmt ?? "", |
|
|
|
ApiConstants.senderCurrency : senderCurrency ?? "", |
|
|
|
ApiConstants.recieverAmount : recieverAmt ?? "", |
|
|
|
ApiConstants.recieverCurrency : recieverCurrency ?? "", |
|
|
|
ApiConstants.recieverCountryId : recieverCountryId ?? "", |
|
|
|
ApiConstants.paymentMethod: paymentMethod ?? "", |
|
|
|
ApiConstants.calcBy : calcBy ?? "" |
|
|
|
] |
|
|
|
print(param) |
|
|
|
// todo |
|
|
|
// call api with these params |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@objc func showCountryList(_ sender: UITapGestureRecognizer) { |
|
|
|
print("show Country List") |
|
|
|
let viewcontroller = UIStoryboard.init(name: "TableViewPicker", bundle: nil).instantiateViewController(withIdentifier: "TablePickerViewController") as! TablePickerViewController |
|
|
|
viewcontroller.data = self.exchangeRateModels |
|
|
|
viewcontroller.data = self.exchangeRateModels ?? [] |
|
|
|
viewcontroller.type = TablePickerViewTitle.country |
|
|
|
viewcontroller.doneAction = self.countrySelected |
|
|
|
// viewcontroller.defaultSelectedData = [self.selectedExchageRateModel] |
|
|
@ -132,26 +151,53 @@ class ExchangeRateViewControllerV2: UIViewController { |
|
|
|
// show country with flag. |
|
|
|
} |
|
|
|
|
|
|
|
private func textChanged(sender: UITextField) { |
|
|
|
switch sender { |
|
|
|
case senderTextField: |
|
|
|
self.calcBy = "c" |
|
|
|
case reciepientTextField: |
|
|
|
self.calcBy = "p" |
|
|
|
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.nativeCountry else {return} |
|
|
|
// todo: native country cha bhane tesko CountryInfo class ma defaullt value cha ki chaina |
|
|
|
// todo: native country cha bhane tesko CountryInfo class ma defaullt value cha ki chaina herne |
|
|
|
// CountryInfo class ma defaullt value cha bhane tyo value rakhera second api hit garna paryo ani aako data dekhaune |
|
|
|
// natra bhane tesko 1000000 kwr ko native ma kati huncha teti populate garaune |
|
|
|
guard let exchangeModel = self.exchangeRateModels.filter({ |
|
|
|
guard let exchangeModel = self.exchangeRateModels?.filter({ |
|
|
|
$0.country?.lowercased() == nativeCountry.lowercased() |
|
|
|
}).first else {return} |
|
|
|
|
|
|
|
if let defaultValue = CountryInfo().getDefaultSendingAmount(for: exchangeModel.countryCode ?? "") { |
|
|
|
// default value cha so aaba tuyo ansar le populate garna paruyo |
|
|
|
if let defaultCurrency = CountryInfo().getDefaultSendingCurrency(for: exchangeModel.countryCode ?? "") { |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
// chaina so tyo aansar le jana paro |
|
|
|
} |
|
|
|
self.selectedExchageRateModel = exchangeModel |
|
|
|
|
|
|
|
|
|
|
|
// if let defaultValue = CountryInfo.getDefaultSendingAmount(<#T##CountryInfo#>) |
|
|
|
// if there is no default amount, then we have to calculate from korean won. so guard ma rakhna thik nahola, yo case hereko chaina |
|
|
|
guard let recievingAmount = CountryInfo().getDefaultSendingAmount(for: exchangeModel.countryCode ?? ""), |
|
|
|
let recievingCurrency = CountryInfo().getDefaultSendingCurrency(for: exchangeModel.countryCode ?? ""), |
|
|
|
let recievingCountryId = exchangeModel.countryId, |
|
|
|
let paymentMethod = self.selectedExchageRateModel?.availableServices?.elementAt(index: selectedPaymentIndex.row) |
|
|
|
else { |
|
|
|
// do something if you have to do |
|
|
|
return |
|
|
|
} |
|
|
|
self.calcBy = "p" |
|
|
|
|
|
|
|
|
|
|
|
self.calculate(senderAmt: nil, senderCurrency: "KRW", recieverAmt: recievingAmount, recieverCurrency: recievingCurrency, recieverCountryId: recievingCountryId, paymentMethod: paymentMethod.id, calcBy: calcBy) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -199,7 +245,6 @@ class ExchangeRateViewControllerV2: UIViewController { |
|
|
|
|
|
|
|
|
|
|
|
private func setupNavigation() { |
|
|
|
|
|
|
|
var backBtnImage = #imageLiteral(resourceName: "backIconBlack") |
|
|
|
backBtnImage = backBtnImage.withRenderingMode(UIImageRenderingMode.alwaysOriginal) |
|
|
|
self.navigationController!.navigationBar.backIndicatorImage = backBtnImage |
|
|
@ -269,50 +314,68 @@ extension ExchangeRateViewControllerV2: UICollectionViewDataSource { |
|
|
|
extension ExchangeRateViewControllerV2 { |
|
|
|
func createTestModel() { |
|
|
|
let service1 = PaymentServiceType() |
|
|
|
service1.id = "1" |
|
|
|
service1.type = "cash" |
|
|
|
service1.subtitle = "1 business day" |
|
|
|
|
|
|
|
let service2 = PaymentServiceType() |
|
|
|
service2.id = "2" |
|
|
|
service2.type = "bank" |
|
|
|
service2.subtitle = "2 hour" |
|
|
|
|
|
|
|
let service3 = PaymentServiceType() |
|
|
|
service3.id = "3" |
|
|
|
service3.type = "home" |
|
|
|
service3.subtitle = "5 business day" |
|
|
|
|
|
|
|
let model = ExchangeRateModel() |
|
|
|
model.country = "Nepal" |
|
|
|
model.countryCode = "Np" |
|
|
|
model.countryId = "1" |
|
|
|
model.currency = "NRS" |
|
|
|
model.availableServices = [service2, service1] |
|
|
|
|
|
|
|
let model1 = ExchangeRateModel() |
|
|
|
model1.country = "Kore" |
|
|
|
model1.country = "Korea" |
|
|
|
model1.countryCode = "krw" |
|
|
|
model1.currency = "NRS" |
|
|
|
model1.countryId = "2" |
|
|
|
model1.currency = "KRW" |
|
|
|
model1.availableServices = [service2, service1, service3] |
|
|
|
|
|
|
|
let model2 = ExchangeRateModel() |
|
|
|
model2.country = "India" |
|
|
|
model2.countryCode = "in" |
|
|
|
model2.currency = "NRS" |
|
|
|
model2.currency = "INR" |
|
|
|
model2.countryId = "3" |
|
|
|
model2.availableServices = [service2] |
|
|
|
|
|
|
|
let model3 = ExchangeRateModel() |
|
|
|
model3.country = "China" |
|
|
|
model3.countryCode = "cn" |
|
|
|
model3.currency = "NRS" |
|
|
|
model3.currency = "CN" |
|
|
|
model3.countryId = "4" |
|
|
|
model3.availableServices = [service2, service1, service3] |
|
|
|
|
|
|
|
let model4 = ExchangeRateModel() |
|
|
|
model4.country = "Cambodia" |
|
|
|
model4.countryCode = "Kh" |
|
|
|
model4.currency = "NRS" |
|
|
|
model4.currency = "USD" |
|
|
|
model4.countryId = "5" |
|
|
|
model4.availableServices = [service2, service1, service3] |
|
|
|
|
|
|
|
self.exchangeRateModels = [model, model1, model2, model3, model4] |
|
|
|
let model5 = ExchangeRateModel() |
|
|
|
model5.country = "Vietnam" |
|
|
|
model5.countryCode = "Vn" |
|
|
|
model5.currency = "VND" |
|
|
|
model5.countryId = "6" |
|
|
|
model5.availableServices = [service2, service1, service3] |
|
|
|
|
|
|
|
self.exchangeRateModels = [model, model1, model2, model3, model4, model5] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extension ExchangeRateViewControllerV2: FetchCountryCurrencyInformation {} |
|
|
|
|