From f2712dc8116c08278de7cb0e2bba930423c5671a Mon Sep 17 00:00:00 2001 From: Simon Mcloughlin Date: Tue, 29 Oct 2024 10:21:36 +0000 Subject: [PATCH] - cherry pick: update WC2 and scene delegate to process universal links correctly --- Kukai Mobile/SceneDelegate.swift | 46 ++++++++++++++----- .../Services/WalletConnectService.swift | 2 +- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Kukai Mobile/SceneDelegate.swift b/Kukai Mobile/SceneDelegate.swift index 5a6cf7c5..9d03e271 100644 --- a/Kukai Mobile/SceneDelegate.swift +++ b/Kukai Mobile/SceneDelegate.swift @@ -38,7 +38,13 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { } if let url = connectionOptions.urlContexts.first?.url { + Logger.app.info("Launching with deeplink") handleDeeplink(url: url) + + } else if let userActivity = connectionOptions.userActivities.first, userActivity.activityType == NSUserActivityTypeBrowsingWeb, let url = userActivity.webpageURL { + Logger.app.info("Launching with universal link") + handleDeeplink(url: url) + } else { Logger.app.info("Launching without URL") } @@ -89,6 +95,15 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { handleDeeplink(url: url) } + func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { + guard userActivity.activityType == NSUserActivityTypeBrowsingWeb, + let url = userActivity.webpageURL else { + return + } + + handleDeeplink(url: url) + } + // MARK: - Non system functions @@ -135,20 +150,29 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { Logger.app.info("Attempting to handle deeplink \(url.absoluteString)") if url.absoluteString.prefix(10) == "kukai://wc" { - var wc2URI = String(url.absoluteString.dropFirst(15)) // just strip off "kukai://wc?uri=" - wc2URI = wc2URI.removingPercentEncoding ?? "" + let wc2URI = String(url.absoluteString.dropFirst(15)) // just strip off "kukai://wc?uri=" + handleWC(withURI: wc2URI) + } else if url.absoluteString.prefix(28) == "https://connect.kukai.app/wc" { + let wc2URI = String(url.absoluteString.dropFirst(33)) // just strip off "https://connect.kukai.app/wc?uri=" + handleWC(withURI: wc2URI) + } + else { + CustomAuth.handle(url: url) + } + } + + private func handleWC(withURI uri: String) { + var wc2URI = uri + wc2URI = wc2URI.removingPercentEncoding ?? "" + + if let uri = try? WalletConnectURI(uriString: String(wc2URI)) { - if let uri = try? WalletConnectURI(uriString: String(wc2URI)) { + if WalletConnectService.shared.hasBeenSetup { + WalletConnectService.shared.pairClient(uri: uri) - if WalletConnectService.shared.hasBeenSetup { - WalletConnectService.shared.pairClient(uri: uri) - - } else { - WalletConnectService.shared.deepLinkPairingToConnect = uri - } + } else { + WalletConnectService.shared.deepLinkPairingToConnect = uri } - } else { - CustomAuth.handle(url: url) } } } diff --git a/Kukai Mobile/Services/WalletConnectService.swift b/Kukai Mobile/Services/WalletConnectService.swift index 507dc9b2..db1ad7e9 100644 --- a/Kukai Mobile/Services/WalletConnectService.swift +++ b/Kukai Mobile/Services/WalletConnectService.swift @@ -80,7 +80,7 @@ public class WalletConnectService { description: "Kukai iOS", url: "https://wallet.kukai.app", icons: ["https://wallet.kukai.app/assets/img/header-logo.svg"], - redirect: (try! AppMetadata.Redirect(native: "kukai://", universal: nil)) ) + redirect: (try! AppMetadata.Redirect(native: "kukai://", universal: "https://connect.kukai.app", linkMode: true)) ) private var pairingTimer: Timer? = nil private var requestOrProposalInProgress = false