Skip to content

Commit

Permalink
feat: consistent file paths (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
JNdhlovu authored Oct 25, 2024
1 parent 4275c5f commit a77c6ef
Show file tree
Hide file tree
Showing 21 changed files with 494 additions and 364 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Release Notes

## (Unreleased)
* Consistent file paths for all products and capture screens

## 10.1.12
* Added selfie capture screens
* Added document capture screens
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.smileidentity.react.results

import java.io.File

data class DocumentCaptureResult(
val selfieFile: File? = null,
val documentFrontFile: File? = null,
val livenessFiles: List<File>? = null,
val documentBackFile: File? = null,
val didSubmitDocumentVerificationJob: Boolean? = null,
val didSubmitEnhancedDocVJob: Boolean? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.smileidentity.react.results

import com.smileidentity.models.v2.SmartSelfieResponse
import java.io.File

data class SmartSelfieCaptureResult(
val selfieFile: File? = null,
val livenessFiles: List<File>? = null,
val apiResponse: SmartSelfieResponse? = null,
val didSubmitBiometricKycJob: Boolean? = null
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.smileidentity.react.utils

import com.smileidentity.react.views.DocumentCaptureResult
import com.smileidentity.react.results.DocumentCaptureResult
import com.squareup.moshi.FromJson
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
Expand All @@ -15,17 +15,44 @@ class DocumentCaptureResultAdapter : JsonAdapter<DocumentCaptureResult>() {
@FromJson
override fun fromJson(reader: JsonReader): DocumentCaptureResult {
reader.beginObject()
var selfieFile: File? = null
var frontFile: File? = null
var backFile: File? = null
var livenessFiles: MutableList<File>? = null
var didSubmitDocumentVerificationJob: Boolean? = null
var didSubmitEnhancedDocVJob: Boolean? = null

while (reader.hasNext()) {
when (reader.nextName()) {
"selfieFile" -> selfieFile = reader.nextString()?.let { File(it) }
"documentFrontFile" -> frontFile = reader.nextString()?.let { File(it) }
"documentBackFile" -> backFile = reader.nextString()?.let { File(it) }
"livenessFiles" -> {
livenessFiles = mutableListOf()
reader.beginArray()
while (reader.hasNext()) {
reader.nextString()?.let { livenessFiles.add(File(it)) }
}
reader.endArray()
}

"didSubmitDocumentVerificationJob" -> didSubmitDocumentVerificationJob =
reader.nextBoolean()

"didSubmitEnhancedDocVJob" -> didSubmitEnhancedDocVJob = reader.nextBoolean()
else -> reader.skipValue()
}
}
reader.endObject()
return DocumentCaptureResult(frontFile, backFile)

return DocumentCaptureResult(
selfieFile = selfieFile,
documentFrontFile = frontFile,
documentBackFile = backFile,
livenessFiles = livenessFiles,
didSubmitDocumentVerificationJob = didSubmitDocumentVerificationJob,
didSubmitEnhancedDocVJob = didSubmitEnhancedDocVJob
)
}

@ToJson
Expand All @@ -34,9 +61,26 @@ class DocumentCaptureResultAdapter : JsonAdapter<DocumentCaptureResult>() {
writer.nullValue()
return
}

writer.beginObject()
writer.name("selfieFile").value(value.selfieFile?.absolutePath)
writer.name("documentFrontFile").value(value.documentFrontFile?.absolutePath)
writer.name("documentBackFile").value(value.documentBackFile?.absolutePath)

writer.name("livenessFiles")
if (value.livenessFiles == null) {
writer.nullValue()
} else {
writer.beginArray()
for (file in value.livenessFiles) {
writer.value(file.absolutePath)
}
writer.endArray()
}

writer.name("didSubmitDocumentVerificationJob").value(value.didSubmitDocumentVerificationJob)
writer.name("didSubmitEnhancedDocVJob").value(value.didSubmitEnhancedDocVJob)

writer.endObject()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.smileidentity.react.utils

import com.smileidentity.react.views.SmartSelfieCaptureResult
import com.smileidentity.SmileID
import com.smileidentity.models.v2.SmartSelfieResponse
import com.smileidentity.react.results.SmartSelfieCaptureResult
import com.squareup.moshi.FromJson
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonAdapter.Factory
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import com.squareup.moshi.ToJson
import java.io.File
import java.lang.reflect.Type

class SelfieCaptureResultAdapter : JsonAdapter<SmartSelfieCaptureResult>() {

Expand All @@ -17,23 +18,35 @@ class SelfieCaptureResultAdapter : JsonAdapter<SmartSelfieCaptureResult>() {
reader.beginObject()
var selfieFile: File? = null
var livenessFiles: List<File>? = null
var apiResponse: SmartSelfieResponse? = null

while (reader.hasNext()) {
when (reader.nextName()) {
"selfieFile" -> selfieFile = reader.nextString()?.let { File(it) }
"livenessFiles" -> {
reader.beginArray()
// Assuming livenessFiles is an array of file paths in the JSON
val files = mutableListOf<File>()
reader.beginArray()
while (reader.hasNext()) {
reader.nextString()?.let { files.add(File(it)) }
}
reader.endArray()
livenessFiles = files
}

"apiResponse" -> apiResponse =
SmileID.moshi.adapter(SmartSelfieResponse::class.java).fromJson(reader)

else -> reader.skipValue()
}
}

reader.endObject()
return SmartSelfieCaptureResult(selfieFile, livenessFiles)
return SmartSelfieCaptureResult(
selfieFile = selfieFile,
livenessFiles = livenessFiles,
apiResponse = apiResponse
)
}

@ToJson
Expand All @@ -44,24 +57,22 @@ class SelfieCaptureResultAdapter : JsonAdapter<SmartSelfieCaptureResult>() {
}
writer.beginObject()
writer.name("selfieFile").value(value.selfieFile?.absolutePath)

writer.name("livenessFiles")
writer.beginArray()
value.livenessFiles?.forEach { file ->
writer.value(file.absolutePath)
}
value.livenessFiles?.forEach { writer.value(it.absolutePath) }
writer.endArray()

writer.name("apiResponse")
if (value.apiResponse != null) {
SmileID.moshi.adapter(SmartSelfieResponse::class.java).toJson(writer, value.apiResponse)
} else {
writer.nullValue()
}
writer.endObject()
}

companion object {
val FACTORY = object : Factory {
override fun create(
type: Type,
annotations: Set<Annotation>,
moshi: Moshi
): JsonAdapter<*>? {
return if (type == SmartSelfieCaptureResult::class.java) SelfieCaptureResultAdapter() else null
}
}
val FACTORY = Factory { type, annotations, moshi -> if (type == SmartSelfieCaptureResult::class.java) SelfieCaptureResultAdapter() else null }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import com.facebook.react.bridge.ReactApplicationContext
import com.smileidentity.SmileID
import com.smileidentity.compose.BiometricKYC
import com.smileidentity.models.IdInfo
import com.smileidentity.results.BiometricKycResult
import com.smileidentity.react.results.SmartSelfieCaptureResult
import com.smileidentity.react.utils.SelfieCaptureResultAdapter
import com.smileidentity.results.SmileIDResult
import com.smileidentity.util.randomJobId
import com.smileidentity.util.randomUserId
import kotlinx.collections.immutable.toImmutableMap
import timber.log.Timber

class SmileIDBiometricKYCView(context: ReactApplicationContext) : SmileIDView(context) {
var idInfo: IdInfo? = null
Expand All @@ -35,24 +35,35 @@ class SmileIDBiometricKYCView(context: ReactApplicationContext) : SmileIDView(co
showAttribution = showAttribution ?: true,
showInstructions = showInstructions ?: true,
extraPartnerParams = (extraPartnerParams ?: mapOf()).toImmutableMap(),
) { result ->
when (result) {
) { res ->
when (res) {
is SmileIDResult.Success -> {
val json = try {
val result =
SmartSelfieCaptureResult(
selfieFile = res.data.selfieFile,
livenessFiles = res.data.livenessFiles,
didSubmitBiometricKycJob = res.data.didSubmitBiometricKycJob,
)
val newMoshi =
SmileID.moshi
.adapter(BiometricKycResult::class.java)
.toJson(result.data)
} catch (e: Exception) {
Timber.w(e)
"null"
.newBuilder()
.add(SelfieCaptureResultAdapter.FACTORY)
.build()
val json =
try {
newMoshi
.adapter(SmartSelfieCaptureResult::class.java)
.toJson(result)
} catch (e: Exception) {
emitFailure(e)
return@BiometricKYC
}
json?.let { js ->
emitSuccess(js)
}
emitSuccess(json)
}

is SmileIDResult.Error -> {
result.throwable.printStackTrace()
emitFailure(result.throwable)
}
is SmileIDResult.Error -> emitFailure(res.throwable)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,15 @@ import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
import com.facebook.react.bridge.ReactApplicationContext
import com.smileidentity.R
import com.smileidentity.SmileID
import com.smileidentity.SmileIDOptIn
import com.smileidentity.compose.document.DocumentCaptureScreen
import com.smileidentity.compose.document.DocumentCaptureSide
import com.smileidentity.compose.theme.colorScheme
import com.smileidentity.react.results.DocumentCaptureResult
import com.smileidentity.react.utils.DocumentCaptureResultAdapter
import com.smileidentity.util.randomJobId
import com.squareup.moshi.JsonClass
import timber.log.Timber
import java.io.File

data class DocumentCaptureResult(
val documentFrontFile: File? = null,
val documentBackFile: File? = null
)

@OptIn(SmileIDOptIn::class)
class SmileIDDocumentCaptureView(context: ReactApplicationContext) : SmileIDView(context) {
var showConfirmation: Boolean = true
var front: Boolean = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
import com.facebook.react.bridge.ReactApplicationContext
import com.smileidentity.SmileID
import com.smileidentity.compose.DocumentVerification
import com.smileidentity.results.DocumentVerificationResult
import com.smileidentity.react.results.DocumentCaptureResult
import com.smileidentity.react.utils.DocumentCaptureResultAdapter
import com.smileidentity.results.SmileIDResult
import com.smileidentity.util.randomJobId
import com.smileidentity.util.randomUserId
import kotlinx.collections.immutable.toImmutableMap
import timber.log.Timber
import java.io.File

class SmileIDDocumentVerificationView(context: ReactApplicationContext) : SmileIDView(context) {
Expand Down Expand Up @@ -49,24 +49,37 @@ class SmileIDDocumentVerificationView(context: ReactApplicationContext) : SmileI
allowNewEnroll = allowNewEnroll ?: false,
bypassSelfieCaptureWithFile = bypassSelfieCaptureWithFile,
extraPartnerParams = (extraPartnerParams ?: mapOf()).toImmutableMap(),
) { result ->
when (result) {
) { res ->
when (res) {
is SmileIDResult.Success -> {
val json = try {
val result =
DocumentCaptureResult(
selfieFile = res.data.selfieFile,
documentFrontFile = res.data.documentFrontFile,
livenessFiles = res.data.livenessFiles,
documentBackFile = res.data.documentBackFile,
didSubmitDocumentVerificationJob = res.data.didSubmitDocumentVerificationJob,
)
val newMoshi =
SmileID.moshi
.adapter(DocumentVerificationResult::class.java)
.toJson(result.data)
} catch (e: Exception) {
Timber.w(e)
"null"
.newBuilder()
.add(DocumentCaptureResultAdapter.FACTORY)
.build()
val json =
try {
newMoshi
.adapter(DocumentCaptureResult::class.java)
.toJson(result)
} catch (e: Exception) {
emitFailure(e)
return@DocumentVerification
}
json?.let { js ->
emitSuccess(js)
}
emitSuccess(json)
}

is SmileIDResult.Error -> {
result.throwable.printStackTrace()
emitFailure(result.throwable)
}
is SmileIDResult.Error -> emitFailure(res.throwable)
}
}
}
Expand Down
Loading

0 comments on commit a77c6ef

Please sign in to comment.