Skip to content

Commit

Permalink
Updated JobStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
vanshg committed Oct 13, 2023
1 parent 5f58aea commit f886070
Show file tree
Hide file tree
Showing 18 changed files with 417 additions and 230 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

### Added
- Enhanced Document Verification
- New JobStatusResponses that depend on the job type

### Changed
- Renamed `DocumentCaptureResultDelegate` -> `DocumentVerificationResultDelegate`
- Delegate types updated to accept generic `JobStatusResponse` objects

### Fixed
- Document Verification UI bugs
Expand Down
6 changes: 5 additions & 1 deletion Example/SmileID/EnterUserIDView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ struct EnterUserIDView_Previews: PreviewProvider {
class UserIDViewModel: ObservableObject, SmartSelfieResultDelegate {
@Published var shouldDismiss = false

func didSucceed(selfieImage: URL, livenessImages: [URL], jobStatusResponse: JobStatusResponse) {
func didSucceed(
selfieImage: URL,
livenessImages: [URL],
jobStatusResponse: JobStatusResponse<SmartSelfieJobResult>
) {
shouldDismiss = true
NotificationCenter.default.post(Notification(
name: Notification.Name(rawValue: "SelfieCaptureComplete"),
Expand Down
6 changes: 3 additions & 3 deletions Example/SmileID/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class HomeViewController: UIViewController, SmartSelfieResultDelegate {
}

func didSucceed(
selfieImage _: URL,
livenessImages _: [URL],
jobStatusResponse _: JobStatusResponse
selfieImage: URL,
livenessImages: [URL],
jobStatusResponse: JobStatusResponse<SmartSelfieJobResult>
) {
cameraVC?.dismiss(animated: true, completion: {
switch self.currentJob {
Expand Down
27 changes: 23 additions & 4 deletions Example/SmileID/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import Combine
import UIKit
import SmileID

class HomeViewModel: ObservableObject, SmartSelfieResultDelegate, DocumentVerificationResultDelegate {
class HomeViewModel:
ObservableObject,
SmartSelfieResultDelegate,
DocumentVerificationResultDelegate,
EnhancedDocumentVerificationResultDelegate {
@Published var product: JobType? {
didSet {
switch product {
Expand Down Expand Up @@ -65,8 +69,12 @@ class HomeViewModel: ObservableObject, SmartSelfieResultDelegate, DocumentVerifi
product = .enhancedDocumentVerification
}

func didSucceed(selfieImage: URL, livenessImages: [URL], jobStatusResponse: JobStatusResponse) {
returnedUserID = jobStatusResponse.result?.partnerParams?.userId ?? ""
func didSucceed(
selfieImage: URL,
livenessImages: [URL],
jobStatusResponse: JobStatusResponse<SmartSelfieJobResult>
) {
returnedUserID = jobStatusResponse.result?.partnerParams.userId ?? ""
UIPasteboard.general.string = returnedUserID
showToast = true
if jobStatusResponse.jobSuccess {
Expand Down Expand Up @@ -103,13 +111,24 @@ class HomeViewModel: ObservableObject, SmartSelfieResultDelegate, DocumentVerifi
selfie: URL,
documentFrontImage: URL,
documentBackImage: URL?,
jobStatusResponse: JobStatusResponse
jobStatusResponse: JobStatusResponse<DocumentVerificationJobResult>
) {
showToast = true
toastMessage = "Document Verification submitted successfully, results processing"
print("Document Verification jobStatusResponse: \(jobStatusResponse)")
}

func didSucceed(
selfie: URL,
documentFrontImage: URL,
documentBackImage: URL?,
jobStatusResponse: JobStatusResponse<EnhancedDocumentVerificationJobResult>
) {
showToast = true
toastMessage = "Enhanced Document Verification submitted successfully, results processing"
print("Document Verification jobStatusResponse: \(jobStatusResponse)")
}

@objc func handleAuthCompletion(_ notification: NSNotification) {
if let dict = notification.userInfo as? NSDictionary {
showToast = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public protocol DocumentVerificationResultDelegate: AnyObject {
selfie: URL,
documentFrontImage: URL,
documentBackImage: URL?,
jobStatusResponse: JobStatusResponse
jobStatusResponse: DocumentVerificationJobStatusResponse
)

/// Delegate method called when an error occurs during Document Verification. This may
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public protocol EnhancedDocumentVerificationResultDelegate: AnyObject {
selfie: URL,
documentFrontImage: URL,
documentBackImage: URL?,
jobStatusResponse: JobStatusResponse
jobStatusResponse: EnhancedDocumentVerificationJobStatusResponse
)

/// Delegate method called when an error occurs during Document Verification. This may
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum DocumentCaptureFlow: Equatable {
case processing(DocumentProcessingState)
}

internal class OrchestratedDocumentVerificationViewModel<T>:
internal class OrchestratedDocumentVerificationViewModel<T, U: JobResult>:
ObservableObject,
SelfieImageCaptureDelegate {
// Input properties
Expand All @@ -30,7 +30,7 @@ internal class OrchestratedDocumentVerificationViewModel<T>:
internal var documentFrontFile: Data?
internal var documentBackFile: Data?
internal var livenessFiles: [Data]?
internal var jobStatusResponse: JobStatusResponse?
internal var jobStatusResponse: JobStatusResponse<U>?
internal var savedFiles: DocumentCaptureResultStore?
internal var networkingSubscriber: AnyCancellable?
internal var stepToRetry: DocumentCaptureFlow?
Expand Down Expand Up @@ -156,7 +156,7 @@ internal class OrchestratedDocumentVerificationViewModel<T>:
SmileID.api.upload(zip: zip, to: prepUploadResponse.uploadUrl)
}
.zip(auth)
.flatMap { uploadResponse, authResponse in
.flatMap { uploadResponse, authResponse -> AnyPublisher<JobStatusResponse<U>, Error> in
let jobStatusRequest = JobStatusRequest(
userId: authResponse.partnerParams.userId,
jobId: authResponse.partnerParams.jobId,
Expand Down Expand Up @@ -204,7 +204,7 @@ internal class OrchestratedDocumentVerificationViewModel<T>:
}

internal class OrchestratedDocumentVerificationViewModelImpl:
OrchestratedDocumentVerificationViewModel<DocumentVerificationResultDelegate> {
OrchestratedDocumentVerificationViewModel<DocumentVerificationResultDelegate, DocumentVerificationJobResult> {
override func onFinished(delegate: DocumentVerificationResultDelegate) {
if let jobStatusResponse = jobStatusResponse, let savedFiles = savedFiles {
delegate.didSucceed(
Expand All @@ -224,7 +224,7 @@ internal class OrchestratedDocumentVerificationViewModelImpl:
}

internal class OrchestratedEnhancedDocumentVerificationViewModel:
OrchestratedDocumentVerificationViewModel<EnhancedDocumentVerificationResultDelegate> {
OrchestratedDocumentVerificationViewModel<EnhancedDocumentVerificationResultDelegate, EnhancedDocumentVerificationJobResult> {
override func onFinished(delegate: EnhancedDocumentVerificationResultDelegate) {
if let jobStatusResponse = jobStatusResponse, let savedFiles = savedFiles {
delegate.didSucceed(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SwiftUI

struct OrchestratedDocumentVerificationScreen<T>: View {
struct OrchestratedDocumentVerificationScreenImpl: View {
let countryCode: String
let documentType: String?
let captureBothSides: Bool
Expand All @@ -11,9 +11,86 @@ struct OrchestratedDocumentVerificationScreen<T>: View {
let showAttribution: Bool
let allowGalleryUpload: Bool
let showInstructions: Bool
let onResult: T
let onResult: DocumentVerificationResultDelegate

var body: some View {
OrchestratedDocumentVerificationScreen(
countryCode: countryCode,
documentType: documentType,
captureBothSides: captureBothSides,
idAspectRatio: idAspectRatio,
bypassSelfieCaptureWithFile: bypassSelfieCaptureWithFile,
userId: userId,
jobId: jobId,
showAttribution: showAttribution,
allowGalleryUpload: allowGalleryUpload,
showInstructions: showInstructions,
onResult: onResult,
viewModel: OrchestratedDocumentVerificationViewModelImpl(
userId: userId,
jobId: jobId,
countryCode: countryCode,
documentType: documentType,
captureBothSides: captureBothSides,
selfieFile: bypassSelfieCaptureWithFile,
jobType: .documentVerification
)
)
}
}

struct OrchestratedEnhancedDocumentVerificationScreen: View {
let countryCode: String
let documentType: String?
let captureBothSides: Bool
let idAspectRatio: Double?
let bypassSelfieCaptureWithFile: URL?
let userId: String
let jobId: String
let showAttribution: Bool
let allowGalleryUpload: Bool
let showInstructions: Bool
let onResult: EnhancedDocumentVerificationResultDelegate

var body: some View {
OrchestratedDocumentVerificationScreen(
countryCode: countryCode,
documentType: documentType,
captureBothSides: captureBothSides,
idAspectRatio: idAspectRatio,
bypassSelfieCaptureWithFile: bypassSelfieCaptureWithFile,
userId: userId,
jobId: jobId,
showAttribution: showAttribution,
allowGalleryUpload: allowGalleryUpload,
showInstructions: showInstructions,
onResult: onResult,
viewModel: OrchestratedEnhancedDocumentVerificationViewModel(
userId: userId,
jobId: jobId,
countryCode: countryCode,
documentType: documentType,
captureBothSides: captureBothSides,
selfieFile: bypassSelfieCaptureWithFile,
jobType: .enhancedDocumentVerification
)
)
}
}

@ObservedObject private var viewModel: OrchestratedDocumentVerificationViewModel<T>
private struct OrchestratedDocumentVerificationScreen<T, U: JobResult>: View {
let countryCode: String
let documentType: String?
let captureBothSides: Bool
let idAspectRatio: Double?
let bypassSelfieCaptureWithFile: URL?
let userId: String
let jobId: String
let showAttribution: Bool
let allowGalleryUpload: Bool
let showInstructions: Bool
let onResult: T
@ObservedObject var viewModel: OrchestratedDocumentVerificationViewModel<T, U>

init(
countryCode: String,
Expand All @@ -26,8 +103,8 @@ struct OrchestratedDocumentVerificationScreen<T>: View {
showAttribution: Bool,
allowGalleryUpload: Bool,
showInstructions: Bool,
jobType: JobType,
onResult: T
onResult: T,
viewModel: OrchestratedDocumentVerificationViewModel<T, U>
) {
self.countryCode = countryCode
self.documentType = documentType
Expand All @@ -40,29 +117,7 @@ struct OrchestratedDocumentVerificationScreen<T>: View {
self.allowGalleryUpload = allowGalleryUpload
self.showInstructions = showInstructions
self.onResult = onResult
// swiftlint:disable force_cast
if jobType == .enhancedDocumentVerification {
viewModel = OrchestratedEnhancedDocumentVerificationViewModel(
userId: userId,
jobId: jobId,
countryCode: countryCode,
documentType: documentType,
captureBothSides: captureBothSides,
selfieFile: bypassSelfieCaptureWithFile,
jobType: jobType
) as! OrchestratedDocumentVerificationViewModel<T>
} else {
viewModel = OrchestratedDocumentVerificationViewModelImpl(
userId: userId,
jobId: jobId,
countryCode: countryCode,
documentType: documentType,
captureBothSides: captureBothSides,
selfieFile: bypassSelfieCaptureWithFile,
jobType: jobType
) as! OrchestratedDocumentVerificationViewModel<T>
}
// swiftlint:enable force_cast
self.viewModel = viewModel
}

var body: some View {
Expand Down
Loading

0 comments on commit f886070

Please sign in to comment.