diff --git a/Example/example-app/Sources/MyIdentityFeature/MyIdentityView.swift b/Example/example-app/Sources/MyIdentityFeature/MyIdentityView.swift index 62cea2bbfa8095805777cdb74b91e8e460637575..61e09c1355755a7f1955e91ad7054d78f3689f5a 100644 --- a/Example/example-app/Sources/MyIdentityFeature/MyIdentityView.swift +++ b/Example/example-app/Sources/MyIdentityFeature/MyIdentityView.swift @@ -1,4 +1,7 @@ import ComposableArchitecture +import ComposablePresentation +import ElixxirDAppsSDK +import ErrorFeature import SwiftUI public struct MyIdentityView: View { @@ -9,15 +12,71 @@ public struct MyIdentityView: View { let store: Store<MyIdentityState, MyIdentityAction> struct ViewState: Equatable { - init(state: MyIdentityState) {} + let identity: Identity? + let isMakingIdentity: Bool + + init(state: MyIdentityState) { + identity = state.identity + isMakingIdentity = state.isMakingIdentity + } + + var isLoading: Bool { + isMakingIdentity + } } public var body: some View { WithViewStore(store.scope(state: ViewState.init)) { viewStore in - Text("MyIdentityView") - .task { - viewStore.send(.viewDidLoad) + Form { + Section { + Text(string(for: viewStore.identity)) + .textSelection(.enabled) + } + + Section { + Button { + viewStore.send(.makeIdentity) + } label: { + HStack { + Text("Make new identity") + Spacer() + if viewStore.isMakingIdentity { + ProgressView() + } + } + } } + .disabled(viewStore.isLoading) + } + .navigationTitle("My identity") + .navigationBarBackButtonHidden(viewStore.isLoading) + .task { + viewStore.send(.viewDidLoad) + } + .sheet( + store.scope( + state: \.error, + action: MyIdentityAction.error + ), + onDismiss: { + viewStore.send(.didDismissError) + }, + content: ErrorView.init(store:) + ) + } + } + + func string(for identity: Identity?) -> String { + guard let identity = identity else { + return "No identity" + } + let encoder = JSONEncoder() + encoder.outputFormatting = .prettyPrinted + do { + let data = try encoder.encode(identity) + return String(data: data, encoding: .utf8) ?? "Decoding error" + } catch { + return "Decoding error: \(error)" } } }