Manos Chorianopoulos

update WalletViewController with getCouponList

......@@ -28,14 +28,12 @@ import UIKit
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var activeCodeImage: UIImageView!
public var coupons:Array<swiftApi.CouponItemModel> = []
public var coupons:Array<swiftApi.CouponItemModel> = swiftApi().getCouponList()
public var dfyCoupons:Array<swiftApi.ActiveDFYCouponModel> = swiftApi().getActiveDFYCoupons()
public override func viewDidLoad() {
super.viewDidLoad()
getCouponsRequest()
setBackButton()
setNavigationTitle("For You")
......@@ -98,9 +96,12 @@ import UIKit
couponEarnView.layer.shadowOpacity = 1.0
couponEarnView.layer.shadowRadius = 3.0
var totalCouponDiscount = coupons.reduce(0) { $0 + (Float($1.discount ?? "") ?? 0) }
totalCouponDiscount = Float(round(100 * totalCouponDiscount) / 100)
let totalCouponDiscountString = String(format: "%.2f", totalCouponDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
couponEarnLabel.text = ""
couponEarnAmountLabel.text = ""
couponEarnLabel.text = "Μέχρι τώρα έχεις κερδίσει " + totalCouponDiscountString + "€ σε προσφορές από " + String(coupons.count) + " κουπόνια!"
couponEarnAmountLabel.text = totalCouponDiscountString + "€"
activeCodeView.layer.cornerRadius = 5.0
activeCodeView.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.16).cgColor
......@@ -144,32 +145,6 @@ import UIKit
}
}
// MARK: - API Functions
func getCouponsRequest() {
swiftApi().getCouponsAsync(getCouponsCallback)
}
func getCouponsCallback (_ couponsData: Array<swiftApi.CouponItemModel>?) -> Void {
if (couponsData != nil) {
let activeCouponData = swiftApi().filterActiveCoupons(couponsData ?? [])
self.coupons = activeCouponData
DispatchQueue.main.async {
self.tableView.reloadData()
var totalCouponDiscount = self.coupons.reduce(0) { $0 + (Float($1.discount ?? "") ?? 0) }
totalCouponDiscount = Float(round(100 * totalCouponDiscount) / 100)
let totalCouponDiscountString = String(format: "%.2f", totalCouponDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
self.couponEarnLabel.text = "Μέχρι τώρα έχεις κερδίσει " + totalCouponDiscountString + "€ σε προσφορές από " + String(activeCouponData.count) + " κουπόνια!"
self.couponEarnAmountLabel.text = totalCouponDiscountString + "€"
}
} else {
self.coupons = []
}
}
// MARK: - Actions
@IBAction func qustionnaireButtonAction(_ sender: Any) {
swiftApi().openQuestionnaire(self);
......