-
Notifications
You must be signed in to change notification settings - Fork 9
/
DebugKeychainContents+View.swift
83 lines (72 loc) · 2.25 KB
/
DebugKeychainContents+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
#if DEBUG
extension DebugKeychainContents.State {
var viewState: DebugKeychainContents.ViewState {
.init(keyedMnemonics: keyedMnemonics.elements)
}
}
// MARK: - DebugKeychainContents.View
extension DebugKeychainContents {
public struct ViewState: Equatable {
let keyedMnemonics: [KeyedMnemonicWithMetadata]
}
@MainActor
public struct View: SwiftUI.View {
private let store: StoreOf<DebugKeychainContents>
public init(store: StoreOf<DebugKeychainContents>) {
self.store = store
}
public var body: some SwiftUI.View {
WithViewStore(store, observe: \.viewState, send: { .view($0) }) { viewStore in
VStack(alignment: .leading) {
Form {
ForEach(viewStore.keyedMnemonics, id: \.self) { keyedMnemonic in
KeyedMnemonicView(keyedMnemonic) {
viewStore.send(.deleteMnemonicByFactorSourceID(keyedMnemonic.id))
}
}
}
Button("Delete All") {
viewStore.send(.deleteAllMnemonics)
}
.padding()
.buttonStyle(.primaryRectangular(isDestructive: true))
}
.task { @MainActor in
await viewStore.send(.task).finish()
}
}
}
}
}
struct KeyedMnemonicView: SwiftUI.View {
let keyedMnemonicWithMetadata: KeyedMnemonicWithMetadata
var keyedMnemonicWithPassphrase: KeyedMnemonicWithPassphrase { keyedMnemonicWithMetadata.keyedMnemonic }
let delete: @Sendable () -> Void
init(_ keyedMnemonicWithMetadata: KeyedMnemonicWithMetadata, delete: @escaping @Sendable () -> Void) {
self.keyedMnemonicWithMetadata = keyedMnemonicWithMetadata
self.delete = delete
}
var body: some SwiftUI.View {
VStack {
Text("`\(keyedMnemonicWithPassphrase.factorSourceID.description)`")
.textStyle(.body3HighImportance)
if let entitiesControlledByFactorSource = keyedMnemonicWithMetadata.entitiesControlledByFactorSource {
VStack(alignment: .leading, spacing: .small3) {
ForEach(entitiesControlledByFactorSource.accounts) { account in
SmallAccountCard(account: account)
.cornerRadius(.small1)
}
}
} else {
Text("❌ Unknown by current Profile")
}
Text("*\(keyedMnemonicWithPassphrase.mnemonicWithPassphrase.mnemonic.phrase)*")
Button("Delete") {
delete()
}
.padding()
.buttonStyle(.primaryRectangular(isDestructive: true))
}
}
}
#endif // DEBUG