diff --git a/Kukai Mobile/Modules/ConnectedApps/WalletConnectSignViewController.swift b/Kukai Mobile/Modules/ConnectedApps/WalletConnectSignViewController.swift index b96f730c..59a93a8f 100644 --- a/Kukai Mobile/Modules/ConnectedApps/WalletConnectSignViewController.swift +++ b/Kukai Mobile/Modules/ConnectedApps/WalletConnectSignViewController.swift @@ -77,8 +77,9 @@ class WalletConnectSignViewController: UIViewController, BottomSheetCustomFixedP self.hideLoadingModal(completion: { [weak self] in TransactionService.shared.resetWalletConnectState() - HomeTabBarController.recordWalletConnectOperationAsComplete() - self?.presentingViewController?.dismiss(animated: true) + self?.presentingViewController?.dismiss(animated: true, completion: { + HomeTabBarController.recordWalletConnectOperationAsComplete() + }) }) } catch { @@ -103,11 +104,12 @@ class WalletConnectSignViewController: UIViewController, BottomSheetCustomFixedP Logger.app.info("WC Reject Request: \(request.id)") Task { do { - try WalletConnectService.reject(topic: request.topic, requestId: request.id) + try WalletConnectService.reject(topic: request.topic, requestId: request.id, autoMarkOpComplete: false) self.hideLoadingModal(completion: { [weak self] in TransactionService.shared.resetWalletConnectState() - HomeTabBarController.recordWalletConnectOperationAsComplete() - self?.presentingViewController?.dismiss(animated: true) + self?.presentingViewController?.dismiss(animated: true, completion: { + HomeTabBarController.recordWalletConnectOperationAsComplete() + }) }) } catch { diff --git a/Kukai Mobile/Modules/Home/HomeTabBarController.swift b/Kukai Mobile/Modules/Home/HomeTabBarController.swift index 5d3f408b..f94c2153 100644 --- a/Kukai Mobile/Modules/Home/HomeTabBarController.swift +++ b/Kukai Mobile/Modules/Home/HomeTabBarController.swift @@ -522,7 +522,9 @@ extension HomeTabBarController: WalletConnectServiceDelegate { Logger.app.error("WC2 error message: \(message) - error: \(error)") self.hideLoadingView { - WalletConnectService.shared.requestDidComplete = true + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + WalletConnectService.shared.requestDidComplete = true + } WalletConnectService.shared.proposalInProgress = false WalletConnectService.shared.requestInProgress = false } diff --git a/Kukai Mobile/Modules/Send/SendCollectibleConfirmViewController.swift b/Kukai Mobile/Modules/Send/SendCollectibleConfirmViewController.swift index be559990..58d7f290 100644 --- a/Kukai Mobile/Modules/Send/SendCollectibleConfirmViewController.swift +++ b/Kukai Mobile/Modules/Send/SendCollectibleConfirmViewController.swift @@ -266,14 +266,17 @@ class SendCollectibleConfirmViewController: UIViewController, SlideButtonDelegat } func dismissAndReturn() { - if isWalletConnectOp { - TransactionService.shared.resetWalletConnectState() - HomeTabBarController.recordWalletConnectOperationAsComplete() - } else { + if !isWalletConnectOp { TransactionService.shared.resetAllState() } - self.dismiss(animated: true, completion: nil) + self.dismiss(animated: true) { [weak self] in + if self?.isWalletConnectOp == true { + TransactionService.shared.resetWalletConnectState() + HomeTabBarController.recordWalletConnectOperationAsComplete() + } + } + (self.presentingViewController as? UINavigationController)?.popToHome() } diff --git a/Kukai Mobile/Modules/Send/SendContractConfirmViewController.swift b/Kukai Mobile/Modules/Send/SendContractConfirmViewController.swift index 2c233afc..a7feaa08 100644 --- a/Kukai Mobile/Modules/Send/SendContractConfirmViewController.swift +++ b/Kukai Mobile/Modules/Send/SendContractConfirmViewController.swift @@ -274,14 +274,17 @@ class SendContractConfirmViewController: UIViewController, SlideButtonDelegate, } func dismissAndReturn() { - if isWalletConnectOp { - TransactionService.shared.resetWalletConnectState() - HomeTabBarController.recordWalletConnectOperationAsComplete() - } else { + if !isWalletConnectOp { TransactionService.shared.resetAllState() } - self.dismiss(animated: true, completion: nil) + self.dismiss(animated: true) { [weak self] in + if self?.isWalletConnectOp == true { + TransactionService.shared.resetWalletConnectState() + HomeTabBarController.recordWalletConnectOperationAsComplete() + } + } + (self.presentingViewController as? UINavigationController)?.popToHome() } diff --git a/Kukai Mobile/Modules/Send/SendTokenConfirmViewController.swift b/Kukai Mobile/Modules/Send/SendTokenConfirmViewController.swift index 8aeb4028..f12c6fa5 100644 --- a/Kukai Mobile/Modules/Send/SendTokenConfirmViewController.swift +++ b/Kukai Mobile/Modules/Send/SendTokenConfirmViewController.swift @@ -300,14 +300,17 @@ class SendTokenConfirmViewController: UIViewController, SlideButtonDelegate, Edi } func dismissAndReturn() { - if isWalletConnectOp { - TransactionService.shared.resetWalletConnectState() - HomeTabBarController.recordWalletConnectOperationAsComplete() - } else { + if !isWalletConnectOp { TransactionService.shared.resetAllState() } - self.dismiss(animated: true, completion: nil) + self.dismiss(animated: true) { [weak self] in + if self?.isWalletConnectOp == true { + TransactionService.shared.resetWalletConnectState() + HomeTabBarController.recordWalletConnectOperationAsComplete() + } + } + (self.presentingViewController as? UINavigationController)?.popToHome() } diff --git a/Kukai Mobile/Services/WalletConnectService.swift b/Kukai Mobile/Services/WalletConnectService.swift index 486d0e7e..e0b63250 100644 --- a/Kukai Mobile/Services/WalletConnectService.swift +++ b/Kukai Mobile/Services/WalletConnectService.swift @@ -364,12 +364,14 @@ public class WalletConnectService { TransactionService.shared.resetWalletConnectState() } - WalletConnectService.shared.proposalInProgress = false + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + WalletConnectService.shared.proposalInProgress = false + } } } @MainActor - public static func reject(topic: String, requestId: RPCID, clearState: Bool = true) throws { + public static func reject(topic: String, requestId: RPCID, clearState: Bool = true, autoMarkOpComplete: Bool = true) throws { Logger.app.info("WC Reject Request topic: \(topic), id: \(requestId.description)") Task { try await Sign.instance.respond(topic: topic, requestId: requestId, response: .error(.init(code: 0, message: ""))) @@ -378,8 +380,12 @@ public class WalletConnectService { TransactionService.shared.resetWalletConnectState() } - WalletConnectService.shared.requestDidComplete = true - WalletConnectService.shared.requestInProgress = false + if autoMarkOpComplete { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + WalletConnectService.shared.requestDidComplete = true + WalletConnectService.shared.requestInProgress = false + } + } } }