Skip to content

Commit

Permalink
Merge pull request #80 from AppSci/release/1.0.12
Browse files Browse the repository at this point in the history
update after test review
  • Loading branch information
yehorkyrylov authored Dec 23, 2022
2 parents 599fbbc + db71ebd commit 5c70746
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
13 changes: 1 addition & 12 deletions Sources/PandaSDK/ConfiguredPanda.swift
Original file line number Diff line number Diff line change
Expand Up @@ -544,18 +544,7 @@ final public class Panda: PandaProtocol, ObserverSupport {
pandaLog("onViewDidAppear \(String(describing: screenName)) \(String(describing: screenId))")
self?.send(event: .screenShowed(screenId: screenId ?? "", screenName: screenName ?? "", source: entryPoint, course: course))
}
viewModel.onDidFinishLoading = { [weak self] screenId, screenName, course, view in
self?.appStoreClient.isNeedToHideTrialPurchasesOnPandaScreen { result in
switch result {
case let .success(isNeedToHide):
if isNeedToHide {
view.hideTrialPurchases()
}

case let .failure(error):
pandaLog(error.localizedDescription)
}
}
viewModel.onDidFinishLoading = { [weak self] screenId, screenName, course in

pandaLog("onDidFinishLoading \(String(describing: screenName)) \(String(describing: screenId))")
self?.send(event: .screenLoaded(screenId: screenId ?? "", screenName: screenName ?? "", source: entryPoint))
Expand Down
49 changes: 38 additions & 11 deletions Sources/PandaSDK/Views/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ final class WebViewController: UIViewController, WKScriptMessageHandler {
if let e = error {
pandaLog("error: \(e)")
} else if self.viewModel?.screenData.id.string == "89a4b8c2-cb7b-45a5-a8df-f5a8ffd32618" {
self.viewModel?.onDidFinishLoading?(self.viewModel?.screenData.id.string, "Tutors-Phone-Collection-v2-Schedule", (self.viewModel?.payload?.data?["course"] as? String), self)
self.viewModel?.onDidFinishLoading?(self.viewModel?.screenData.id.string, "Tutors-Phone-Collection-v2-Schedule", (self.viewModel?.payload?.data?["course"] as? String))

}
if let res = result {
Expand All @@ -352,22 +352,24 @@ final class WebViewController: UIViewController, WKScriptMessageHandler {

func didFinishLoading(_ url: URL?) {
guard let url = url else {
viewModel?.onDidFinishLoading?(viewModel?.screenData.id.string, viewModel?.screenData.name, (viewModel?.payload?.data?["course"] as? String), self)
viewModel?.onDidFinishLoading?(viewModel?.screenData.id.string, viewModel?.screenData.name, (viewModel?.payload?.data?["course"] as? String))
return
}
let urlComps = URLComponents(url: url, resolvingAgainstBaseURL: true)
let screenID = urlComps?.queryItems?.first(where: { $0.name == "screen_id" })?.value ?? viewModel?.screenData.id.string
let screenName = urlComps?.queryItems?.first(where: { $0.name == "screen_name" })?.value ?? viewModel?.screenData.name
viewModel?.onDidFinishLoading?(screenID, screenName, (viewModel?.payload?.data?["course"] as? String), self)
viewModel?.onDidFinishLoading?(screenID, screenName, (viewModel?.payload?.data?["course"] as? String))
}

func handleScreenDidLoad() {
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(failedByTimeOut), object: nil)

setPayload()

wv.alpha = 1
loadingIndicator.stopAnimating()
hideTrialPurchasesIfNeeded { [weak self] in
self?.wv.alpha = 1
self?.loadingIndicator.stopAnimating()
}

pandaLog("html did load \(Date().timeIntervalSince1970) \(Date())")
}

Expand Down Expand Up @@ -654,12 +656,33 @@ extension WebViewController {
}
}

func hideTrialPurchases() {
DispatchQueue.main.async {
self.wv.evaluateJavaScript("removeTrialUi()") { _, error in
if let error = error {
pandaLog(error.localizedDescription)
func hideTrialPurchasesIfNeeded(actionAfter: @escaping (() -> Void)) {
guard
let panda = Panda.shared as? Panda
else {
actionAfter()
return
}

panda.appStoreClient.isNeedToHideTrialPurchasesOnPandaScreen { result in
switch result {
case let .success(isNeedToHide):
switch isNeedToHide {
case true:
DispatchQueue.main.async { [weak self] in
self?.wv.evaluateJavaScript(Constants.hideTrialJSFunctionName) { _, error in
if let error = error {
pandaLog(error.localizedDescription)
}
actionAfter()
}
}
case false:
actionAfter()
}
case let .failure(error):
pandaLog(error.localizedDescription)
actionAfter()
}
}
}
Expand Down Expand Up @@ -823,4 +846,8 @@ extension WebViewController {
case onPolicy
case onSubscriptionTerms
}

private enum Constants {
static let hideTrialJSFunctionName = "removeTrialUi"
}
}
4 changes: 2 additions & 2 deletions Sources/PandaSDK/Views/WebViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protocol WebViewModelProtocol {
var onApplePayPurchase: ((_ pandaID: String?, _ source: String, _ screenId: String, _ screenName: String, _ viewController: WebViewController) -> Void)! { get set }
var onViewWillAppear: ((_ screenId: String?, _ screenName: String?) -> Void)? { get set }
var onViewDidAppear: ((_ screenId: String?, _ screenName: String?, _ course: String?) -> Void)? { get set }
var onDidFinishLoading: ((_ screenId: String?, _ screenName: String?, _ course: String?, _ viewController: WebViewController) -> Void)? { get set }
var onDidFinishLoading: ((_ screenId: String?, _ screenName: String?, _ course: String?) -> Void)? { get set }
var onBillingIssue: ((_ viewController: WebViewController) -> Void)? { get set }
var onRestorePurchase: ((_ viewController: WebViewController, _ screenId: String?, _ screenName: String?) -> Void)? { get set }
var onTerms: (() -> Void)? { get set }
Expand All @@ -41,7 +41,7 @@ final class WebViewModel: WebViewModelProtocol {
@objc var onApplePayPurchase: ((String?, String, String, String, WebViewController) -> Void)!
var onViewWillAppear: ((_ screenId: String?, _ screenName: String?) -> Void)?
var onViewDidAppear: ((_ screenId: String?, _ screenName: String?, _ course: String?) -> Void)?
var onDidFinishLoading: ((_ screenId: String?, _ screenName: String?, _ course: String?, _ viewController: WebViewController) -> Void)?
var onDidFinishLoading: ((_ screenId: String?, _ screenName: String?, _ course: String?) -> Void)?
var onBillingIssue: ((_ viewController: WebViewController) -> Void)?
var onRestorePurchase: ((_ viewController: WebViewController, _ screenId: String?, _ screenName: String?) -> Void)?
var onTerms: (() -> Void)?
Expand Down

0 comments on commit 5c70746

Please sign in to comment.