-
Notifications
You must be signed in to change notification settings - Fork 9
/
Main+View.swift
79 lines (68 loc) · 1.63 KB
/
Main+View.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import ComposableArchitecture
import SwiftUI
extension Main.State {
public var showIsUsingTestnetBanner: Bool {
!isOnMainnet
}
}
// MARK: - Main.View
extension Main {
@MainActor
public struct View: SwiftUI.View {
private let store: StoreOf<Main>
public init(store: StoreOf<Main>) {
self.store = store
}
public var body: some SwiftUI.View {
NavigationStack {
Home.View(store: store.home)
.destinations(with: store)
}
.task { @MainActor in
await store.send(.view(.task)).finish()
}
.showDeveloperDisclaimerBanner(store.banner)
.presentsDappInteractions()
}
}
}
private extension StoreOf<Main> {
var destination: PresentationStoreOf<Main.Destination> {
func scopeState(state: State) -> PresentationState<Main.Destination.State> {
state.$destination
}
return scope(state: scopeState, action: Action.destination)
}
var banner: Store<Bool, Never> {
scope(state: \.showIsUsingTestnetBanner, action: actionless)
}
var home: StoreOf<Home> {
scope(state: \.home, action: \.child.home)
}
}
@MainActor
private extension View {
func destinations(with store: StoreOf<Main>) -> some View {
let destinationStore = store.destination
return navigationDestination(store: destinationStore.scope(state: \.settings, action: \.settings)) {
Settings.View(store: $0)
}
}
}
#if DEBUG
import ComposableArchitecture
import SwiftUI
struct MainView_Previews: PreviewProvider {
static var previews: some SwiftUI.View {
Main.View(
store: .init(
initialState: .previewValue,
reducer: Main.init
)
)
}
}
extension Main.State {
public static let previewValue = Self(home: .previewValue)
}
#endif