Skip to content

Commit fca92ec

Browse files
committed
Merge branch 'feature/ui_updates' into develop
2 parents 267be9c + 828c800 commit fca92ec

File tree

3 files changed

+56
-27
lines changed

3 files changed

+56
-27
lines changed

Kukai Mobile/Modules/Side Menu/WalletConnectViewModel.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ class WalletConnectViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
6868
// Get data
6969
pairs = Pair.instance.getPairings().compactMap({ pair -> PairObj? in
7070

71-
if pair.peer == nil {
71+
let sessions = Sign.instance.getSessions().filter({ $0.pairingTopic == pair.topic })
72+
73+
if pair.peer == nil || sessions.count == 0 {
7274
return nil
7375

7476
} else {
75-
let firstSession = Sign.instance.getSessions().filter({ $0.pairingTopic == pair.topic }).first
77+
let firstSession = sessions.first
7678
let firstAccount = firstSession?.accounts.first
7779
let address = firstAccount?.address
7880
let network = firstAccount?.blockchain.reference == "ghostnet" ? "Ghostnet" : "Mainnet"

Kukai Mobile/SceneDelegate.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
2828
window.overrideUserInterfaceStyle = ThemeManager.shared.currentInterfaceStyle()
2929
}
3030

31-
if let userActivity = connectionOptions.userActivities.first {
32-
Logger.app.info("Handling user activity")
33-
handle(userActivity: userActivity)
31+
if let url = connectionOptions.urlContexts.first?.url {
32+
handleDeeplink(url: url)
33+
} else {
34+
Logger.app.info("Launching without URL")
3435
}
3536
}
3637

@@ -70,17 +71,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
7071
return
7172
}
7273

73-
if url.absoluteString.prefix(10) == "kukai://wc" {
74-
var wc2URI = String(url.absoluteString.dropFirst(15)) // just strip off "kukai://wc?uri="
75-
wc2URI = wc2URI.removingPercentEncoding ?? ""
76-
77-
if let uri = WalletConnectURI(string: String(wc2URI)) {
78-
WalletConnectService.shared.pairClient(uri: uri)
79-
return
80-
}
81-
}
82-
83-
CustomAuth.handle(url: url)
74+
handleDeeplink(url: url)
8475
}
8576

8677

@@ -110,15 +101,24 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
110101
}
111102
}
112103

113-
private func handle(userActivity: NSUserActivity) {
114-
guard let url = userActivity.webpageURL, userActivity.activityType == NSUserActivityTypeBrowsingWeb else { return }
104+
private func handleDeeplink(url: URL) {
105+
Logger.app.info("Attempting to handle deeplink \(url.absoluteString)")
115106

116-
Logger.app.info("Attempting to handle Wallet Connect pairing")
117-
let wcUri = url.absoluteString.deletingPrefix("https://walletconnect.com/wc?uri=")
118-
guard let uri = WalletConnectURI(string: wcUri) else { return }
119-
120-
Task(priority: .high) {
121-
try? await Pair.instance.pair(uri: uri)
107+
if url.absoluteString.prefix(10) == "kukai://wc" {
108+
var wc2URI = String(url.absoluteString.dropFirst(15)) // just strip off "kukai://wc?uri="
109+
wc2URI = wc2URI.removingPercentEncoding ?? ""
110+
111+
if let uri = WalletConnectURI(string: String(wc2URI)) {
112+
113+
if WalletConnectService.shared.hasBeenSetup {
114+
WalletConnectService.shared.pairClient(uri: uri)
115+
116+
} else {
117+
WalletConnectService.shared.deepLinkPairingToConnect = uri
118+
}
119+
}
120+
} else {
121+
CustomAuth.handle(url: url)
122122
}
123123
}
124124
}

Kukai Mobile/Services/WalletConnectService.swift

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public class WalletConnectService {
5454
private var temporaryBag = [AnyCancellable]()
5555

5656
public static let shared = WalletConnectService()
57+
public var deepLinkPairingToConnect: WalletConnectURI? = nil
58+
public var hasBeenSetup = false
5759
public weak var delegate: WalletConnectServiceDelegate? = nil
5860

5961
private static let projectId = "97f804b46f0db632c52af0556586a5f3"
@@ -63,6 +65,8 @@ public class WalletConnectService {
6365
icons: ["https://wallet.kukai.app/assets/img/header-logo.svg"],
6466
redirect: AppMetadata.Redirect(native: "kukai://", universal: nil))
6567

68+
//private var incomingRequestPublisher = PassthroughSubject<Any, Never>()
69+
6670
@Published public var didCleanAfterDelete: Bool = false
6771
@Published public var requestDidComplete: Bool = false
6872

@@ -85,6 +89,18 @@ public class WalletConnectService {
8589

8690
// Callbacks
8791

92+
/*
93+
incomingRequestPublisher
94+
.buffer(size: 10, prefetch: .byRequest, whenFull: .dropNewest)
95+
.flatMap(maxPublishers: .max(1)) { [weak self] sessionRequest in
96+
97+
}
98+
.sink(receiveValue: { success in
99+
Logger.app.info("WC request completed with success: \(success)")
100+
})
101+
.store(in: &bag)
102+
*/
103+
88104
Sign.instance.sessionRequestPublisher
89105
.buffer(size: 10, prefetch: .byRequest, whenFull: .dropNewest)
90106
.flatMap(maxPublishers: .max(1)) { [weak self] sessionRequest in
@@ -119,11 +135,20 @@ public class WalletConnectService {
119135
.receive(on: DispatchQueue.main)
120136
.sink { [weak self] data in
121137
Logger.app.info("WC sessionDeletePublisher \(data.0)")
122-
Task { [weak self] in
123-
await WalletConnectService.cleanupSessionlessPairs()
138+
//Task { [weak self] in
139+
//await WalletConnectService.cleanupSessionlessPairs()
124140
self?.didCleanAfterDelete = true
125-
}
141+
//}
126142
}.store(in: &bag)
143+
144+
hasBeenSetup = true
145+
146+
if let uri = deepLinkPairingToConnect {
147+
Task {
148+
await pairClient(uri: uri)
149+
deepLinkPairingToConnect = nil
150+
}
151+
}
127152
}
128153

129154

@@ -309,6 +334,7 @@ public class WalletConnectService {
309334
}
310335
}
311336

337+
/*
312338
@MainActor
313339
public static func cleanupSessionlessPairs() async {
314340
var pairsToClean: [Pairing] = []
@@ -323,6 +349,7 @@ public class WalletConnectService {
323349
try? await Pair.instance.disconnect(topic: pair.topic)
324350
})
325351
}
352+
*/
326353

327354
@MainActor
328355
public static func reject(proposalId: String, reason: RejectionReason) throws {

0 commit comments

Comments
 (0)