Skip to content

Commit

Permalink
refactor: address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedbashir committed Jun 24, 2024
1 parent 7d2e834 commit 8b448b5
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 84 deletions.
2 changes: 1 addition & 1 deletion Core/Core/Configuration/Config/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ extension Config: ConfigProtocol {
}

public var ecommerceURL: String? {
return string(for: ConfigKeys.ecommerceURL.rawValue)
string(for: ConfigKeys.ecommerceURL.rawValue)
}
}

Expand Down
5 changes: 3 additions & 2 deletions Core/Core/CourseUpgrade/CourseUpgradeEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ enum CourseUpgradeEndpoint: EndPointType {
}

var baseURL: String {
return CourseUpgradeHandler.ecommerceURL
CourseUpgradeHandler.ecommerceURL
}

var task: HTTPTask {
Expand All @@ -65,7 +65,8 @@ enum CourseUpgradeEndpoint: EndPointType {
basketID: basketID,
price: price,
currencyCode: currencyCode,
receipt: receipt):
receipt: receipt
):

let params: Parameters = [
"basket_id": basketID,
Expand Down
30 changes: 10 additions & 20 deletions Core/Core/CourseUpgrade/CourseUpgradeHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public class CourseUpgradeHandler: CourseUpgradeHandlerProtocol {
helper.handleCourseUpgrade(
upgradeHadler: self,
state: upgradeState,
delegate: nil)
delegate: nil
)
completion?(state)
}
}
Expand All @@ -69,10 +70,11 @@ public class CourseUpgradeHandler: CourseUpgradeHandlerProtocol {
}
}

public init(config: ConfigProtocol,
interactor: CourseUpgradeInteractorProtocol,
storeKitHandler: StoreKitHandlerProtocol,
helper: CourseUpgradeHelperProtocol
public init(
config: ConfigProtocol,
interactor: CourseUpgradeInteractorProtocol,
storeKitHandler: StoreKitHandlerProtocol,
helper: CourseUpgradeHelperProtocol
) {
self.interactor = interactor
self.storeKitHandler = storeKitHandler
Expand Down Expand Up @@ -127,11 +129,7 @@ public class CourseUpgradeHandler: CourseUpgradeHandlerProtocol {
await checkout(basketID: basketID, sku: sku)

} catch let error {
if error.isInternetError {

} else {
state = .error(.basketError(error))
}
state = .error(.basketError(error))
}
}

Expand All @@ -154,11 +152,7 @@ public class CourseUpgradeHandler: CourseUpgradeHandlerProtocol {
}

} catch let error {
if error.isInternetError {

} else {
state = .error(.checkoutError(error))
}
state = .error(.checkoutError(error))
}
}

Expand Down Expand Up @@ -192,11 +186,7 @@ public class CourseUpgradeHandler: CourseUpgradeHandlerProtocol {
state = .complete

} catch let error {
if error.isInternetError {

} else {
state = .error(.verifyReceiptError(error))
}
state = .error(.verifyReceiptError(error))
}
}

