Skip to content

Commit

Permalink
Add displayName property to DocElementsViewModel struct
Browse files Browse the repository at this point in the history
  • Loading branch information
phisakel committed Sep 27, 2024
1 parent 0bc11af commit c5fe752
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
14 changes: 7 additions & 7 deletions Sources/EudiWalletKit/Services/PresentationSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import LocalAuthentication
/// This class wraps the ``PresentationService`` instance, providing bindable fields to a SwifUI view
public class PresentationSession: ObservableObject {
public var presentationService: any PresentationService
/// Reader certificate issuer (only for BLE flow wih verifier using reader authentication)
/// Reader certificate issuer (the Common Name (CN) from the verifier's certificate)
@Published public var readerCertIssuer: String?
/// Reader legal name (if provided)
@Published public var readerLegalName: String?
Expand All @@ -44,12 +44,12 @@ public class PresentationSession: ObservableObject {
var handleSelected: ((Bool, RequestItems?) -> Void)?
/// Device engagement data (QR data for the BLE flow)
@Published public var deviceEngagement: String?
// map of document id to doc types
public var docIdAndTypes: [String: String]
// map of document id to (doc type, display name) pairs
public var docIdAndTypes: [String: (String, String?)]
/// User authentication required
var userAuthenticationRequired: Bool

public init(presentationService: any PresentationService, docIdAndTypes: [String: String], userAuthenticationRequired: Bool) {
public init(presentationService: any PresentationService, docIdAndTypes: [String: (String, String?)], userAuthenticationRequired: Bool) {
self.presentationService = presentationService
self.docIdAndTypes = docIdAndTypes
self.userAuthenticationRequired = userAuthenticationRequired
Expand All @@ -65,10 +65,10 @@ public class PresentationSession: ObservableObject {
// show the items as checkboxes
guard let validRequestItems = request[UserRequestKeys.valid_items_requested.rawValue] as? RequestItems else { return }
disclosedDocuments = [DocElementsViewModel]()
for (docId, docType) in docIdAndTypes {
var tmp = validRequestItems.toDocElementViewModels(docId: docId, docType: docType, valid: true)
for (docId, (docType, displayName)) in docIdAndTypes {
var tmp = validRequestItems.toDocElementViewModels(docId: docId, docType: docType, displayName: displayName, valid: true)
if let errorRequestItems = request[UserRequestKeys.error_items_requested.rawValue] as? RequestItems, errorRequestItems.count > 0 {
tmp = tmp.merging(with: errorRequestItems.toDocElementViewModels(docId: docId, docType: docType, valid: false))
tmp = tmp.merging(with: errorRequestItems.toDocElementViewModels(docId: docId, docType: docType, displayName: displayName, valid: false))
}
disclosedDocuments.append(contentsOf: tmp)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/EudiWalletKit/Services/StorageManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public class StorageManager: ObservableObject {
return retModel
}

public func getDocIdsToTypes() -> [String: String] {
Dictionary(uniqueKeysWithValues: mdocModels.map { m in (m.id, m.docType) })
public func getDocIdsToTypes() -> [String: (String, String?)] {
Dictionary(uniqueKeysWithValues: mdocModels.map { m in (m.id, (m.docType, m.displayName) ) })
}

/// Load documents from storage
Expand Down
7 changes: 4 additions & 3 deletions Sources/EudiWalletKit/ViewModels/DocElementsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public struct DocElementsViewModel: Identifiable {
public var id: String { docId }
public var docId: String
public let docType: String
public let displayName: String?
public var isEnabled: Bool
public var elements: [ElementViewModel]
}
Expand All @@ -47,10 +48,10 @@ extension DocElementsViewModel {
}

extension RequestItems {
func toDocElementViewModels(docId: String, docType: String, valid: Bool) -> [DocElementsViewModel] {
func toDocElementViewModels(docId: String, docType: String, displayName: String?, valid: Bool) -> [DocElementsViewModel] {
compactMap { dType,nsItems in
if dType != docType { nil }
else { DocElementsViewModel(docId: docId, docType: docType, isEnabled: valid, elements: DocElementsViewModel.fluttenItemViewModels(nsItems, valid: valid, mandatoryElementKeys: DocElementsViewModel.getMandatoryElementKeys(docType: docType))) }
else { DocElementsViewModel(docId: docId, docType: docType, displayName: displayName, isEnabled: valid, elements: DocElementsViewModel.fluttenItemViewModels(nsItems, valid: valid, mandatoryElementKeys: DocElementsViewModel.getMandatoryElementKeys(docType: docType))) }
}
}
}
Expand All @@ -63,7 +64,7 @@ extension Array where Element == DocElementsViewModel {
for otherDE in other {
if let exist = first(where: { $0.docId == otherDE.docId}) {
let newElements = (exist.elements + otherDE.elements).sorted(by: { $0.isEnabled && $1.isDisabled })
res.append(DocElementsViewModel(docId: exist.docId, docType: exist.docType, isEnabled: exist.isEnabled, elements: newElements))
res.append(DocElementsViewModel(docId: exist.docId, docType: exist.docType, displayName: exist.displayName, isEnabled: exist.isEnabled, elements: newElements))
}
else { res.append(otherDE) }
}
Expand Down

0 comments on commit c5fe752

Please sign in to comment.