Browse Source

notification raised after updateing balance

pull/1/head
ccr 6 years ago
parent
commit
abf1a87c0b
  1. 24
      GMERemittance/Module/Auto refund/AutoRefundsViewController.swift
  2. 6
      GMERemittance/Module/Auto refund/autoRefundService.swift
  3. 2
      GMERemittance/Module/PennyTestSubmit/User Interface/View/PennyTestSubmitViewController.swift
  4. 7
      GMERemittance/SideMenu/SideMenuViewController.swift

24
GMERemittance/Module/Auto refund/AutoRefundsViewController.swift

@ -63,6 +63,7 @@ class AutoRefundsViewController: UIViewController {
let amount = self.amountTextfield.text!
let minAmnt = self.autorefund?.minAmount ?? "0"
if amount.isEmpty {self.show(error: "add refund amount"); return}
if !isValidRefundable(amount: amount) {
self.show(error: "Amount cannot be minimum than \(Utility.getCommaSeperatedString(numberString: minAmnt) ?? "")")
return
@ -73,20 +74,37 @@ class AutoRefundsViewController: UIViewController {
let id = Utility.getMyId()
self.showProgressHud()
self.refund(amount: amount, userName: userName, chargeAmount: chargeAmt, userId: id, success: { (message) in
self.refund(amount: amount, userName: userName, chargeAmount: chargeAmt, userId: id, success: { (successMessage) in
self.hideProgressHud()
self.alertWithOk(message: message, title: "Success", okTitle: "Ok", style: UIAlertControllerStyle.alert, OkStyle: UIAlertActionStyle.default, okAction: {
self.alertWithOk(message: successMessage?.message, title: "Success", okTitle: "Ok", style: UIAlertControllerStyle.alert, OkStyle: UIAlertActionStyle.default, okAction: {
self.navigationController?.popViewController(animated: true)
self.updateBalance(value: successMessage)
})
}) { (error) in
self.hideProgressHud()
self.show(error: error.localizedDescription)
}
}
private func updateBalance(value: SuccessMessage?) {
let balance = value?.extra ?? ""
let yearlyLimits = value?.yearlyLimit ?? ""
UserDefaults.standard.set(yearlyLimits, forKey: UserKeys.yearlyLimit)
UserDefaults.standard.set(balance, forKey: UserKeys.availableBalance)
let userInfo = [SideMenuNavigationNotifications.availableBalance : balance]
NotificationCenter.default.post(name: self.getAvailableBalanceNotificationName(), object: nil, userInfo: userInfo)
}
func getAvailableBalanceNotificationName() -> Notification.Name {
return Notification.Name.init(rawValue: SideMenuNavigationNotifications.availableBalance)
}
private func isValidRefundable(amount: String) -> Bool {
let minRefundAmount = self.autorefund?.minAmount ?? "0"
let _minRefundAmount = self.autorefund?.minAmount ?? "0"
let minRefundAmount = _minRefundAmount.replacingOccurrences(of: ",", with: "")
print(minRefundAmount)
guard let amt = Double(amount), let minRefundAmt = Double(minRefundAmount) else {return false}
let result = amt > minRefundAmt
return result

6
GMERemittance/Module/Auto refund/autoRefundService.swift

@ -34,11 +34,11 @@ extension FetchAutoRefundInfo {
protocol RefundService: ApiServiceType {
func refund(amount: String, userName: String, chargeAmount: String, userId: String, success: @escaping (String) -> (), failure: @escaping (Error) -> ())
func refund(amount: String, userName: String, chargeAmount: String, userId: String, success: @escaping (SuccessMessage?) -> (), failure: @escaping (Error) -> ())
}
extension RefundService {
func refund(amount: String, userName: String, chargeAmount: String, userId: String, success: @escaping (String) -> (), failure: @escaping (Error) -> ()) {
func refund(amount: String, userName: String, chargeAmount: String, userId: String, success: @escaping (SuccessMessage?) -> (), failure: @escaping (Error) -> ()) {
let url = baseUrl + "refund/proceed"
let params = [
"Username": userName,
@ -51,7 +51,7 @@ extension RefundService {
let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""])
failure(error)
}else {
success(response.data?.message ?? "")
success(response.data)
}
}) { (error) in
failure(error)

2
GMERemittance/Module/PennyTestSubmit/User Interface/View/PennyTestSubmitViewController.swift

@ -129,7 +129,7 @@ class PennyTestSubmitViewController: UIViewController {
@IBAction func Verify(_ sender: UIButton) {
let customerId = Utility.getMyId()
let certNumber = self.verificationCodeTextField.text!
let certNumber = self.verificationCodeTextField.text!.removeSpacesTrailingPreceding()
if certNumber.isEmpty || certNumber.count != 4 {
self.alert(message: "Please enter valid verification code")
return

7
GMERemittance/SideMenu/SideMenuViewController.swift

@ -64,7 +64,9 @@ class SideMenuViewController: UIViewController {
}
private func setup() {
self.withdrawButton.isHidden = !Utility.pennyTestVerified()
let shouldShowWithdrawButton = Utility.pennyTestVerified() && Utility.isVerifiedUser()
self.withdrawButton.isHidden = !shouldShowWithdrawButton
self.view.backgroundColor = AppConstants.themeRedColor
self.roundedBgView.layer.cornerRadius = 20
self.labelBalance.text = "0"
@ -75,7 +77,8 @@ class SideMenuViewController: UIViewController {
@objc private func updateBalance(sender: Notification) {
let balance = sender.userInfo?[SideMenuNavigationNotifications.availableBalance] as? String
self.labelBalance.text = balance
self.withdrawButton.isHidden = !Utility.pennyTestVerified()
let shouldShowWithdrawButton = Utility.pennyTestVerified() && Utility.isVerifiedUser()
self.withdrawButton.isHidden = !shouldShowWithdrawButton
}

Loading…
Cancel
Save