Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Bitkit/Components/NodeStateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
52 changes: 44 additions & 8 deletions Bitkit/Views/Settings/AppStatusView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
Loading