From 0e6193425b2adefeb41bcb8130e2491409149d3f Mon Sep 17 00:00:00 2001 From: Simon McLoughlin Date: Fri, 19 Jan 2024 12:01:57 +0000 Subject: [PATCH] attempt to fix possible issue with WC2 spinner not going away --- Kukai Mobile/Modules/Home/HomeTabBarController.swift | 11 +++++++++++ Kukai Mobile/Services/WalletConnectService.swift | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/Kukai Mobile/Modules/Home/HomeTabBarController.swift b/Kukai Mobile/Modules/Home/HomeTabBarController.swift index 99adc107..3ee6160a 100644 --- a/Kukai Mobile/Modules/Home/HomeTabBarController.swift +++ b/Kukai Mobile/Modules/Home/HomeTabBarController.swift @@ -451,6 +451,7 @@ extension HomeTabBarController: WalletConnectServiceDelegate { self.scanButton.addSubview(self.walletConnectActivity) self.walletConnectActivity.startAnimating() + recheckConnectionIn3Seconds() } else { self.scanButton.isEnabled = true @@ -459,6 +460,16 @@ extension HomeTabBarController: WalletConnectServiceDelegate { } } + private func recheckConnectionIn3Seconds() { + DispatchQueue.main.asyncAfter(wallDeadline: .now() + 3) { [weak self] in + WalletConnectService.shared.isConnected { [weak self] connected in + if connected { + self?.connectionStatusChanged(status: .connected) + } + } + } + } + public func pairRequested() { self.performSegue(withIdentifier: "wallet-connect-pair", sender: nil) } diff --git a/Kukai Mobile/Services/WalletConnectService.swift b/Kukai Mobile/Services/WalletConnectService.swift index ecca9d9c..dab0fa0c 100644 --- a/Kukai Mobile/Services/WalletConnectService.swift +++ b/Kukai Mobile/Services/WalletConnectService.swift @@ -61,6 +61,7 @@ public class WalletConnectService { public weak var delegate: WalletConnectServiceDelegate? = nil private var bag = [AnyCancellable]() + private var tempConnectionSubscription: AnyCancellable? = nil private static let projectId = "97f804b46f0db632c52af0556586a5f3" private static let metadata = AppMetadata(name: "Kukai iOS", description: "Kukai iOS", @@ -171,6 +172,16 @@ public class WalletConnectService { } } + public func isConnected(completion: @escaping ((Bool) -> Void)) { + tempConnectionSubscription = Networking.instance.socketConnectionStatusPublisher.sink { [weak self] status in + completion(status == .connected) + + self?.tempConnectionSubscription?.cancel() + } + + tempConnectionSubscription?.store(in: &bag) + } + // MARK: - Queue Management