Expand Down
55 changes: 30 additions & 25 deletions Core/Core/CourseUpgrade/CourseUpgradeHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public class CourseUpgradeHelper: CourseUpgradeHelperProtocol {
case .success(let courseID, let blockID):
helperModel = CourseUpgradeHelperModel(courseID: courseID, blockID: blockID, screen: screen)
if upgradeHadler.upgradeMode == .userInitiated {
removeLoader(success: true, removeView: true)
removeLoader(success: true, shouldRemoveView: true)
postSuccessNotification()
} else {
showSilentRefreshAlert()
Expand Down Expand Up @@ -170,7 +170,7 @@ public class CourseUpgradeHelper: CourseUpgradeHelperProtocol {
shouldRemove = true
}

removeLoader(success: false, removeView: shouldRemove)
removeLoader(success: false, shouldRemoveView: shouldRemove)

default:
break
Expand Down Expand Up @@ -226,7 +226,7 @@ public class CourseUpgradeHelper: CourseUpgradeHelperProtocol {
}

extension CourseUpgradeHelper {
func showSuccess() {
func trackAndResetOnSuccess() {
analytics.trackCourseUpgradeSuccess(
courseID: courseID ?? "",
blockID: blockID,
Expand Down Expand Up @@ -338,7 +338,7 @@ extension CourseUpgradeHelper {
case .verify, .complete:
return .execute
default:
return .unknown
return .unknown
}
}

Expand All @@ -360,21 +360,21 @@ extension CourseUpgradeHelper {

public func removeLoader(
success: Bool? = false,
removeView: Bool? = false,
shouldRemoveView: Bool? = false,
completion: (() -> Void)? = nil
) {
self.completion = completion
if success == true {
helperModel = nil
}

if removeView == true {
if shouldRemoveView == true {
Task {@MainActor in
await router.hideUpgradeLoaderView(animated: true)
helperModel = nil

if success == true {
showSuccess()
trackAndResetOnSuccess()
} else {
showError()
}
Expand Down Expand Up @@ -407,30 +407,35 @@ extension CourseUpgradeHelper {
self?.reset()
}
)

router.presentNativeAlert(
title: CoreLocalization.CourseUpgrade.SuccessAlert.silentAlertTitle,
message: CoreLocalization.CourseUpgrade.SuccessAlert.silentAlertMessage,
actions: actions
)
}

public func showRestorePurchasesAlert() {
guard let topController = UIApplication.topViewController() else { return }
let alertController = UIAlertController().showAlert(
withTitle: CoreLocalization.CourseUpgrade.Restore.alertTitle,
message: CoreLocalization.CourseUpgrade.Restore.alertMessage,
onViewController: topController) { _, _, _ in }

alertController.addButton(
withTitle: CoreLocalization.CourseUpgrade.FailureAlert.getHelp) { [weak self] _ in
var actions: [UIAlertAction] = []

actions.append(
UIAlertAction(
title: CoreLocalization.CourseUpgrade.FailureAlert.getHelp,
style: .default
) { [weak self] _ in
self?.launchEmailComposer(errorMessage: "Error: restore_purchases")
self?.trackUpgradeErrorAction(errorAction: .emailSupport, alertType: .restore)
}

alertController.addButton(withTitle: CoreLocalization.close, style: .default) { [weak self] _ in
self?.trackUpgradeErrorAction(errorAction: .close, alertType: .restore)
}
)

actions.append(
UIAlertAction(
title: CoreLocalization.close,
style: .default
) { [weak self] _ in
self?.trackUpgradeErrorAction(errorAction: .close, alertType: .restore)
}
)

router.presentNativeAlert(
title: CoreLocalization.CourseUpgrade.Restore.alertTitle,
message: CoreLocalization.CourseUpgrade.Restore.alertMessage,
actions: actions
)
}
}

Expand Down
2 changes: 0 additions & 2 deletions Core/Core/CourseUpgrade/StorekitHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public class StorekitHandler: NSObject, StoreKitHandlerProtocol {
switch purchase.transaction.transactionState {
case .purchased, .restored:
if purchase.needsFinishTransaction {
// Deliver content from server, then:
// SwiftyStoreKit.finishTransaction(purchase.transaction)
self?.purchases[purchase.productId] = purchase
}
default:
Expand Down
3 changes: 2 additions & 1 deletion Core/Core/CourseUpgrade/View/UpgradeInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public struct UpgradeInfoView<Content>: View where Content: View {
leftImage: buttonImage,
imagesStyle: .attachedToText,
isTitleTracking: false,
isLimitedOnPad: false)
isLimitedOnPad: false
)
.opacity(shouldHideButton ? 0 : 1)
.disabled(viewModel.isLoading)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public class UpgradeInfoViewModel: ObservableObject {
self.interactiveDismissDisabled = false
}
default:
print("Upgrade state changed: \(state)")
debugLog("Upgrade state changed: \(state)")
}
}
)
Expand Down
16 changes: 10 additions & 6 deletions Core/Core/Extensions/UIAlertController+BlockActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public extension UIAlertController {
viewController: controller,
title: title,
message: message,
preferredStyle: preferredStyle
, cancelButtonTitle: cancelButtonTitle,
preferredStyle: preferredStyle,
cancelButtonTitle: cancelButtonTitle,
destructiveButtonTitle: destructiveButtonTitle,
otherButtonsTitle: otherButtonsTitle,
tapBlock: tapBlock
Expand Down Expand Up @@ -78,7 +78,8 @@ public extension UIAlertController {
if let tap = tapBlock {
tap(controller, action, cancelButtonIndex)
}
})
}
)
controller.addAction(cancelAction)
}

Expand All @@ -90,7 +91,8 @@ public extension UIAlertController {
if let tap = tapBlock {
tap(controller, action, destructiveButtonIndex)
}
})
}
)
controller.addAction(destructiveAction)
}

