Skip to content

Commit

Permalink
update universal links to accept universal links
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcl committed Oct 18, 2024
1 parent 3764295 commit b77f408
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
46 changes: 35 additions & 11 deletions Kukai Mobile/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
2 changes: 1 addition & 1 deletion Kukai Mobile/Services/WalletConnectService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b77f408

Please sign in to comment.