From 7667e5979b07fa770a61c64a00f7fb9d1702a16a Mon Sep 17 00:00:00 2001 From: Simon McLoughlin Date: Wed, 24 Jan 2024 15:56:29 +0000 Subject: [PATCH] try to prevent getPublicAddress from causing an app hang --- .../KukaiCoreSwift/Services/TorusAuthService.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/KukaiCoreSwift/Services/TorusAuthService.swift b/Sources/KukaiCoreSwift/Services/TorusAuthService.swift index 8a7a0904..77bc9dbf 100644 --- a/Sources/KukaiCoreSwift/Services/TorusAuthService.swift +++ b/Sources/KukaiCoreSwift/Services/TorusAuthService.swift @@ -320,13 +320,13 @@ public class TorusAuthService: NSObject { let isTestnet = (verifierWrapper.networkType == .testnet) self.fetchNodeDetails = CASDKFactory().createFetchNodeDetails(network: (isTestnet ? .TESTNET : .MAINNET), urlSession: networkService.urlSession, networkUrl: (isTestnet ? "https://rpc.ankr.com/eth_ropsten" : nil)) - Task { @MainActor in + Task { do { let remoteNodeDetails = try await self.fetchNodeDetails.getNodeDetails(verifier: verifierName, verifierID: socialUserId) self.nodeDetails = remoteNodeDetails guard let nd = self.nodeDetails else { - completion(Result.failure(KukaiError.internalApplicationError(error: TorusAuthError.invalidNodeDetails))) + DispatchQueue.main.async { completion(Result.failure(KukaiError.internalApplicationError(error: TorusAuthError.invalidNodeDetails))) } return } @@ -339,7 +339,7 @@ public class TorusAuthService: NSObject { let bytesX = Sodium.shared.utils.hex2bin(x), let bytesY = Sodium.shared.utils.hex2bin(y) else { Logger.torus.error("Finding address - no valid pub key x and y returned") - completion(Result.failure(KukaiError.internalApplicationError(error: TorusAuthError.invalidTorusResponse))) + DispatchQueue.main.async { completion(Result.failure(KukaiError.internalApplicationError(error: TorusAuthError.invalidTorusResponse))) } return } @@ -355,17 +355,17 @@ public class TorusAuthService: NSObject { // Run Blake2b hashing on public key guard let hash = Sodium.shared.genericHash.hash(message: publicKey, outputLength: 20) else { Logger.torus.error("Finding address - generating hash failed") - completion(Result.failure(KukaiError.internalApplicationError(error: TorusAuthError.cryptoError))) + DispatchQueue.main.async { completion(Result.failure(KukaiError.internalApplicationError(error: TorusAuthError.cryptoError))) } return } // Create tz2 address and return let tz2Address = Base58Check.encode(message: hash, prefix: Prefix.Address.tz2) - completion(Result.success(tz2Address)) + DispatchQueue.main.async { completion(Result.success(tz2Address)) } } catch { Logger.torus.error("Error logging in: \(error)") - completion(Result.failure(KukaiError.internalApplicationError(error: error))) + DispatchQueue.main.async { completion(Result.failure(KukaiError.internalApplicationError(error: error))) } return } }