Skip to content

Commit

Permalink
Merge branch '4.3.1_release' into 'main'
Browse files Browse the repository at this point in the history
Bump version to 4.3.1

See merge request product/dvc/sdk/public/socure-sigmadevice-wrapper-react-native!25
  • Loading branch information
pavan-mellamputi-socure committed Aug 14, 2024
2 parents 915207d + e974d61 commit 9c36f5e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import com.socure.idplus.device.error.SigmaDeviceError

class SigmaDeviceModule(reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext) {
private var sendDataPromise: Promise? = null

private val handler = Handler(reactContext.mainLooper)

Expand All @@ -32,49 +31,59 @@ class SigmaDeviceModule(reactContext: ReactApplicationContext) :
@ReactMethod
fun initializeSDK(sdkKey: String, sigmaDeviceOptions: ReadableMap?, promise: Promise) {
val activity = currentActivity
sendDataPromise = promise
if (activity == null) {
sendDataPromise?.reject(Throwable(message = "Aborting since app activity object is null"))
promise.reject(Throwable(message = "Aborting since app activity object is null"))
return
}

var isFirstTime = true
handler.post {
SigmaDevice.initializeSDK(
activity as AppCompatActivity,
sdkKey,
getSigmaDeviceOptions(sigmaDeviceOptions),
object : SigmaDeviceCallback {
override fun onError(errorType: SigmaDeviceError, errorMessage: String?) {
sendDataPromise?.reject(Throwable(message = "${errorType.name}: $errorMessage"))
if (!isFirstTime) {
return
}

isFirstTime = false
promise.reject(Throwable(message = "${errorType.name}: $errorMessage"))
}

override fun onSessionCreated(sessionToken: String) {
sendSessionToken(sessionToken)
if (!isFirstTime) {
return
}

isFirstTime = false
sendSessionToken(sessionToken, promise)
}
})
}
}

@ReactMethod
fun getSessionToken(promise: Promise) {
sendDataPromise = promise
handler.post {
SigmaDevice.getSessionToken(object : SessionTokenCallback {
override fun onComplete(sessionToken: String) {
sendSessionToken(sessionToken)
sendSessionToken(sessionToken, promise)
}

override fun onError(errorType: SigmaDeviceError, errorMessage: String?) {
sendDataPromise?.reject(Throwable(message = "${errorType.name}: $errorMessage"))
promise.reject(Throwable(message = "${errorType.name}: $errorMessage"))
}

})
}
}

private fun sendSessionToken(sessionToken: String) {
private fun sendSessionToken(sessionToken: String, promise: Promise) {
val response = Arguments.createMap()
response.putString("sessionToken", sessionToken)
sendDataPromise?.resolve(response)
promise.resolve(response)
}

private fun getSigmaDeviceOptions(sigmaDeviceOptions: ReadableMap?): SigmaDeviceOptions {
Expand All @@ -97,15 +106,14 @@ class SigmaDeviceModule(reactContext: ReactApplicationContext) :
fun processDevice(sigmaDeviceContext: String, promise: Promise) {
val context = getContextFromString(sigmaDeviceContext)

sendDataPromise = promise
handler.post {
SigmaDevice.processDevice(context, object : SessionTokenCallback {
override fun onComplete(sessionToken: String) {
sendSessionToken(sessionToken)
sendSessionToken(sessionToken, promise)
}

override fun onError(errorType: SigmaDeviceError, errorMessage: String?) {
sendDataPromise?.reject(Throwable(message = "${errorType.name}: $errorMessage"))
promise.reject(Throwable(message = "${errorType.name}: $errorMessage"))
}

})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@socure-inc/react-native-device-risk",
"version": "4.3.0",
"version": "4.3.1",
"description": "React bridge to enable iOS and Android Device Risk SDKs to be used by React Native apps",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down

0 comments on commit 9c36f5e

Please sign in to comment.