Expose network state to iOS bridge
This commit is contained in:
@@ -2,6 +2,7 @@ import Foundation
|
||||
|
||||
public protocol SessionBridge: Sendable {
|
||||
func authState() async throws -> AuthState
|
||||
func networkState() async throws -> NetworkState
|
||||
func pollEvents() async throws -> [SessionEvent]
|
||||
func sendPhoneNumber(_ phone: String) async throws
|
||||
func sendCode(_ code: String) async throws
|
||||
@@ -66,6 +67,10 @@ public actor FakeSessionBridge: SessionBridge {
|
||||
auth
|
||||
}
|
||||
|
||||
public func networkState() async throws -> NetworkState {
|
||||
.ready
|
||||
}
|
||||
|
||||
public func pollEvents() async throws -> [SessionEvent] {
|
||||
let drained = events
|
||||
events.removeAll()
|
||||
|
||||
@@ -26,6 +26,10 @@ public actor UniFfiSessionBridge: SessionBridge {
|
||||
Self.mapAuthState(handle.authState())
|
||||
}
|
||||
|
||||
public func networkState() async throws -> NetworkState {
|
||||
Self.mapNetworkState(handle.networkState())
|
||||
}
|
||||
|
||||
public func pollEvents() async throws -> [SessionEvent] {
|
||||
handle.pollEvents().map(Self.mapEvent)
|
||||
}
|
||||
|
||||
@@ -24,10 +24,24 @@ public final class SessionStore: ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
public func refreshNetworkState() async {
|
||||
do {
|
||||
networkState = try await bridge.networkState()
|
||||
errorMessage = nil
|
||||
} catch {
|
||||
errorMessage = error.localizedDescription
|
||||
}
|
||||
}
|
||||
|
||||
public func apply(events: [SessionEvent]) {
|
||||
for event in events {
|
||||
if case let .authChanged(state) = event {
|
||||
switch event {
|
||||
case let .authChanged(state):
|
||||
authState = state
|
||||
case let .networkChanged(state):
|
||||
networkState = state
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ struct TeleTuiIOSSmokeTests {
|
||||
|
||||
await store.refreshAuthState()
|
||||
precondition(store.authState == .waitPhoneNumber)
|
||||
await store.refreshNetworkState()
|
||||
precondition(store.networkState == .ready)
|
||||
|
||||
viewModel.phone = "+10000000000"
|
||||
await viewModel.submitCurrentStep()
|
||||
|
||||
Reference in New Issue
Block a user