Skip to content

Commit

Permalink
feat(sample): Third batch of sample app code
Browse files Browse the repository at this point in the history
  • Loading branch information
goncalo-frade-iohk committed Jan 10, 2023
1 parent dd262cf commit b79e11f
Show file tree
Hide file tree
Showing 8 changed files with 390 additions and 0 deletions.
4 changes: 4 additions & 0 deletions PrismAgent/Sources/PrismAgent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,8 @@ public class PrismAgent {
.flatMap { $0.publisher }
.eraseToAnyPublisher()
}

public func verifiableCredentials() -> AnyPublisher<[VerifiableCredential], Error> {
pluto.getAllCredentials()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
EE75A32B294A822C007D4405 /* ErrorDialogView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE75A32A294A822C007D4405 /* ErrorDialogView.swift */; };
EE75A32D294A82A4007D4405 /* RoundedRectWithBorderText.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE75A32C294A82A4007D4405 /* RoundedRectWithBorderText.swift */; };
EE75A32F294A8D55007D4405 /* DisplayErrorState.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE75A32E294A8D55007D4405 /* DisplayErrorState.swift */; };
EE75A337294A905F007D4405 /* ProofOfRequestCheckView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE75A332294A905F007D4405 /* ProofOfRequestCheckView.swift */; };
EE75A338294A905F007D4405 /* ProofOfRequestBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE75A333294A905F007D4405 /* ProofOfRequestBuilder.swift */; };
EE75A339294A905F007D4405 /* ProofOfRequestState.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE75A334294A905F007D4405 /* ProofOfRequestState.swift */; };
EE75A33A294A905F007D4405 /* ProofOfRequestViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE75A335294A905F007D4405 /* ProofOfRequestViewModel.swift */; };
EE75A33B294A905F007D4405 /* ProofOfRequestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE75A336294A905F007D4405 /* ProofOfRequestView.swift */; };
EE75A33D294A9172007D4405 /* CheckButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE75A33C294A9172007D4405 /* CheckButton.swift */; };
EEB7D32229420180006E076D /* SetupPrismAgentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEB7D32129420180006E076D /* SetupPrismAgentView.swift */; };
EEB7D3242942018C006E076D /* SetupPrismAgentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEB7D3232942018C006E076D /* SetupPrismAgentViewModel.swift */; };
EEE61FBA2937CA280053AE52 /* AtalaPrismWalletDemoApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE61FB92937CA280053AE52 /* AtalaPrismWalletDemoApp.swift */; };
Expand Down Expand Up @@ -160,6 +166,12 @@
EE75A32A294A822C007D4405 /* ErrorDialogView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorDialogView.swift; sourceTree = "<group>"; };
EE75A32C294A82A4007D4405 /* RoundedRectWithBorderText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundedRectWithBorderText.swift; sourceTree = "<group>"; };
EE75A32E294A8D55007D4405 /* DisplayErrorState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayErrorState.swift; sourceTree = "<group>"; };
EE75A332294A905F007D4405 /* ProofOfRequestCheckView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProofOfRequestCheckView.swift; sourceTree = "<group>"; };
EE75A333294A905F007D4405 /* ProofOfRequestBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProofOfRequestBuilder.swift; sourceTree = "<group>"; };
EE75A334294A905F007D4405 /* ProofOfRequestState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProofOfRequestState.swift; sourceTree = "<group>"; };
EE75A335294A905F007D4405 /* ProofOfRequestViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProofOfRequestViewModel.swift; sourceTree = "<group>"; };
EE75A336294A905F007D4405 /* ProofOfRequestView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProofOfRequestView.swift; sourceTree = "<group>"; };
EE75A33C294A9172007D4405 /* CheckButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckButton.swift; sourceTree = "<group>"; };
EEB7D32129420180006E076D /* SetupPrismAgentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetupPrismAgentView.swift; sourceTree = "<group>"; };
EEB7D3232942018C006E076D /* SetupPrismAgentViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetupPrismAgentViewModel.swift; sourceTree = "<group>"; };
EEE61FB62937CA280053AE52 /* AtalaPrismWalletDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AtalaPrismWalletDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -228,6 +240,7 @@
EE6C38CA29462474006CD2D3 /* WalletDemo */ = {
isa = PBXGroup;
children = (
EE75A330294A905F007D4405 /* ProofOfRequest */,
EE75A314294A7CAE007D4405 /* AddNewContact */,
EE75A309294A34E1007D4405 /* CredentialDetail */,
EE75A2FC294A33D0007D4405 /* CredentialsList */,
Expand Down Expand Up @@ -264,6 +277,7 @@
EE75A32A294A822C007D4405 /* ErrorDialogView.swift */,
EE75A32C294A82A4007D4405 /* RoundedRectWithBorderText.swift */,
EE75A32E294A8D55007D4405 /* DisplayErrorState.swift */,
EE75A33C294A9172007D4405 /* CheckButton.swift */,
);
path = UIHelper;
sourceTree = "<group>";
Expand Down Expand Up @@ -377,6 +391,26 @@
path = UI;
sourceTree = "<group>";
};
EE75A330294A905F007D4405 /* ProofOfRequest */ = {
isa = PBXGroup;
children = (
EE75A331294A905F007D4405 /* UI */,
EE75A333294A905F007D4405 /* ProofOfRequestBuilder.swift */,
EE75A334294A905F007D4405 /* ProofOfRequestState.swift */,
EE75A335294A905F007D4405 /* ProofOfRequestViewModel.swift */,
EE75A336294A905F007D4405 /* ProofOfRequestView.swift */,
);
path = ProofOfRequest;
sourceTree = "<group>";
};
EE75A331294A905F007D4405 /* UI */ = {
isa = PBXGroup;
children = (
EE75A332294A905F007D4405 /* ProofOfRequestCheckView.swift */,
);
path = UI;
sourceTree = "<group>";
};
EEB7D32029420155006E076D /* SetupPrismAgent */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -590,6 +624,7 @@
files = (
EE75A303294A33D0007D4405 /* CredentialsListViewModel.swift in Sources */,
EE75A2FB29487F36007D4405 /* MainViewModel.swift in Sources */,
EE75A33D294A9172007D4405 /* CheckButton.swift in Sources */,
EE75A323294A7CAE007D4405 /* AddNewContactViewModel.swift in Sources */,
EEB7D3242942018C006E076D /* SetupPrismAgentViewModel.swift in Sources */,
EEE620132937F1D40053AE52 /* PrintObjects.swift in Sources */,
Expand All @@ -599,13 +634,15 @@
EE6C39172946851D006CD2D3 /* QRCodeScannerBuilder.swift in Sources */,
EE6C39152946851D006CD2D3 /* QRScannerView.swift in Sources */,
EEE61FE02937CEAA0053AE52 /* SeedViewModel.swift in Sources */,
EE75A33A294A905F007D4405 /* ProofOfRequestViewModel.swift in Sources */,
EE75A302294A33D0007D4405 /* CredentialsListView.swift in Sources */,
EE6C393929468533006CD2D3 /* HomeState.swift in Sources */,
EE6C38DC294626E1006CD2D3 /* String+extensions.swift in Sources */,
EEE61FE82937D7EE0053AE52 /* DIDFuncionalitiesView.swift in Sources */,
EEE61FBC2937CA280053AE52 /* FuncionalitiesList.swift in Sources */,
EE75A327294A7D40007D4405 /* Button+Configuration.swift in Sources */,
EE6C3909294683C4006CD2D3 /* DashboardRouter.swift in Sources */,
EE75A339294A905F007D4405 /* ProofOfRequestState.swift in Sources */,
EEE61FDD2937CD7A0053AE52 /* SeedFuncionalitiesView.swift in Sources */,
EE75A325294A7D0F007D4405 /* AtalaButton.swift in Sources */,
EE6C38EE29467A9D006CD2D3 /* DisablePreferenceKey.swift in Sources */,
Expand All @@ -616,6 +653,7 @@
EE75A32B294A822C007D4405 /* ErrorDialogView.swift in Sources */,
EE75A305294A33D0007D4405 /* CredentialsListRouter.swift in Sources */,
EE75A31E294A7CAE007D4405 /* AlreadyConnectedView.swift in Sources */,
EE75A337294A905F007D4405 /* ProofOfRequestCheckView.swift in Sources */,
EE75A311294A34E1007D4405 /* CredentialDetailNeoView.swift in Sources */,
EE75A30E294A34E1007D4405 /* CredentialDetailViewModel.swift in Sources */,
EE6C38EC29467A7A006CD2D3 /* ClearFullCoverModifier.swift in Sources */,
Expand Down Expand Up @@ -645,6 +683,7 @@
EE6C393129468533006CD2D3 /* ActivityListView.swift in Sources */,
EE75A308294A346B007D4405 /* NavigationTypeUtilModifiers.swift in Sources */,
EE6C390329468288006CD2D3 /* Builder.swift in Sources */,
EE75A338294A905F007D4405 /* ProofOfRequestBuilder.swift in Sources */,
EE6C39182946851D006CD2D3 /* QRCodeScannerView.swift in Sources */,
EE6C38EA29467A36006CD2D3 /* DashboardView.swift in Sources */,
EE75A320294A7CAE007D4405 /* InsertCodeView.swift in Sources */,
Expand All @@ -654,6 +693,7 @@
EEB7D32229420180006E076D /* SetupPrismAgentView.swift in Sources */,
EE6C38F029468196006CD2D3 /* DIContainer.swift in Sources */,
EE75A306294A33D0007D4405 /* CredentialsListState.swift in Sources */,
EE75A33B294A905F007D4405 /* ProofOfRequestView.swift in Sources */,
EE6C393829468533006CD2D3 /* HomeBuilder.swift in Sources */,
EE75A32F294A8D55007D4405 /* DisplayErrorState.swift in Sources */,
EEE620162937F3110053AE52 /* SigningVerificationViewModel.swift in Sources */,
Expand Down
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)
}
}
}
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
}
}
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()
}
})
}
}
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)
}
}
Loading

0 comments on commit b79e11f

Please sign in to comment.