[iOS] handle auth error on paid route purchase validation

This commit is contained in:
Aleksey Belouosv 2018-11-29 18:30:24 +03:00 committed by Olesia Bolovintseva
parent c818aac440
commit 0962d95289
3 changed files with 33 additions and 15 deletions

View file

@ -111,20 +111,7 @@ final class CatalogWebViewController: WebViewController {
}
override func willLoadUrl(_ decisionHandler: @escaping (Bool) -> Void) {
pendingTransactionsHandler.handlePendingTransactions { [weak self] (status) in
switch status {
case .none:
fallthrough
case .success:
decisionHandler(true)
break
case .error:
MWMAlertViewController.activeAlert().presentInfoAlert(L("title_error_downloading_bookmarks"),
text: L("failed_purchase_support_message"))
decisionHandler(false)
self?.loadingIndicator.stopAnimating()
}
}
handlePendingTransactions { decisionHandler($0) }
}
override func webView(_ webView: WKWebView,
@ -164,6 +151,36 @@ final class CatalogWebViewController: WebViewController {
loadingIndicator.stopAnimating()
}
private func handlePendingTransactions(completion: @escaping (Bool) -> Void) {
pendingTransactionsHandler.handlePendingTransactions { [weak self] (status) in
switch status {
case .none:
fallthrough
case .success:
completion(true)
case .error:
MWMAlertViewController.activeAlert().presentInfoAlert(L("title_error_downloading_bookmarks"),
text: L("failed_purchase_support_message"))
completion(false)
self?.loadingIndicator.stopAnimating()
case .needAuth:
if let s = self {
s.signup(anchor: s.toolbar, onComplete: {
if $0 {
s.handlePendingTransactions(completion: completion)
} else {
MWMAlertViewController.activeAlert().presentInfoAlert(L("title_error_downloading_bookmarks"),
text: L("failed_purchase_support_message"))
completion(false)
s.loadingIndicator.stopAnimating()
}
})
}
break;
}
}
}
private func parseUrl(_ url: URL) -> CatalogCategoryInfo? {
guard let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) else { return nil }
guard let components = urlComponents.queryItems?.reduce(into: [:], { $0[$1.name] = $1.value })

View file

@ -3,6 +3,7 @@ enum PendingTransactionsStatus: Int {
case none
case success
case error
case needAuth
}
@objc

View file

@ -23,7 +23,7 @@ final class PendingTransactionsHandler: IPendingTransactionsHandler {
case .error:
completion(.error)
case .authError:
break // TODO(@beloal)
completion(.needAuth)
}
}
break