Start WalletConnect session from universal link

This commit is contained in:
Ivan Grachyov 2021-06-15 00:42:21 +03:00
parent f8edfb066f
commit af48f91ebc
2 changed files with 16 additions and 7 deletions

View File

@ -76,12 +76,16 @@ class Agent {
statusBarItem.button?.sendAction(on: [.leftMouseUp])
}
func processInputLink(_ link: String) {
let session = WalletConnect.shared.sessionWithLink(link)
showInitialScreen(onAppStart: false, wcSession: session)
}
@objc private func statusBarButtonClicked(sender: NSStatusBarButton) {
let pasteboard = NSPasteboard.general
let link = pasteboard.string(forType: .string) ?? ""
pasteboard.clearContents()
let session = WalletConnect.shared.sessionWithLink(link)
showInitialScreen(onAppStart: false, wcSession: session)
processInputLink(link)
}
private func proceedAfterAuthentication(reason: String, completion: @escaping (Bool) -> Void) {

View File

@ -5,24 +5,29 @@ import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
private let agent = Agent.shared
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return false
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
Agent.shared.start()
Agent.shared.setupStatusBarItem()
agent.start()
agent.setupStatusBarItem()
}
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
Agent.shared.reopen()
agent.reopen()
return true
}
func application(_ application: NSApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([NSUserActivityRestoring]) -> Void) -> Bool {
if let url = userActivity.webpageURL?.absoluteString {
print(url)
let prefix = "https://encrypted.ink/wc?uri="
if let url = userActivity.webpageURL?.absoluteString, url.hasPrefix(prefix),
let link = url.dropFirst(prefix.count).removingPercentEncoding {
agent.processInputLink(link)
}
// TODO: do something if could not parse input link
return true
}