Skip to content

Commit

Permalink
remove old commented out attempts to reconnect WC2, now that issue is…
Browse files Browse the repository at this point in the history
… solved
  • Loading branch information
simonmcl committed Nov 12, 2024
1 parent 7aa6180 commit 2dd3147
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 98 deletions.
73 changes: 1 addition & 72 deletions Kukai Mobile/Modules/Home/HomeTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class HomeTabBarController: UITabBarController, UITabBarControllerDelegat
private var gradientLayers: [CAGradientLayer] = []
private var highlightedGradient = CAGradientLayer()
private var sideMenuVc: SideMenuViewController? = nil
private var walletConnectActivity = UIActivityIndicatorView()

private var activityAnimationFrames: [UIImage] = []
private var activityTabBarImageView: UIImageView? = nil
Expand Down Expand Up @@ -67,7 +66,6 @@ public class HomeTabBarController: UITabBarController, UITabBarControllerDelegat

DispatchQueue.global(qos: .background).async {
DependencyManager.shared.balanceService.loadCache(address: address)
//self?.reconnectWalletConnectIfNeeded()

DispatchQueue.main.async {
DependencyManager.shared.addressLoaded = address
Expand All @@ -90,7 +88,6 @@ public class HomeTabBarController: UITabBarController, UITabBarControllerDelegat

DispatchQueue.global(qos: .background).async {
DependencyManager.shared.balanceService.loadCache(address: address)
//self?.reconnectWalletConnectIfNeeded()

DispatchQueue.main.async {

Expand Down Expand Up @@ -126,8 +123,6 @@ public class HomeTabBarController: UITabBarController, UITabBarControllerDelegat
.dropFirst()
.sink { [weak self] address in

//self?.reconnectWalletConnectIfNeeded()

if DependencyManager.shared.appUpdateService.isRequiredUpdate {
self?.displayUpdateRequired()
}
Expand All @@ -148,7 +143,6 @@ public class HomeTabBarController: UITabBarController, UITabBarControllerDelegat
DependencyManager.shared.balanceService.$addressErrored
.dropFirst()
.sink { [weak self] obj in
//self?.reconnectWalletConnectIfNeeded()

if let obj = obj, obj.address == DependencyManager.shared.selectedWalletAddress {

Expand All @@ -167,14 +161,6 @@ public class HomeTabBarController: UITabBarController, UITabBarControllerDelegat
self?.supressAutoRefreshError = true
self?.refreshType = .refreshEverything
self?.refresh(addresses: nil)

/*
// When returning from a long background, WC2 can sometimes be stuck in a disconnected state.
// Give it a few seconds to try connect by itself, and then try manual intervention
DispatchQueue.main.asyncAfter(deadline: .now() + 3) { [weak self] in
self?.recheckWalletConnectAnimation(tryManualReconnect: true)
}
*/
}.store(in: &bag)

ThemeManager.shared.$themeDidChange
Expand Down Expand Up @@ -266,25 +252,6 @@ public class HomeTabBarController: UITabBarController, UITabBarControllerDelegat
}
}

public override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

//recheckWalletConnectAnimation()
}

// When returning from background, WC2 socket can get stuck sometimes.
// First we double check that no event was missed by running the logic again
// Second we have an optional request to attempt to reconnect the socket by re-initalising the WC2 singletons
public func recheckWalletConnectAnimation(tryManualReconnect: Bool = false) {
/*let isConnected = WalletConnectService.shared.isConnected
connectionStatusChanged(status: isConnected ? .connected : .disconnected)

if !isConnected && tryManualReconnect {
attemptWC2Reconnect()
}
*/
}

public override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

Expand Down Expand Up @@ -525,46 +492,8 @@ extension HomeTabBarController: ScanViewControllerDelegate {
extension HomeTabBarController: WalletConnectServiceDelegate {

public func connectionStatusChanged(status: SocketConnectionStatus) {
/*if status == .disconnected {

if walletConnectActivity.superview == nil {
self.walletConnectActivity.frame = self.scanButton.frame
self.walletConnectActivity.isUserInteractionEnabled = true
self.walletConnectActivity.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(attemptWC2Reconnect)))
self.scanButton.addSubview(self.walletConnectActivity)
}

self.scanButton.setImage(UIImage(), for: .normal) // passing in nil doesn't work sometimes, needs to be an empty image
self.walletConnectActivity.color = ThemeManager.shared.currentInterfaceStyle() == .dark ? .white : .black
self.walletConnectActivity.startAnimating()

} else {
self.scanButton.setImage(UIImage(named: "ScanQR"), for: .normal)
self.walletConnectActivity.stopAnimating()
self.walletConnectActivity.removeFromSuperview()
}
*/
}

@objc private func attemptWC2Reconnect() {
//WalletConnectService.shared.setup(force: true)
}

/*
public func walletConnectSocketFailedToReconnect3Times() {
DispatchQueue.main.async {
self.windowError(withTitle: "error".localized(), description: "error-wc2-reconnect".localized())
}
}
*/

/*
public func reconnectWalletConnectIfNeeded() {
if !WalletConnectService.shared.isConnected {
WalletConnectService.shared.reconnect()
}

}
*/

public func pairRequested() {
if self.presentedViewController == nil {
Expand Down
27 changes: 1 addition & 26 deletions Kukai Mobile/Services/WalletConnectService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public protocol WalletConnectServiceDelegate: AnyObject {
func processedOperations(ofType: WalletConnectOperationType)
func error(message: String?, error: Error?)
func connectionStatusChanged(status: SocketConnectionStatus)
//func walletConnectSocketFailedToReconnect3Times()
}

public struct WalletConnectGetAccountObj: Codable {
Expand Down Expand Up @@ -80,9 +79,6 @@ public class WalletConnectService {
private typealias walletConnectRequestTuple = (request: Request, context: VerifyContext?)
private typealias walletConnectPorposalTuple = (proposal: Session.Proposal, context: VerifyContext?)

//private var isReconnecting = false
//private var isManualDisconnection = true

@Published public var sessionsUpdated: Bool = false

private init() {}
Expand Down Expand Up @@ -125,28 +121,7 @@ public class WalletConnectService {
// Monitor connection
Networking.instance.socketConnectionStatusPublisher.sink { status in
Logger.app.info("WC2 - Connection status: changed to \(status == .connected ? "connected" : "disconnected")")

if status == .disconnected {
WalletConnectService.shared.isConnected = false

/*
if self?.isManualDisconnection == false && self?.isReconnecting == false {
WalletConnectService.shared.reconnect()

} else if self?.isManualDisconnection == true {
self?.isManualDisconnection = false
}
*/

} else {
WalletConnectService.shared.isConnected = true

/*
if let uri = self?.deepLinkPairingToConnect {
self?.pairClient(uri: uri)
}
*/
}
WalletConnectService.shared.isConnected = status == .connected

DispatchQueue.main.async {
WalletConnectService.shared.delegate?.connectionStatusChanged(status: status)
Expand Down

0 comments on commit 2dd3147

Please sign in to comment.