diff --git a/Bitkit/Components/NodeStateView.swift b/Bitkit/Components/NodeStateView.swift index 03738400..4e0c2a30 100644 --- a/Bitkit/Components/NodeStateView.swift +++ b/Bitkit/Components/NodeStateView.swift @@ -45,12 +45,38 @@ struct NodeStateView: View { channelsSection balanceSection } + .refreshable { + await refreshNodeState() + } } .navigationBarHidden(true) // .padding(.horizontal, 16) .bottomSafeAreaPadding() } + private func refreshNodeState() async { + wallet.syncState() + + // If node is in an error state or stopped, retry starting it + if case .errorStarting = wallet.nodeLifecycleState { + do { + try await wallet.start() + } catch { + await MainActor.run { + app.toast(error) + } + } + } else if wallet.nodeLifecycleState == .stopped { + do { + try await wallet.start() + } catch { + await MainActor.run { + app.toast(error) + } + } + } + } + var statusSection: some View { Section { HStack { diff --git a/Bitkit/Views/Settings/AppStatusView.swift b/Bitkit/Views/Settings/AppStatusView.swift index 147b4b90..f72c6cc2 100644 --- a/Bitkit/Views/Settings/AppStatusView.swift +++ b/Bitkit/Views/Settings/AppStatusView.swift @@ -4,21 +4,25 @@ struct AppStatusView: View { @EnvironmentObject private var navigation: NavigationViewModel @EnvironmentObject private var network: NetworkMonitor @EnvironmentObject private var wallet: WalletViewModel + @EnvironmentObject private var app: AppViewModel var body: some View { VStack(alignment: .leading, spacing: 0) { NavigationBar(title: t("settings__status__title")) .padding(.bottom, 16) - VStack(spacing: 16) { - internetStatusRow - bitcoinNodeStatusRow - nodeStatusRow - channelsStatusRow - backupStatusRow + ScrollView { + VStack(spacing: 16) { + internetStatusRow + bitcoinNodeStatusRow + nodeStatusRow + channelsStatusRow + backupStatusRow + } + } + .refreshable { + await refreshAppStatus() } - - Spacer() } .navigationBarHidden(true) .padding(.horizontal, 16) @@ -28,6 +32,38 @@ struct AppStatusView: View { } } + private func refreshAppStatus() async { + wallet.syncState() + + if wallet.nodeLifecycleState == .running { + do { + try await wallet.sync() + } catch { + await MainActor.run { + app.toast(error) + } + } + } + + if case .errorStarting = wallet.nodeLifecycleState { + do { + try await wallet.start() + } catch { + await MainActor.run { + app.toast(error) + } + } + } else if wallet.nodeLifecycleState == .stopped { + do { + try await wallet.start() + } catch { + await MainActor.run { + app.toast(error) + } + } + } + } + // MARK: - Status Rows private var internetStatusRow: some View {