Skip to content

Commit 642d881

Browse files
committed
feat: surface kyoto sync phase status
1 parent d902e68 commit 642d881

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

BDKSwiftExampleWallet/Extensions/BDK+Extensions/CbfClient+Extensions.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ extension CbfClient {
7272
)
7373
}
7474
}
75+
case .stateUpdate(let nodeState):
76+
await MainActor.run {
77+
NotificationCenter.default.post(
78+
name: NSNotification.Name("KyotoStateUpdate"),
79+
object: nil,
80+
userInfo: ["state": nodeState]
81+
)
82+
}
7583
case .connectionsMet, .successfulHandshake:
7684
await MainActor.run {
7785
if !hasEstablishedConnection {

BDKSwiftExampleWallet/View Model/WalletViewModel.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class WalletViewModel {
4747
}
4848
var isKyotoConnected: Bool = false
4949
var currentBlockHeight: UInt32 = 0
50+
var kyotoNodeState: NodeState?
5051

5152
private var updateProgress: @Sendable (UInt64, UInt64) -> Void {
5253
{ [weak self] inspected, total in
@@ -161,6 +162,23 @@ class WalletViewModel {
161162
}
162163
}
163164
}
165+
166+
NotificationCenter.default.addObserver(
167+
forName: NSNotification.Name("KyotoStateUpdate"),
168+
object: nil,
169+
queue: .main
170+
) { [weak self] notification in
171+
guard let self else { return }
172+
if self.bdkClient.getClientType() != .kyoto { return }
173+
if let nodeState = notification.userInfo?["state"] as? NodeState {
174+
self.kyotoNodeState = nodeState
175+
if nodeState == .transactionsSynced {
176+
self.walletSyncState = .synced
177+
} else {
178+
self.walletSyncState = .syncing
179+
}
180+
}
181+
}
164182
}
165183

166184
private func fullScanWithProgress() async {

BDKSwiftExampleWallet/View/Home/ActivityHomeHeaderView.swift

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Created by Rubens Machion on 24/04/25.
66
//
77

8+
import BitcoinDevKit
89
import SwiftUI
910

1011
struct ActivityHomeHeaderView: View {
@@ -17,6 +18,7 @@ struct ActivityHomeHeaderView: View {
1718
let isKyotoClient: Bool
1819
let isKyotoConnected: Bool
1920
let currentBlockHeight: UInt32
21+
let kyotoNodeState: NodeState?
2022

2123
let showAllTransactions: () -> Void
2224

@@ -40,7 +42,13 @@ struct ActivityHomeHeaderView: View {
4042
} else if walletSyncState == .syncing {
4143
HStack {
4244
if isKyotoClient {
43-
if progress < 100.0 { // Kyoto progress is percent
45+
if let status = kyotoStatusText {
46+
Text(status)
47+
.padding(.trailing, -5.0)
48+
.fontWeight(.semibold)
49+
.contentTransition(.opacity)
50+
.transition(.opacity)
51+
} else if progress < 100.0 { // Kyoto progress is percent
4452
if currentBlockHeight > 0 {
4553
Text("Block \(currentBlockHeight)")
4654
.padding(.trailing, -5.0)
@@ -198,3 +206,28 @@ struct ActivityHomeHeaderView: View {
198206
}
199207
}
200208
}
209+
210+
extension ActivityHomeHeaderView {
211+
fileprivate var kyotoStatusText: String? {
212+
guard isKyotoClient, let kyotoNodeState else { return nil }
213+
// Kyoto's NodeState reflects the next stage it will enter, so describe upcoming work.
214+
switch kyotoNodeState {
215+
case .behind:
216+
// Still acquiring header tips, so call out the header sync explicitly.
217+
return "Getting headers..."
218+
case .headersSynced:
219+
// Kyoto reports this once headers are already finished, so surface the next
220+
// actionable phase the node is entering rather than the completed step.
221+
return "Preparing filters..."
222+
case .filterHeadersSynced:
223+
// Filter headers are ready; actual filter scanning starts next.
224+
return "Scanning filters..."
225+
case .filtersSynced:
226+
// Filters are exhausted; the node now gossips for matching blocks/txs.
227+
return "Fetching matches..."
228+
case .transactionsSynced:
229+
// No further phases—fall back to showing percent + standard synced UI.
230+
return nil
231+
}
232+
}
233+
}

BDKSwiftExampleWallet/View/WalletView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ struct WalletView: View {
5151
needsFullScan: viewModel.needsFullScan,
5252
isKyotoClient: viewModel.isKyotoClient,
5353
isKyotoConnected: viewModel.isKyotoConnected,
54-
currentBlockHeight: viewModel.currentBlockHeight
54+
currentBlockHeight: viewModel.currentBlockHeight,
55+
kyotoNodeState: viewModel.kyotoNodeState
5556
) {
5657
showAllTransactions = true
5758
}

0 commit comments

Comments
 (0)