Skip to content

Commit

Permalink
feat: android nitts
Browse files Browse the repository at this point in the history
  • Loading branch information
JNdhlovu committed Oct 10, 2023
1 parent 30b9178 commit 653db4f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
22 changes: 21 additions & 1 deletion android/src/main/java/com/smileidentity/react/ReactUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package com.smileidentity.react
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.ReadableType
import com.smileidentity.models.IdInfo
import com.smileidentity.models.JobType
import com.smileidentity.models.PartnerParams
import com.smileidentity.util.randomUserId

fun ReadableMap.toMap(): Map<String, String> {
val map = mutableMapOf<String, String>()
Expand Down Expand Up @@ -46,7 +49,7 @@ fun ReadableMap.idInfo(): IdInfo? {
if (!hasKey("country")) {
return null
}
val country = getString("country") ?: IllegalArgumentException("country is required")
val country = getString("country") ?: throw IllegalArgumentException("country is required")
return IdInfo(
country = country,
idType = if (hasKey("idType")) getString("idType") else null,
Expand All @@ -59,3 +62,20 @@ fun ReadableMap.idInfo(): IdInfo? {
entered = if (hasKey("entered")) getBoolean("entered") else false,
)
}


fun ReadableMap.partnerParams(): PartnerParams {
if (hasKey("partnerParams")) {
val partnerParams = getMap("partnerParams")
return PartnerParams(
jobType = if (hasKey("jobType")) JobType.fromValue(getInt("jobType")) else null,
userId = if (hasKey("userId")) getString("userId")!! else randomUserId(),
jobId = if (hasKey("jobId")) getString("jobId")!! else randomUserId(),
extras = if (hasKey("extras")) partnerParams?.getMap("extras")!!.toMap() else emptyMap()
)
}
return PartnerParams(
userId = randomUserId(),
jobId = randomUserId(),
)
}
14 changes: 3 additions & 11 deletions android/src/main/java/com/smileidentity/react/SmileIdModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import com.facebook.react.bridge.ReadableMap
import com.smileidentity.SmileID
import com.smileidentity.SmileIdSpec
import com.smileidentity.models.EnhancedKycRequest
import com.smileidentity.models.JobType
import com.smileidentity.models.PartnerParams
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -31,7 +29,6 @@ class SmileIdModule internal constructor(context: ReactApplicationContext) :
@ReactMethod
override fun doEnhancedKycAsync(request: ReadableMap, promise: Promise) = launch(
work = {
val partnerParams = request.getMap("partnerParams")!!
SmileID.api.doEnhancedKycAsync(
EnhancedKycRequest(
country = request.getString("country")!!,
Expand All @@ -44,15 +41,10 @@ class SmileIdModule internal constructor(context: ReactApplicationContext) :
phoneNumber = request.getString("phoneNumber"),
bankCode = request.getString("bankCode"),
callbackUrl = request.getString("callbackUrl"),
partnerParams = PartnerParams(
jobType = JobType.fromValue(partnerParams.getInt("jobType")),
jobId = partnerParams.getString("jobId")!!,
userId = partnerParams.getString("userId")!!,
extras = partnerParams.getMap("extras")?.toMap() ?: emptyMap()
),
partnerParams = request.partnerParams(),
sourceSdk = "android (react-native)",
timestamp = partnerParams.getString("timestamp")!!,
signature = partnerParams.getString("signature")!!,
timestamp = request.partnerParams().extras["timestamp"]!!,
signature = request.partnerParams().extras["signature"]!!,
)
)
},
Expand Down

0 comments on commit 653db4f

Please sign in to comment.