Skip to content

Commit c692929

Browse files
committed
feat: refresh connection state on reconnect
1 parent 642d881 commit c692929

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ extension CbfClient {
4141
let id = ObjectIdentifier(self)
4242

4343
let task = Task { [self] in
44-
var hasEstablishedConnection = false
4544
while true {
4645
if Task.isCancelled { break }
4746
do {
@@ -63,14 +62,11 @@ extension CbfClient {
6362
object: nil,
6463
userInfo: ["height": height]
6564
)
66-
if !hasEstablishedConnection {
67-
hasEstablishedConnection = true
68-
NotificationCenter.default.post(
69-
name: NSNotification.Name("KyotoConnectionUpdate"),
70-
object: nil,
71-
userInfo: ["connected": true]
72-
)
73-
}
65+
NotificationCenter.default.post(
66+
name: NSNotification.Name("KyotoConnectionUpdate"),
67+
object: nil,
68+
userInfo: ["connected": true]
69+
)
7470
}
7571
case .stateUpdate(let nodeState):
7672
await MainActor.run {
@@ -79,17 +75,19 @@ extension CbfClient {
7975
object: nil,
8076
userInfo: ["state": nodeState]
8177
)
78+
NotificationCenter.default.post(
79+
name: NSNotification.Name("KyotoConnectionUpdate"),
80+
object: nil,
81+
userInfo: ["connected": true]
82+
)
8283
}
8384
case .connectionsMet, .successfulHandshake:
8485
await MainActor.run {
85-
if !hasEstablishedConnection {
86-
hasEstablishedConnection = true
87-
NotificationCenter.default.post(
88-
name: NSNotification.Name("KyotoConnectionUpdate"),
89-
object: nil,
90-
userInfo: ["connected": true]
91-
)
92-
}
86+
NotificationCenter.default.post(
87+
name: NSNotification.Name("KyotoConnectionUpdate"),
88+
object: nil,
89+
userInfo: ["connected": true]
90+
)
9391
}
9492
default:
9593
break

0 commit comments

Comments
 (0)