forked from organicmaps/organicmaps
[iOS] handle auth error on paid route purchase validation
This commit is contained in:
parent
c818aac440
commit
0962d95289
3 changed files with 33 additions and 15 deletions
|
@ -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 })
|
||||
|
|
|
@ -3,6 +3,7 @@ enum PendingTransactionsStatus: Int {
|
|||
case none
|
||||
case success
|
||||
case error
|
||||
case needAuth
|
||||
}
|
||||
|
||||
@objc
|
||||
|
|
|
@ -23,7 +23,7 @@ final class PendingTransactionsHandler: IPendingTransactionsHandler {
|
|||
case .error:
|
||||
completion(.error)
|
||||
case .authError:
|
||||
break // TODO(@beloal)
|
||||
completion(.needAuth)
|
||||
}
|
||||
}
|
||||
break
|
||||
|
|
Loading…
Add table
Reference in a new issue