Skip to content

Commit

Permalink
Merge branch 'main' into update-changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
jumaallan authored Aug 19, 2024
2 parents 6c9320d + 473f067 commit 3525ca3
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ internal class OrchestratedBiometricKycViewModel: ObservableObject {

// MARK: - Other Properties

internal var selfieFile: URL?
internal var livenessFiles: [URL]?
private var error: Error?
private var selfieCaptureResultStore: SelfieCaptureResultStore?
private var didSubmitBiometricJob: Bool = false

// MARK: - UI Properties
Expand All @@ -45,18 +46,21 @@ internal class OrchestratedBiometricKycViewModel: ObservableObject {
}

func onRetry() {
if selfieCaptureResultStore == nil {
DispatchQueue.main.async { self.step = .selfie }
if let selfieFile {
submitJob()
} else {
submitJob(selfieCaptureResultStore: selfieCaptureResultStore!)
DispatchQueue.main.async { self.step = .selfie }
}
}

func onFinished(delegate: BiometricKycResultDelegate) {
if let selfieCaptureResultStore {
if let selfieFile = selfieFile,
let livenessFiles = livenessFiles,
let selfiePath = getRelativePath(from: selfieFile)
{
delegate.didSucceed(
selfieImage: selfieCaptureResultStore.selfie,
livenessImages: selfieCaptureResultStore.livenessImages,
selfieImage: selfiePath,
livenessImages: livenessFiles.compactMap { getRelativePath(from: $0) },
didSubmitBiometricJob: didSubmitBiometricJob
)
} else if let error {
Expand All @@ -66,21 +70,39 @@ internal class OrchestratedBiometricKycViewModel: ObservableObject {
}
}

func submitJob(selfieCaptureResultStore: SelfieCaptureResultStore) {
func submitJob() {
DispatchQueue.main.async { self.step = .processing(.inProgress) }
Task {
do {
let livenessImages = selfieCaptureResultStore.livenessImages
let selfieImage = selfieCaptureResultStore.selfie
selfieFile = try LocalStorage.getFileByType(
jobId: jobId,
fileType: FileType.selfie
)

livenessFiles = try LocalStorage.getFilesByType(
jobId: jobId,
fileType: FileType.liveness
)

guard let selfieFile else {
// Set step to .selfieCapture so that the Retry button goes back to this step
DispatchQueue.main.async { self.step = .selfie }
error = SmileIDError.unknown("Error capturing selfie")
return
}

var allFiles = [URL]()
let infoJson = try LocalStorage.createInfoJsonFile(
jobId: jobId,
idInfo: idInfo.copy(entered: true),
selfie: selfieImage,
livenessImages: livenessImages
)
let zipData = try LocalStorage.zipFiles(
at: livenessImages + [selfieImage] + [infoJson]
selfie: selfieFile,
livenessImages: livenessFiles
)
allFiles.append(contentsOf: [selfieFile, infoJson])
if let livenessFiles {
allFiles.append(contentsOf: livenessFiles)
}
let zipData = try LocalStorage.zipFiles(at: allFiles)
let authRequest = AuthenticationRequest(
jobType: .biometricKyc,
enrollment: false,
Expand Down Expand Up @@ -128,18 +150,6 @@ internal class OrchestratedBiometricKycViewModel: ObservableObject {
didSubmitBiometricJob = true
do {
try LocalStorage.moveToSubmittedJobs(jobId: self.jobId)
self.selfieCaptureResultStore = SelfieCaptureResultStore(
selfie: try LocalStorage.getFileByType(
jobId: jobId,
fileType: FileType.selfie,
submitted: true
) ?? selfieCaptureResultStore.selfie,
livenessImages: try LocalStorage.getFilesByType(
jobId: jobId,
fileType: FileType.liveness,
submitted: true
) ?? selfieCaptureResultStore.livenessImages
)
} catch {
print("Error moving job to submitted directory: \(error)")
self.error = error
Expand All @@ -149,24 +159,10 @@ internal class OrchestratedBiometricKycViewModel: ObservableObject {
DispatchQueue.main.async { self.step = .processing(.success) }
} catch let error as SmileIDError {
do {
let didMove = try LocalStorage.handleOfflineJobFailure(
_ = try LocalStorage.handleOfflineJobFailure(
jobId: self.jobId,
error: error
)
if didMove {
self.selfieCaptureResultStore = SelfieCaptureResultStore(
selfie: try LocalStorage.getFileByType(
jobId: jobId,
fileType: FileType.selfie,
submitted: true
) ?? selfieCaptureResultStore.selfie,
livenessImages: try LocalStorage.getFilesByType(
jobId: jobId,
fileType: FileType.liveness,
submitted: true
) ?? selfieCaptureResultStore.livenessImages
)
}
} catch {
print("Error moving job to submitted directory: \(error)")
self.error = error
Expand Down Expand Up @@ -199,24 +195,15 @@ internal class OrchestratedBiometricKycViewModel: ObservableObject {

extension OrchestratedBiometricKycViewModel: SmartSelfieResultDelegate {
func didSucceed(
selfieImage: URL,
livenessImages: [URL],
selfieImage _: URL,
livenessImages _: [URL],
apiResponse _: SmartSelfieResponse?
) {
selfieCaptureResultStore = SelfieCaptureResultStore(
selfie: selfieImage,
livenessImages: livenessImages
)
if let selfieCaptureResultStore {
submitJob(selfieCaptureResultStore: selfieCaptureResultStore)
} else {
error = SmileIDError.unknown("Failed to save selfie capture result")
DispatchQueue.main.async { self.step = .processing(.error) }
}
submitJob()
}

func didError(error _: Error) {
error = SmileIDError.unknown("Failed to capture selfie")
error = SmileIDError.unknown("Error capturing selfie")
DispatchQueue.main.async { self.step = .processing(.error) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public struct ConsentScreen: View {
Image(uiImage: SmileIDResourcesHelper.SmileEmblem)
}
}
}
}.preferredColorScheme(.light)
}
}

Expand Down Expand Up @@ -208,6 +208,6 @@ public struct ConsentDeniedScreen: View {
if showAttribution {
Image(uiImage: SmileIDResourcesHelper.SmileEmblem)
}
}
}.preferredColorScheme(.light)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,36 @@ internal class IOrchestratedDocumentVerificationViewModel<T, U: JobResult>: Obse
}

func submitJob() {
guard let documentFrontFile else {
// Set step to .frontDocumentCapture so that the Retry button goes back to this step
step = .frontDocumentCapture
onError(error: SmileIDError.unknown("Error getting document front file"))
return
}
guard let selfieFile else {
// Set step to .selfieCapture so that the Retry button goes back to this step
step = .selfieCapture
onError(error: SmileIDError.unknown("Error getting selfie file"))
return
}
DispatchQueue.main.async {
self.step = .processing(.inProgress)
}
Task {
let zip: Data
do {
guard let documentFrontFile else {
// Set step to .frontDocumentCapture so that the Retry button goes back to this step
step = .frontDocumentCapture
onError(error: SmileIDError.unknown("Error getting document front file"))
return
}

selfieFile = try LocalStorage.getFileByType(
jobId: jobId,
fileType: FileType.selfie
)

livenessFiles = try LocalStorage.getFilesByType(
jobId: jobId,
fileType: FileType.liveness
)

guard let selfieFile else {
// Set step to .selfieCapture so that the Retry button goes back to this step
step = .selfieCapture
onError(error: SmileIDError.unknown("Error getting selfie file"))
return
}

DispatchQueue.main.async {
self.step = .processing(.inProgress)
}

var allFiles = [URL]()
let frontDocumentUrl = try LocalStorage.createDocumentFile(
jobId: jobId,
Expand Down Expand Up @@ -286,9 +298,11 @@ internal class IOrchestratedDocumentVerificationViewModel<T, U: JobResult>: Obse
}

extension IOrchestratedDocumentVerificationViewModel: SmartSelfieResultDelegate {
func didSucceed(selfieImage: URL, livenessImages: [URL], apiResponse _: SmartSelfieResponse?) {
selfieFile = selfieImage
livenessFiles = livenessImages
func didSucceed(
selfieImage _: URL,
livenessImages _: [URL],
apiResponse _: SmartSelfieResponse?
) {
submitJob()
}

Expand All @@ -302,11 +316,15 @@ internal class OrchestratedDocumentVerificationViewModel:
IOrchestratedDocumentVerificationViewModel<DocumentVerificationResultDelegate, DocumentVerificationJobResult>
{
override func onFinished(delegate: DocumentVerificationResultDelegate) {
if let savedFiles {
if let savedFiles,
let selfiePath = getRelativePath(from: selfieFile),
let documentFrontPath = getRelativePath(from: savedFiles.documentFront),
let documentBackPath = getRelativePath(from: savedFiles.documentBack)
{
delegate.didSucceed(
selfie: savedFiles.selfie,
documentFrontImage: savedFiles.documentFront,
documentBackImage: savedFiles.documentBack,
selfie: selfiePath,
documentFrontImage: documentFrontPath,
documentBackImage: documentBackPath,
didSubmitDocumentVerificationJob: didSubmitJob
)
} else if let error {
Expand All @@ -325,11 +343,15 @@ internal class OrchestratedEnhancedDocumentVerificationViewModel:
IOrchestratedDocumentVerificationViewModel<EnhancedDocumentVerificationResultDelegate, EnhancedDocumentVerificationJobResult>
{
override func onFinished(delegate: EnhancedDocumentVerificationResultDelegate) {
if let savedFiles {
if let savedFiles,
let selfiePath = getRelativePath(from: selfieFile),
let documentFrontPath = getRelativePath(from: savedFiles.documentFront),
let documentBackPath = getRelativePath(from: savedFiles.documentBack)
{
delegate.didSucceed(
selfie: savedFiles.selfie,
documentFrontImage: savedFiles.documentFront,
documentBackImage: savedFiles.documentBack,
selfie: selfiePath,
documentFrontImage: documentFrontPath,
documentBackImage: documentBackPath,
didSubmitEnhancedDocVJob: didSubmitJob
)
} else if let error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct CaptureButton: View {
label: { Image(uiImage: SmileIDResourcesHelper.Capture) }
)
.frame(width: 70, height: 70, alignment: .center)
.preferredColorScheme(.light)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ public struct DocumentCaptureInstructionsScreen: View {
}
}
.padding(.horizontal, 16)
.preferredColorScheme(.light)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,6 @@ struct CaptureScreenContent: View {
Spacer()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.preferredColorScheme(.light)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ struct DocumentShapedBoundingBox: View {
// issues on iOS 14 devices
.cutout(cutoutShape)
.overlay(cutoutShape.stroke(borderColor, lineWidth: 4))
}
}.preferredColorScheme(.light)
}
}
1 change: 1 addition & 0 deletions Sources/SmileID/Classes/Navigation/NavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct NavigationBar: View {
}
.frame(height: 50)
.frame(maxHeight: .infinity, alignment: .top)
.preferredColorScheme(.light)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ struct FaceShapedProgressIndicator: View {
.animation(.easeInOut, value: progress)
)
.edgesIgnoringSafeArea(.all)
.preferredColorScheme(.light)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct InfiniteProgressBar: View {
overlayRect(in: geo.frame(in: .global))
})
.clipped()
.preferredColorScheme(.light)
}

private func overlayRect(in rect: CGRect) -> some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public struct SelfieCaptureScreen: View {
}
.padding(24)
}
.preferredColorScheme(.light)
.alert(item: $viewModel.unauthorizedAlert) { alert in
Alert(
title: Text(alert.title),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@ public struct SmartSelfieInstructionsScreen: View {
}
}
.padding(.horizontal, 16)
.preferredColorScheme(.light)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public struct SmileButton: View {
.cornerRadius(cornerRadius)
.frame(maxWidth: .infinity)
.disabled(isDisabled)
.preferredColorScheme(.light)
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions Sources/SmileID/Classes/Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,19 @@ func getErrorSubtitle(errorMessageRes: String?, errorMessage: String?) -> String
return SmileIDResourcesHelper.localizedString(for: "Confirmation.FailureReason")
}
}

func getRelativePath(from absoluteURL: URL?) -> URL? {
guard let absoluteURL = absoluteURL else {
return nil
}

let relativeComponents = absoluteURL.pathComponents
.drop(while: { $0 != "SmileID" })
.dropFirst()

if relativeComponents.isEmpty {
return absoluteURL
} else {
return URL(string: relativeComponents.joined(separator: "/"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ public struct ImageCaptureConfirmationDialog: View {
.cornerRadius(24)
.shadow(radius: 16)
.padding(32)
.preferredColorScheme(.light)
}
}
Loading

0 comments on commit 3525ca3

Please sign in to comment.