-
Notifications
You must be signed in to change notification settings - Fork 9
/
FactorSourceAccess+View.swift
110 lines (96 loc) · 2.89 KB
/
FactorSourceAccess+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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// MARK: - FactorSourceAccess.View
extension FactorSourceAccess {
struct ViewState: Equatable {
let title: String
let message: String
let externalDevice: String?
let isRetryEnabled: Bool
let height: CGFloat
}
@MainActor
struct View: SwiftUI.View {
private let store: StoreOf<FactorSourceAccess>
init(store: StoreOf<FactorSourceAccess>) {
self.store = store
}
var body: some SwiftUI.View {
WithViewStore(store, observe: \.viewState, send: { .view($0) }) { viewStore in
content(viewStore)
.withNavigationBar {
viewStore.send(.closeButtonTapped)
}
.presentationDetents([.fraction(viewStore.height), .large])
.presentationDragIndicator(.visible)
.interactiveDismissDisabled()
.presentationBackground(.blur)
.onFirstTask { @MainActor in
await store.send(.view(.onFirstTask)).finish()
}
.destinations(with: store)
}
}
@ViewBuilder
private func content(_ viewStore: ViewStoreOf<FactorSourceAccess>) -> some SwiftUI.View {
VStack(spacing: .medium3) {
Image(asset: AssetResource.signingKey)
.foregroundColor(.app.gray3)
Text(viewStore.title)
.textStyle(.sheetTitle)
.foregroundColor(.app.gray1)
Text(LocalizedStringKey(viewStore.message))
.textStyle(.body1Regular)
.foregroundColor(.app.gray1)
externalDevice(viewStore.externalDevice)
if viewStore.isRetryEnabled {
Button {
viewStore.send(.retryButtonTapped)
} label: {
Text(L10n.Common.retry)
.textStyle(.body1Header)
.foregroundColor(.app.blue2)
.frame(height: .standardButtonHeight)
.frame(maxWidth: .infinity)
}
}
}
.multilineTextAlignment(.center)
.padding(.horizontal, .large2)
}
@ViewBuilder
private func externalDevice(_ value: String?) -> some SwiftUI.View {
if let value {
HStack(spacing: .medium3) {
Image(asset: AssetResource.signingKey)
.resizable()
.frame(.smallest)
.foregroundColor(.app.gray3)
Text(value)
.textStyle(.secondaryHeader)
.foregroundColor(.app.gray1)
.padding(.trailing, .small2)
}
.padding(.medium2)
.background(Color.app.gray5)
.cornerRadius(.large1)
}
}
}
}
private extension StoreOf<FactorSourceAccess> {
var destination: PresentationStoreOf<FactorSourceAccess.Destination> {
func scopeState(state: State) -> PresentationState<FactorSourceAccess.Destination.State> {
state.$destination
}
return scope(state: scopeState, action: Action.destination)
}
}
@MainActor
private extension View {
func destinations(with store: StoreOf<FactorSourceAccess>) -> some View {
let destinationStore = store.destination
return noP2PLinkAlert(with: destinationStore)
}
private func noP2PLinkAlert(with destinationStore: PresentationStoreOf<FactorSourceAccess.Destination>) -> some View {
alert(store: destinationStore.scope(state: \.noP2PLink, action: \.noP2PLink))
}
}