-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sample): Third batch of sample app code
- Loading branch information
1 parent
dd262cf
commit b79e11f
Showing
8 changed files
with
390 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...etDemo/AtalaPrismWalletDemo/Modules/WalletDemo/ProofOfRequest/ProofOfRequestBuilder.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Combine | ||
import Foundation | ||
import PrismAgent | ||
import SwiftUI | ||
|
||
struct ProofOfRequestComponent: ComponentContainer { | ||
let proofOfRequest: RequestPresentation | ||
let container: DIContainer | ||
} | ||
|
||
struct ProofOfRequestBuilder: Builder { | ||
func build(component: ProofOfRequestComponent) -> some View { | ||
let viewModel = getViewModel(component: component) { | ||
ProofOfRequestViewModelImpl( | ||
proofOfRequest: component.proofOfRequest, | ||
agent: component.container.resolve(type: PrismAgent.self)! | ||
) | ||
} | ||
return ProofOfRequestView<ProofOfRequestViewModelImpl>(viewModel: viewModel) | ||
.onDisappear { | ||
component.container.unregister(type: ProofOfRequestViewModelImpl.self) | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...lletDemo/AtalaPrismWalletDemo/Modules/WalletDemo/ProofOfRequest/ProofOfRequestState.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Foundation | ||
struct ProofOfRequestState { | ||
enum FlowStep { | ||
case loading | ||
case shareCredentials | ||
case confirm | ||
case error(DisplayError) | ||
} | ||
|
||
enum RequestedCredentials { | ||
case idCredential | ||
case universityDegree | ||
case proofOfEmployment | ||
case insurance | ||
case custom(String) | ||
} | ||
|
||
struct Contact { | ||
let text: String | ||
// let credentialsRequested: [RequestedCredentials] | ||
} | ||
|
||
struct Credential { | ||
let id: String | ||
let text: String | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...alletDemo/AtalaPrismWalletDemo/Modules/WalletDemo/ProofOfRequest/ProofOfRequestView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import SwiftUI | ||
|
||
protocol ProofOfRequestViewModel: ProofOfRequestCheckViewModel { | ||
var flowStep: ProofOfRequestState.FlowStep { get } | ||
var dismiss: Bool { get } | ||
func viewDidAppear() | ||
func confirmDismiss() | ||
} | ||
|
||
struct ProofOfRequestView<ViewModel: ProofOfRequestViewModel>: View { | ||
@StateObject var viewModel: ViewModel | ||
@Environment(\.presentationMode) var presentationMode | ||
|
||
var body: some View { | ||
VStack { | ||
switch viewModel.flowStep { | ||
case .loading: | ||
ProgressView() | ||
.progressViewStyle( | ||
CircularProgressViewStyle() | ||
) | ||
.onAppear(perform: { | ||
self.viewModel.viewDidAppear() | ||
}) | ||
.frame(maxWidth: .infinity, maxHeight: 55) | ||
.commitDisablePreference() | ||
.disabled(true) | ||
case .shareCredentials: | ||
ProofOfRequestCheckView<ViewModel>() | ||
.environmentObject(viewModel) | ||
.commitDisablePreference() | ||
.disabled(viewModel.loading) | ||
case .confirm: | ||
VStack(spacing: 20) { | ||
Image("img_success") | ||
VStack(spacing: 5) { | ||
Text("credentials_detail_share_success_title".localize()) | ||
.font(.caption) | ||
.fontWeight(.light) | ||
Text("credentials_detail_share_success".localize()) | ||
.fontWeight(.heavy) | ||
.foregroundColor(.black) | ||
} | ||
|
||
Divider() | ||
|
||
AtalaButton { | ||
self.viewModel.confirmDismiss() | ||
} label: { | ||
Text("ok".localize()) | ||
} | ||
} | ||
.padding(24) | ||
.commitDisablePreference() | ||
.disabled(viewModel.loading) | ||
case let .error(error): | ||
ErrorDialogView(error: .constant(error)) { | ||
presentationMode.wrappedValue.dismiss() | ||
} | ||
} | ||
} | ||
.background(Color.white) | ||
.clipShape(RoundedRectangle(cornerRadius: 10)) | ||
.padding() | ||
.animation(.default) | ||
.onChange(of: viewModel.dismiss, perform: { value in | ||
if value { | ||
self.presentationMode.wrappedValue.dismiss() | ||
} | ||
}) | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...Demo/AtalaPrismWalletDemo/Modules/WalletDemo/ProofOfRequest/ProofOfRequestViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import Combine | ||
import Foundation | ||
import PrismAgent | ||
|
||
final class ProofOfRequestViewModelImpl: ProofOfRequestViewModel { | ||
@Published var contact: ProofOfRequestState.Contact = .init(text: "") | ||
@Published var flowStep: ProofOfRequestState.FlowStep = .loading | ||
@Published var credential = [ProofOfRequestState.Credential]() | ||
@Published var checks = [Bool]() | ||
@Published var loading = false | ||
@Published var dismiss = false | ||
|
||
private let proofOfRequest: RequestPresentation | ||
private let agent: PrismAgent | ||
private var cancellables = Set<AnyCancellable>() | ||
|
||
init( | ||
proofOfRequest: RequestPresentation, | ||
agent: PrismAgent | ||
) { | ||
self.proofOfRequest = proofOfRequest | ||
self.agent = agent | ||
} | ||
|
||
func viewDidAppear() { | ||
bind() | ||
} | ||
|
||
func sendPresentation() { | ||
guard !loading else { return } | ||
loading = true | ||
} | ||
|
||
func share() { | ||
|
||
} | ||
|
||
func confirmDismiss() { | ||
// proofOfRequestRepository | ||
// .processedProofOfRequest(proofOfRequest) | ||
// .receive(on: DispatchQueue.main) | ||
// .sink { [weak self] _ in | ||
// self?.dismiss = true | ||
// } receiveValue: {} | ||
// .store(in: &cancellables) | ||
} | ||
|
||
private func bind() { | ||
// let proofOfRequest = proofOfRequest | ||
// | ||
// contactsRepository | ||
// .getAll() | ||
// .map { $0.first { $0.token == proofOfRequest.connectionToken } } | ||
// .first() | ||
// .replaceError(with: nil) | ||
// .dropNil() | ||
// .map { [weak self] in | ||
// self?.contactDomain = $0 | ||
// return ProofOfRequestState.Contact( | ||
// icon: $0.logo.map { .data($0) } ?? .credential, | ||
// text: $0.name, | ||
// credentialsRequested: mapTypeIDs(proofOfRequest.typeIds) | ||
// ) | ||
// } | ||
// .receive(on: DispatchQueue.main) | ||
// .assign(to: &$contact) | ||
// | ||
// credentialsRepository | ||
// .getAll() | ||
// .replaceError(with: []) | ||
// .map { $0.filter { proofOfRequest.typeIds.contains($0.type) } } | ||
// .first() | ||
// .map { | ||
// $0.map { | ||
// ProofOfRequestState.Credential( | ||
// id: $0.id, | ||
// text: $0.credentialName | ||
// ) | ||
// } | ||
// } | ||
// .receive(on: DispatchQueue.main) | ||
// .sink { [weak self] credentials in | ||
// self?.credential = credentials | ||
// self?.checks = credentials.map { _ in false } | ||
// self?.loading = false | ||
// self?.flowStep = .shareCredentials | ||
// } | ||
// .store(in: &cancellables) | ||
} | ||
} | ||
|
||
private func mapTypeIDs( | ||
_ ids: [String] | ||
) -> [ProofOfRequestState.RequestedCredentials] { | ||
ids.map { mapTypeID($0) } | ||
} | ||
|
||
private func mapTypeID( | ||
_ id: String | ||
) -> ProofOfRequestState.RequestedCredentials { | ||
switch id { | ||
case "ID Government": | ||
return .idCredential | ||
case "University Degree": | ||
return .universityDegree | ||
case "Proof of employment": | ||
return .proofOfEmployment | ||
case "Insurance Credential": | ||
return .insurance | ||
default: | ||
return .custom(id) | ||
} | ||
} |
Oops, something went wrong.