Expand All @@ -102,7 +104,8 @@ public extension UIAlertController {
if let tap = tapBlock {
tap(controller, action, destructiveButtonIndex)
}
})
}
)
controller.addAction(otherAction)
}
}
Expand Down Expand Up @@ -208,7 +211,8 @@ public extension UIAlertController {
if let tap = actionBlock {
tap(action)
}
})
}
)
addAction(alertAction)
}

Expand Down
2 changes: 1 addition & 1 deletion Core/Core/Network/EndPointType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public protocol EndPointType {

public extension EndPointType {
var baseURL: String {
return ""
""
}
}
7 changes: 5 additions & 2 deletions Core/Core/View/Base/SnackBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ public struct SnackBarView: View {
.accessibilityIdentifier("snackbar_button")
}

}.shadowCardStyle(bgColor: bgColor,
textColor: Theme.Colors.white)
}
.shadowCardStyle(
bgColor: bgColor,
textColor: Theme.Colors.white
)
.padding(.bottom, 10)
}
}
Expand Down
8 changes: 4 additions & 4 deletions Course/Course/Data/Model/Data_CourseOutlineResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ public extension DataLayer {
certificate = try values.decode(Certificate.self, forKey: .certificate)
org = try values.decode(String.self, forKey: .org)
isSelfPaced = try values.decode(Bool.self, forKey: .isSelfPaced)
courseModes = try values.decode([CourseMode].self, forKey: .courseModes)
enrollmentDetails = try values.decode(EnrollmentDetail.self, forKey: .enrollmentDetails)
courseStart = try values.decode(String.self, forKey: .courseStart)
coursewareAccessDetails = try values.decode(CoursewareAccessDetails.self, forKey: .coursewareAccessDetails)
courseModes = try? values.decode([CourseMode].self, forKey: .courseModes)
enrollmentDetails = try? values.decode(EnrollmentDetail.self, forKey: .enrollmentDetails)
courseStart = try? values.decode(String.self, forKey: .courseStart)
coursewareAccessDetails = try? values.decode(CoursewareAccessDetails.self, forKey: .coursewareAccessDetails)
courseProgress = try? values.decode(DataLayer.CourseProgress.self, forKey: .courseProgress)
populateCourseSKU()
}
Expand Down
11 changes: 6 additions & 5 deletions Dashboard/Dashboard/Data/DashboardRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ public class DashboardRepository: DashboardRepositoryProtocol {
private let persistence: DashboardPersistenceProtocol
private let serverConfig: ServerConfigProtocol

public init(api: API,
storage: CoreStorage,
config: ConfigProtocol,
persistence: DashboardPersistenceProtocol,
serverConfig: ServerConfigProtocol
public init(
api: API,
storage: CoreStorage,
config: ConfigProtocol,
persistence: DashboardPersistenceProtocol,
serverConfig: ServerConfigProtocol
) {
self.api = api
self.storage = storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ extension ListDashboardViewModel {
courseID: inprogressIAP.courseID,
pacing: inprogressIAP.pacing,
screen: .dashboard,
flowType: .silent)
flowType: .silent
)

await upgradehandler.upgradeCourse(
sku: inprogressIAP.sku,
Expand Down
8 changes: 4 additions & 4 deletions OpenEdX/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -955,15 +955,15 @@ extension Router {

@MainActor
public func showRestoreProgressView() {
let unlockView = RestoreInProgressView()
let controller = UIHostingController(rootView: unlockView)

let unlockView = RestoreInProgressView()
let controller = UIHostingController(rootView: unlockView)
controller.view.frame = CGRect(x: 0,
y: 0,
width: UIScreen.main.bounds.width,
height: UIScreen.main.bounds.height)
controller.view.backgroundColor = .black.withAlphaComponent(0.8)
controller.view.tag = 10010
controller.view.tag = 10010
UIApplication.shared.window?.addSubview(controller.view)
}

Expand Down
Loading

0 comments on commit 8b448b5

Please sign in to comment.