From ffdb2c237ad369254f353615fda53dec73187ef4 Mon Sep 17 00:00:00 2001 From: Nick Klockenga Date: Tue, 31 Mar 2026 22:42:46 -0400 Subject: [PATCH] add chaintip height to success message in wallet info and connection status screen when testing Electrum connection. Also add network chain check in these tests as well. --- .../Main/Dashboard/ConnectionStatusView.swift | 14 ++++++++++++-- .../Views/Main/Settings/WalletInfoView.swift | 16 +++++++++++++--- .../Views/Setup/ElectrumServerSetupSection.swift | 5 +++-- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/hellbender/Views/Main/Dashboard/ConnectionStatusView.swift b/hellbender/Views/Main/Dashboard/ConnectionStatusView.swift index 22f3e9c..bbd24b2 100644 --- a/hellbender/Views/Main/Dashboard/ConnectionStatusView.swift +++ b/hellbender/Views/Main/Dashboard/ConnectionStatusView.swift @@ -105,7 +105,7 @@ struct ConnectionStatusView: View { if let result = testResult { Text(result) .font(.hbBody(13)) - .foregroundStyle(result.starts(with: "Success") ? Color.hbSuccess : Color.hbError) + .foregroundStyle(result.starts(with: "Success") ? Color.hbSuccess : result.starts(with: "Warning") ? Color.hbBitcoinOrange : Color.hbError) } } .hbCard() @@ -343,7 +343,17 @@ struct ConnectionStatusView: View { let config = wallet.electrumConfig do { let height = try await service.testElectrumConnection(config: config) - testResult = "Success — chain tip at block \(height)" + let network = wallet.bitcoinNetwork + if network != .signet { + if let detected = try? await service.detectElectrumNetwork(config: config), + detected != network + { + testResult = "Warning: Server is \(detected.displayName), expected \(network.displayName)" + isTesting = false + return + } + } + testResult = "Success — \(network.displayName) Chain Tip Height \(height)" } catch { testResult = "Failed: \(BitcoinService.friendlyElectrumError(error))" } diff --git a/hellbender/Views/Main/Settings/WalletInfoView.swift b/hellbender/Views/Main/Settings/WalletInfoView.swift index c0b32f4..e07daed 100644 --- a/hellbender/Views/Main/Settings/WalletInfoView.swift +++ b/hellbender/Views/Main/Settings/WalletInfoView.swift @@ -235,7 +235,7 @@ struct WalletInfoView: View { if let result = connectionTestResult { Text(result) .font(.hbBody(13)) - .foregroundStyle(result.starts(with: "Success") ? Color.hbSuccess : Color.hbError) + .foregroundStyle(result.starts(with: "Success") ? Color.hbSuccess : result.starts(with: "Warning") ? Color.hbBitcoinOrange : Color.hbError) } HStack(spacing: 12) { @@ -476,9 +476,19 @@ struct WalletInfoView: View { logger.info("Testing Electrum connection to \(config.url, privacy: .public)") Task { do { - try await BitcoinService.shared.testElectrumConnection(config: config) + let height = try await BitcoinService.shared.testElectrumConnection(config: config) logger.info("Electrum connection test succeeded") - connectionTestResult = "Success — server responded to ping" + let network = wallet.bitcoinNetwork + if network != .signet { + if let detected = try? await BitcoinService.shared.detectElectrumNetwork(config: config), + detected != network + { + connectionTestResult = "Warning: Server is \(detected.displayName), expected \(network.displayName)" + isTestingConnection = false + return + } + } + connectionTestResult = "Success — \(network.displayName) Chain Tip Height \(height)" } catch { logger.error("Electrum connection test failed: \(error)") connectionTestResult = "Failed: \(error.localizedDescription)" diff --git a/hellbender/Views/Setup/ElectrumServerSetupSection.swift b/hellbender/Views/Setup/ElectrumServerSetupSection.swift index f918249..59cc367 100644 --- a/hellbender/Views/Setup/ElectrumServerSetupSection.swift +++ b/hellbender/Views/Setup/ElectrumServerSetupSection.swift @@ -177,8 +177,9 @@ struct ElectrumServerSetupSection: View { let height = try await BitcoinService.shared.testElectrumConnection(config: config) // Verify network for mainnet, testnet3, testnet4 (skip signet) if expectedNetwork != .signet { - let detected = try await BitcoinService.shared.detectElectrumNetwork(config: config) - if let detected, detected != expectedNetwork { + if let detected = try? await BitcoinService.shared.detectElectrumNetwork(config: config), + detected != expectedNetwork + { connectionTestResult = "Warning: Server is \(detected.displayName), expected \(expectedNetwork.displayName)" isTestingConnection = false return