Skip to content
Snippets Groups Projects
Commit 5b765fd9 authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Present errors in landing feature

parent c232f245
No related branches found
No related tags found
1 merge request!1Client management
...@@ -56,6 +56,7 @@ let package = Package( ...@@ -56,6 +56,7 @@ let package = Package(
.target( .target(
name: "AppFeature", name: "AppFeature",
dependencies: [ dependencies: [
.target(name: "ErrorFeature"),
.target(name: "LandingFeature"), .target(name: "LandingFeature"),
.target(name: "SessionFeature"), .target(name: "SessionFeature"),
.product( .product(
...@@ -108,10 +109,15 @@ let package = Package( ...@@ -108,10 +109,15 @@ let package = Package(
.target( .target(
name: "LandingFeature", name: "LandingFeature",
dependencies: [ dependencies: [
.target(name: "ErrorFeature"),
.product( .product(
name: "ComposableArchitecture", name: "ComposableArchitecture",
package: "swift-composable-architecture" package: "swift-composable-architecture"
), ),
.product(
name: "ComposablePresentation",
package: "swift-composable-presentation"
),
.product( .product(
name: "ElixxirDAppsSDK", name: "ElixxirDAppsSDK",
package: "elixxir-dapps-sdk-swift" package: "elixxir-dapps-sdk-swift"
......
import Combine import Combine
import ComposableArchitecture import ComposableArchitecture
import ElixxirDAppsSDK import ElixxirDAppsSDK
import ErrorFeature
import LandingFeature import LandingFeature
import SessionFeature import SessionFeature
import SwiftUI import SwiftUI
...@@ -36,7 +37,8 @@ extension AppEnvironment { ...@@ -36,7 +37,8 @@ extension AppEnvironment {
), ),
setClient: { clientSubject.send($0) }, setClient: { clientSubject.send($0) },
bgScheduler: bgScheduler, bgScheduler: bgScheduler,
mainScheduler: mainScheduler mainScheduler: mainScheduler,
error: ErrorEnvironment()
), ),
session: SessionEnvironment() session: SessionEnvironment()
) )
......
...@@ -6,7 +6,7 @@ public struct ErrorState: Equatable { ...@@ -6,7 +6,7 @@ public struct ErrorState: Equatable {
self.error = error self.error = error
} }
var error: NSError public var error: NSError
} }
public enum ErrorAction: Equatable {} public enum ErrorAction: Equatable {}
......
import Combine import Combine
import ComposableArchitecture import ComposableArchitecture
import ElixxirDAppsSDK import ElixxirDAppsSDK
import ErrorFeature
public struct LandingState: Equatable { public struct LandingState: Equatable {
public init( public init(
hasStoredClient: Bool = false, hasStoredClient: Bool = false,
isMakingClient: Bool = false, isMakingClient: Bool = false,
isRemovingClient: Bool = false isRemovingClient: Bool = false,
error: ErrorState? = nil
) { ) {
self.hasStoredClient = hasStoredClient self.hasStoredClient = hasStoredClient
self.isMakingClient = isMakingClient self.isMakingClient = isMakingClient
self.isRemovingClient = isRemovingClient self.isRemovingClient = isRemovingClient
self.error = error
} }
var hasStoredClient: Bool var hasStoredClient: Bool
var isMakingClient: Bool var isMakingClient: Bool
var isRemovingClient: Bool var isRemovingClient: Bool
var error: ErrorState?
} }
public enum LandingAction: Equatable { public enum LandingAction: Equatable {
...@@ -26,6 +30,8 @@ public enum LandingAction: Equatable { ...@@ -26,6 +30,8 @@ public enum LandingAction: Equatable {
case removeStoredClient case removeStoredClient
case didRemoveStoredClient case didRemoveStoredClient
case didFailRemovingStoredClient(NSError) case didFailRemovingStoredClient(NSError)
case didDismissError
case error(ErrorAction)
} }
public struct LandingEnvironment { public struct LandingEnvironment {
...@@ -33,18 +39,21 @@ public struct LandingEnvironment { ...@@ -33,18 +39,21 @@ public struct LandingEnvironment {
clientStorage: ClientStorage, clientStorage: ClientStorage,
setClient: @escaping (Client) -> Void, setClient: @escaping (Client) -> Void,
bgScheduler: AnySchedulerOf<DispatchQueue>, bgScheduler: AnySchedulerOf<DispatchQueue>,
mainScheduler: AnySchedulerOf<DispatchQueue> mainScheduler: AnySchedulerOf<DispatchQueue>,
error: ErrorEnvironment
) { ) {
self.clientStorage = clientStorage self.clientStorage = clientStorage
self.setClient = setClient self.setClient = setClient
self.bgScheduler = bgScheduler self.bgScheduler = bgScheduler
self.mainScheduler = mainScheduler self.mainScheduler = mainScheduler
self.error = error
} }
public var clientStorage: ClientStorage public var clientStorage: ClientStorage
public var setClient: (Client) -> Void public var setClient: (Client) -> Void
public var bgScheduler: AnySchedulerOf<DispatchQueue> public var bgScheduler: AnySchedulerOf<DispatchQueue>
public var mainScheduler: AnySchedulerOf<DispatchQueue> public var mainScheduler: AnySchedulerOf<DispatchQueue>
public var error: ErrorEnvironment
} }
public let landingReducer = Reducer<LandingState, LandingAction, LandingEnvironment> public let landingReducer = Reducer<LandingState, LandingAction, LandingEnvironment>
...@@ -80,7 +89,7 @@ public let landingReducer = Reducer<LandingState, LandingAction, LandingEnvironm ...@@ -80,7 +89,7 @@ public let landingReducer = Reducer<LandingState, LandingAction, LandingEnvironm
case .didFailMakingClient(let error): case .didFailMakingClient(let error):
state.isMakingClient = false state.isMakingClient = false
state.hasStoredClient = env.clientStorage.hasStoredClient() state.hasStoredClient = env.clientStorage.hasStoredClient()
// TODO: handle error state.error = ErrorState(error: error)
return .none return .none
case .removeStoredClient: case .removeStoredClient:
...@@ -105,10 +114,21 @@ public let landingReducer = Reducer<LandingState, LandingAction, LandingEnvironm ...@@ -105,10 +114,21 @@ public let landingReducer = Reducer<LandingState, LandingAction, LandingEnvironm
case .didFailRemovingStoredClient(let error): case .didFailRemovingStoredClient(let error):
state.isRemovingClient = false state.isRemovingClient = false
state.hasStoredClient = env.clientStorage.hasStoredClient() state.hasStoredClient = env.clientStorage.hasStoredClient()
// TODO: handle error state.error = ErrorState(error: error)
return .none
case .didDismissError:
state.error = nil
return .none return .none
} }
} }
.presenting(
errorReducer,
state: .keyPath(\.error),
id: .keyPath(\.?.error),
action: /LandingAction.error,
environment: \.error
)
#if DEBUG #if DEBUG
extension LandingEnvironment { extension LandingEnvironment {
...@@ -116,7 +136,8 @@ extension LandingEnvironment { ...@@ -116,7 +136,8 @@ extension LandingEnvironment {
clientStorage: .failing, clientStorage: .failing,
setClient: { _ in fatalError() }, setClient: { _ in fatalError() },
bgScheduler: .failing, bgScheduler: .failing,
mainScheduler: .failing mainScheduler: .failing,
error: .failing
) )
} }
#endif #endif
import ComposableArchitecture import ComposableArchitecture
import ComposablePresentation
import ErrorFeature
import SwiftUI import SwiftUI
public struct LandingView: View { public struct LandingView: View {
...@@ -59,6 +61,16 @@ public struct LandingView: View { ...@@ -59,6 +61,16 @@ public struct LandingView: View {
.task { .task {
viewStore.send(.viewDidLoad) viewStore.send(.viewDidLoad)
} }
.sheet(
store.scope(
state: \.error,
action: LandingAction.error
),
onDismiss: {
viewStore.send(.didDismissError)
},
content: ErrorView.init(store:)
)
} }
} }
} }
......
import ComposableArchitecture import ComposableArchitecture
import ErrorFeature
import XCTest import XCTest
@testable import LandingFeature @testable import LandingFeature
...@@ -115,6 +116,7 @@ final class LandingFeatureTests: XCTestCase { ...@@ -115,6 +116,7 @@ final class LandingFeatureTests: XCTestCase {
store.receive(.didFailMakingClient(error)) { store.receive(.didFailMakingClient(error)) {
$0.isMakingClient = false $0.isMakingClient = false
$0.hasStoredClient = false $0.hasStoredClient = false
$0.error = ErrorState(error: error)
} }
} }
...@@ -180,6 +182,7 @@ final class LandingFeatureTests: XCTestCase { ...@@ -180,6 +182,7 @@ final class LandingFeatureTests: XCTestCase {
store.receive(.didFailRemovingStoredClient(error)) { store.receive(.didFailRemovingStoredClient(error)) {
$0.isRemovingClient = false $0.isRemovingClient = false
$0.hasStoredClient = true $0.hasStoredClient = true
$0.error = ErrorState(error: error)
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment