From 523cbf27d48915f7437d1d6d1dc777e7a3b1f8f8 Mon Sep 17 00:00:00 2001 From: "Sourav Ganguly (isouravganguly)" Date: Mon, 8 Dec 2025 17:44:23 +0530 Subject: [PATCH 1/9] chore: SAM login; update hostApp with userInfo on update --- .../SmallcaseGatewayModule.kt | 42 +++++++++++++++---- .../app/apis/Functions.tsx | 31 ++++++++++++-- .../app/screens/SmtScreen.tsx | 34 ++++++++++++--- src/SmallcaseGateway.js | 16 +++++++ 4 files changed, 106 insertions(+), 17 deletions(-) diff --git a/android/src/main/java/com/reactnativesmallcasegateway/SmallcaseGatewayModule.kt b/android/src/main/java/com/reactnativesmallcasegateway/SmallcaseGatewayModule.kt index da28ad8b..e4b35106 100644 --- a/android/src/main/java/com/reactnativesmallcasegateway/SmallcaseGatewayModule.kt +++ b/android/src/main/java/com/reactnativesmallcasegateway/SmallcaseGatewayModule.kt @@ -161,9 +161,12 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext) : ReactConte fun launchSmallplug(targetEndpoint: String, params: String, promise: Promise) { SmallcaseGatewaySdk.launchSmallPlug(currentActivity!!, SmallplugData(targetEndpoint, params), object : SmallPlugResponseListener { - override fun onFailure(errorCode: Int, errorMessage: String) { - val err = createErrorJSON(errorCode, errorMessage, null) - + override fun onFailure(errorCode: Int, errorMessage: String, userInfo: UserInfo?) { + val dataMap = Arguments.createMap() + userInfoToWritableMap(userInfo)?.let { + dataMap.putMap("userInfo", it) + } + val err = createErrorJSON(errorCode, errorMessage, dataMap) promise.reject("error", err) } @@ -210,8 +213,12 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext) : ReactConte } SmallcaseGatewaySdk.launchSmallPlug(currentActivity!!, SmallplugData(targetEndpoint, params), object : SmallPlugResponseListener { - override fun onFailure(errorCode: Int, errorMessage: String) { - val err = createErrorJSON(errorCode, errorMessage, null) + override fun onFailure(errorCode: Int, errorMessage: String, userInfo: UserInfo?) { + val dataMap = Arguments.createMap() + userInfoToWritableMap(userInfo)?.let { + dataMap.putMap("userInfo", it) + } + val err = createErrorJSON(errorCode, errorMessage, dataMap) promise.reject("error", err) } @@ -469,15 +476,36 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext) : ReactConte writableMap.putBoolean("success", result.success) writableMap.putString("smallcaseAuthToken", result.smallcaseAuthToken) + val dataMap = Arguments.createMap() + userInfoToWritableMap(result.userInfo)?.let { + dataMap.putMap("userInfo", it) + } + + if (dataMap.keySetIterator().hasNextKey()) { + writableMap.putMap("data", dataMap) + } + return writableMap } - private fun createErrorJSON(errorCode: Int?, errorMessage: String?, data: String?): WritableMap { + private fun userInfoToWritableMap(userInfo: UserInfo?): WritableMap? { + if (userInfo == null) return null + + val map = Arguments.createMap() + map.putString("number", userInfo.number) + map.putString("countryCode", userInfo.countryCode) + return map + } + + private fun createErrorJSON(errorCode: Int?, errorMessage: String?, data: Any?): WritableMap { val errObj = Arguments.createMap() errorCode?.let { errObj.putInt("errorCode", it) } errorMessage?.let { errObj.putString("errorMessage", it) } - data?.let { errObj.putString("data", it) } + when (data) { + is String -> errObj.putString("data", data) + is WritableMap -> errObj.putMap("data", data) + } return errObj } diff --git a/smart_investing_react_native/app/apis/Functions.tsx b/smart_investing_react_native/app/apis/Functions.tsx index 186efaab..159d6a2a 100644 --- a/smart_investing_react_native/app/apis/Functions.tsx +++ b/smart_investing_react_native/app/apis/Functions.tsx @@ -422,14 +422,35 @@ interface UIConfig { backIconOpacity: number; } +export interface UserInfo { + phoneNumber: string; + phoneCountryCode: string; +} + +export interface SmallplugRes { + success: boolean; + smallcaseAuthToken: string; + data?: { + userInfo?: UserInfo; + }; +} + +export interface SmallplugError { + errorCode: number; + errorMessage: string; + data?: { + userInfo?: UserInfo; + }; +} + async function launchSmallPlug( targetEndpoint: any, params: any, uiConfig: UIConfig, -) { +): Promise { try { console.log(`launchSmallPlug start ${JSON.stringify(uiConfig)}`); - const res = await SmallcaseGateway.launchSmallplugWithBranding( + const res: any = await SmallcaseGateway.launchSmallplugWithBranding( targetEndpoint, params, uiConfig.headerColor ?? '', @@ -438,12 +459,14 @@ async function launchSmallPlug( uiConfig.backIconOpacity, ); console.log(`launch dm res -> ${JSON.stringify(res)}`); - alert('Launch Smallplug Success', JSON.stringify(res)); + await alert('Launch Smallplug Success', JSON.stringify(res)); + return res; } catch (error) { console.log( 'Launch Smallplug error stringified - ' + JSON.stringify(error), ); - alert('Launch Smallplug Error', getErrorString(error)); + await alert('Launch Smallplug Error', getErrorString(error)); + throw error; } } diff --git a/smart_investing_react_native/app/screens/SmtScreen.tsx b/smart_investing_react_native/app/screens/SmtScreen.tsx index f4ddafae..dee1fe83 100644 --- a/smart_investing_react_native/app/screens/SmtScreen.tsx +++ b/smart_investing_react_native/app/screens/SmtScreen.tsx @@ -3,8 +3,9 @@ import {Button, TextInput, View} from 'react-native'; import {launchSmallPlug} from '../apis/Functions'; const SmtScreen = () => { - const [targetEndpoint, onChangeTargetEndpoint] = - React.useState(null); + const [targetEndpoint, onChangeTargetEndpoint] = React.useState< + string | null + >(null); const [params, onChangeParams] = React.useState(null); const [headerColor, onChangeHeaderColor] = React.useState( null, @@ -15,8 +16,9 @@ const SmtScreen = () => { const [backIconColor, onChangeBackIconColor] = React.useState( null, ); - const [backIconOpacity, onChangeBackIconOpacity] = - React.useState(null); + const [backIconOpacity, onChangeBackIconOpacity] = React.useState< + string | null + >(null); return ( { }} />