From 6bf4f574d4683bcb345c4ccc5dd37af1029e98a7 Mon Sep 17 00:00:00 2001 From: Simon McLoughlin Date: Wed, 21 Aug 2024 11:18:43 +0100 Subject: [PATCH] add timeouts to ledger sign process --- Sources/KukaiCoreSwift/Models/LedgerWallet.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/KukaiCoreSwift/Models/LedgerWallet.swift b/Sources/KukaiCoreSwift/Models/LedgerWallet.swift index 9e74f11b..e8a1bd2f 100644 --- a/Sources/KukaiCoreSwift/Models/LedgerWallet.swift +++ b/Sources/KukaiCoreSwift/Models/LedgerWallet.swift @@ -78,8 +78,14 @@ public class LedgerWallet: Wallet { let isWatermarkedOperation = (String(hex.prefix(2)) == "03") && hex.count != 32 LedgerService.shared.connectTo(uuid: ledgerUUID) - .flatMap { _ -> AnyPublisher in + .timeout(.seconds(10), scheduler: RunLoop.main, customError: { + return KukaiError.knownErrorMessage("Timed out waiting for device to connect. Check device/bluetooth is turned on and try again") + }) + .flatMap { _ -> Publishers.Timeout, RunLoop> in return LedgerService.shared.sign(hex: hex, parse: isWatermarkedOperation) + .timeout(.seconds(10), scheduler: RunLoop.main, customError: { + return KukaiError.knownErrorMessage("Timed out waiting for device to connect. Check device/bluetooth is turned on and try again") + }) } .sink(onError: { error in completion(Result.failure(error))