blockchainethereumblockchain-walleterc20erc721walletxdaidappdecentralizederc1155erc875iosswifttokens
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
2.1 KiB
56 lines
2.1 KiB
// Copyright SIX DAY LLC. All rights reserved.
|
|
|
|
import Foundation
|
|
import UIKit
|
|
import Result
|
|
import MBProgressHUD
|
|
import SafariServices
|
|
|
|
enum ConfirmationError: LocalizedError {
|
|
case cancel
|
|
}
|
|
|
|
extension UIViewController {
|
|
func displaySuccess(title: String? = .none, message: String? = .none) {
|
|
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
|
|
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
|
|
present(alert, animated: true, completion: nil)
|
|
}
|
|
|
|
func displayError(error: Error) {
|
|
let alert = UIAlertController(title: error.prettyError, message: "", preferredStyle: UIAlertControllerStyle.alert)
|
|
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
|
|
present(alert, animated: true, completion: nil)
|
|
}
|
|
|
|
func confirm(
|
|
title: String? = .none,
|
|
message: String? = .none,
|
|
okTitle: String = NSLocalizedString("generic.Ok", value: "Ok", comment: ""),
|
|
okStyle: UIAlertActionStyle = .default,
|
|
completion: @escaping (Result<Void, ConfirmationError>) -> Void
|
|
) {
|
|
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
alertController.addAction(UIAlertAction(title: okTitle, style: okStyle, handler: { _ in
|
|
completion(.success())
|
|
}))
|
|
alertController.addAction(UIAlertAction(title: NSLocalizedString("Generic.Cancel", comment: ""), style: .cancel, handler: { _ in
|
|
completion(.failure(ConfirmationError.cancel))
|
|
}))
|
|
self.present(alertController, animated: true, completion: nil)
|
|
}
|
|
|
|
func displayLoading(text: String = "Loading...", animated: Bool = true) {
|
|
let hud = MBProgressHUD.showAdded(to: self.view, animated: animated)
|
|
hud.label.text = text
|
|
}
|
|
|
|
func hideLoading(animated: Bool = true) {
|
|
MBProgressHUD.hide(for: view, animated: animated)
|
|
}
|
|
|
|
func openURL(_ url: URL) {
|
|
let controller = SFSafariViewController(url: url)
|
|
present(controller, animated: true, completion: nil)
|
|
}
|
|
}
|
|
|