2020-01-04 19:31:52 +00:00
|
|
|
import UIKit
|
|
|
|
import Flutter
|
2021-04-20 17:49:53 +00:00
|
|
|
import UnstoppableDomainsResolution
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
@UIApplicationMain
|
|
|
|
@objc class AppDelegate: FlutterAppDelegate {
|
2021-04-20 17:49:53 +00:00
|
|
|
lazy var resolution : Resolution? = {
|
2021-07-07 13:50:55 +00:00
|
|
|
return try? Resolution()
|
2021-05-24 18:06:12 +00:00
|
|
|
}()
|
|
|
|
|
2020-09-21 15:41:44 +00:00
|
|
|
override func application(
|
|
|
|
_ application: UIApplication,
|
|
|
|
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
|
|
|
) -> Bool {
|
2021-06-04 15:25:17 +00:00
|
|
|
if #available(iOS 10.0, *) {
|
|
|
|
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
|
|
|
|
}
|
|
|
|
|
2020-09-21 15:41:44 +00:00
|
|
|
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
|
2021-05-10 10:06:57 +00:00
|
|
|
let legacyMigrationChannel = FlutterMethodChannel(
|
|
|
|
name: "com.cakewallet.cakewallet/legacy_wallet_migration",
|
|
|
|
binaryMessenger: controller.binaryMessenger)
|
|
|
|
legacyMigrationChannel.setMethodCallHandler({
|
2020-09-21 15:41:44 +00:00
|
|
|
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
|
|
|
|
|
|
|
|
switch call.method {
|
2020-09-23 18:26:10 +00:00
|
|
|
case "decrypt":
|
2020-09-21 15:41:44 +00:00
|
|
|
guard let args = call.arguments as? Dictionary<String, Any>,
|
2020-09-23 18:26:10 +00:00
|
|
|
let data = args["bytes"] as? FlutterStandardTypedData,
|
2020-09-21 15:41:44 +00:00
|
|
|
let key = args["key"] as? String,
|
|
|
|
let salt = args["salt"] as? String else {
|
2020-09-23 18:26:10 +00:00
|
|
|
result(nil)
|
2020-09-21 15:41:44 +00:00
|
|
|
return
|
|
|
|
}
|
2020-09-23 18:26:10 +00:00
|
|
|
|
|
|
|
let content = decrypt(data: data.data, key: key, salt: salt)
|
|
|
|
result(content)
|
|
|
|
case "read_user_defaults":
|
2020-09-21 15:41:44 +00:00
|
|
|
guard let args = call.arguments as? Dictionary<String, Any>,
|
|
|
|
let key = args["key"] as? String,
|
2020-09-23 18:26:10 +00:00
|
|
|
let type = args["type"] as? String else {
|
|
|
|
result(nil)
|
2020-09-21 15:41:44 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-23 18:26:10 +00:00
|
|
|
var value: Any?
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case "string":
|
|
|
|
value = UserDefaults.standard.string(forKey: key)
|
|
|
|
case "int":
|
|
|
|
value = UserDefaults.standard.integer(forKey: key)
|
|
|
|
case "bool":
|
|
|
|
value = UserDefaults.standard.bool(forKey: key)
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
result(value)
|
2020-09-21 15:41:44 +00:00
|
|
|
default:
|
2020-09-23 18:26:10 +00:00
|
|
|
result(FlutterMethodNotImplemented)
|
2020-09-21 15:41:44 +00:00
|
|
|
}
|
|
|
|
})
|
2021-05-24 18:06:12 +00:00
|
|
|
|
2021-05-10 10:06:57 +00:00
|
|
|
let utilsChannel = FlutterMethodChannel(
|
|
|
|
name: "com.cake_wallet/native_utils",
|
|
|
|
binaryMessenger: controller.binaryMessenger)
|
2021-07-22 10:34:42 +00:00
|
|
|
utilsChannel.setMethodCallHandler({ [weak self] (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
|
2021-05-10 10:06:57 +00:00
|
|
|
switch call.method {
|
|
|
|
case "sec_random":
|
|
|
|
guard let args = call.arguments as? Dictionary<String, Any>,
|
|
|
|
let count = args["count"] as? Int else {
|
|
|
|
result(nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
result(secRandom(count: count))
|
2021-07-07 13:50:55 +00:00
|
|
|
case "getUnstoppableDomainAddress":
|
|
|
|
guard let args = call.arguments as? Dictionary<String, String>,
|
|
|
|
let domain = args["domain"],
|
|
|
|
let ticker = args["ticker"],
|
|
|
|
let resolution = self?.resolution else {
|
|
|
|
result(nil)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
resolution.addr(domain: domain, ticker: ticker) { addrResult in
|
|
|
|
var address : String = ""
|
|
|
|
|
|
|
|
switch addrResult {
|
|
|
|
case .success(let returnValue):
|
|
|
|
address = returnValue
|
|
|
|
case .failure(let error):
|
|
|
|
print("Expected Address, but got \(error)")
|
|
|
|
}
|
|
|
|
|
|
|
|
result(address)
|
|
|
|
}
|
2022-01-21 13:02:00 +00:00
|
|
|
|
2021-05-10 10:06:57 +00:00
|
|
|
default:
|
|
|
|
result(FlutterMethodNotImplemented)
|
|
|
|
}
|
|
|
|
})
|
2021-05-24 18:06:12 +00:00
|
|
|
|
2020-09-21 15:41:44 +00:00
|
|
|
GeneratedPluginRegistrant.register(with: self)
|
|
|
|
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
|
|
|
}
|
2023-04-10 17:10:35 +00:00
|
|
|
|
|
|
|
override func applicationWillResignActive(_: UIApplication ) {
|
2023-05-02 13:30:19 +00:00
|
|
|
self.window?.rootViewController?.view.endEditing(true)
|
2023-04-10 17:10:35 +00:00
|
|
|
self.window?.isHidden = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
override func applicationDidBecomeActive(_: UIApplication) {
|
|
|
|
self.window?.isHidden = false;
|
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|