Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def kotlin_version = getExtOrDefault('kotlinVersion')
dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
implementation 'com.smallcase.gateway:sdk:5.0.1'
implementation 'com.smallcase.gateway:sdk:6.0.0'
implementation 'com.smallcase.loans:sdk:4.0.0'
implementation "androidx.core:core-ktx:1.3.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ 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) {
override fun onFailure(errorCode: Int, errorMessage: String) {
val err = createErrorJSON(errorCode, errorMessage, null)

promise.reject("error", err)
}

Expand Down Expand Up @@ -469,15 +468,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
}
Expand Down
98 changes: 60 additions & 38 deletions ios/SmallcaseGateway.m
Original file line number Diff line number Diff line change
Expand Up @@ -333,40 +333,51 @@ @interface RCT_EXTERN_MODULE(SmallcaseGateway, NSObject)

[SCGateway.shared launchSmallPlugWithPresentingController:[[[UIApplication sharedApplication] keyWindow] rootViewController] smallplugData:smallplugData completion:^(id smallplugResponse, NSError * error) {

NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];

if (error != nil) {
NSLog(@"%@", error.domain);
double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
[responseDict setValue:[NSNumber numberWithBool:false] forKey:@"success"];
[responseDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
[responseDict setValue:error.domain forKey:@"error"];

resolve(responseDict);
return;
NSMutableDictionary *errorDict = [[NSMutableDictionary alloc] init];
[errorDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
[errorDict setValue:error.domain forKey:@"errorMessage"];

reject(@"error", error.domain, error);
});
} else {

if ([smallplugResponse isKindOfClass: [NSString class]]) {
NSLog(@"%@", smallplugResponse);

[responseDict setValue:[NSNumber numberWithBool: true] forKey:@"success"];
[responseDict setValue:smallplugResponse forKey:@"smallcaseAuthToken"];
if ([smallplugResponse isKindOfClass:[SmallPlugResult class]]) {
SmallPlugResult *result = (SmallPlugResult *)smallplugResponse;

NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
[responseDict setValue:[NSNumber numberWithBool:true] forKey:@"success"];

if (result.smallcaseAuthToken) {
[responseDict setValue:result.smallcaseAuthToken forKey:@"smallcaseAuthToken"];
}

// Add userInfo inside data object if available
if (result.userInfo) {
NSMutableDictionary *dataDict = [[NSMutableDictionary alloc] init];
NSMutableDictionary *userInfoDict = [[NSMutableDictionary alloc] init];

if (result.userInfo.number) {
[userInfoDict setValue:result.userInfo.number forKey:@"number"];
}
if (result.userInfo.countryCode) {
[userInfoDict setValue:result.userInfo.countryCode forKey:@"countryCode"];
}

[dataDict setValue:userInfoDict forKey:@"userInfo"];
[responseDict setValue:dataDict forKey:@"data"];
}

double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {

resolve(responseDict);
return;

});
}
}

}];
});
}
Expand Down Expand Up @@ -405,40 +416,51 @@ @interface RCT_EXTERN_MODULE(SmallcaseGateway, NSObject)

[SCGateway.shared launchSmallPlugWithPresentingController:[[[UIApplication sharedApplication] keyWindow] rootViewController] smallplugData:smallplugData smallplugUiConfig:smallplugUiConfig completion:^(id smallplugResponse, NSError * error) {

NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];

if (error != nil) {
NSLog(@"%@", error.domain);
double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
[responseDict setValue:[NSNumber numberWithBool:false] forKey:@"success"];
[responseDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
[responseDict setValue:error.domain forKey:@"error"];

resolve(responseDict);
return;
NSMutableDictionary *errorDict = [[NSMutableDictionary alloc] init];
[errorDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
[errorDict setValue:error.domain forKey:@"errorMessage"];

reject(@"error", error.domain, error);
});
} else {

if ([smallplugResponse isKindOfClass: [NSString class]]) {
NSLog(@"%@", smallplugResponse);

[responseDict setValue:[NSNumber numberWithBool: true] forKey:@"success"];
[responseDict setValue:smallplugResponse forKey:@"smallcaseAuthToken"];
if ([smallplugResponse isKindOfClass:[SmallPlugResult class]]) {
SmallPlugResult *result = (SmallPlugResult *)smallplugResponse;

NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
[responseDict setValue:[NSNumber numberWithBool:true] forKey:@"success"];

if (result.smallcaseAuthToken) {
[responseDict setValue:result.smallcaseAuthToken forKey:@"smallcaseAuthToken"];
}

// Add userInfo inside data object if available
if (result.userInfo) {
NSMutableDictionary *dataDict = [[NSMutableDictionary alloc] init];
NSMutableDictionary *userInfoDict = [[NSMutableDictionary alloc] init];

if (result.userInfo.number) {
[userInfoDict setValue:result.userInfo.number forKey:@"number"];
}
if (result.userInfo.countryCode) {
[userInfoDict setValue:result.userInfo.countryCode forKey:@"countryCode"];
}

[dataDict setValue:userInfoDict forKey:@"userInfo"];
[responseDict setValue:dataDict forKey:@"data"];
}

double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {

resolve(responseDict);
return;

});
}
}

}];
});
}
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@
"jest": "^28.1.1",
"pod-install": "^0.1.0",
"prettier": "^2.0.5",
"react": "17.0.2",
"react-native": "0.68.2",
"react-native-builder-bob": "^0.18.3",
"release-it": "^15.0.0",
"standard-version": "^9.5.0",
Expand Down
2 changes: 1 addition & 1 deletion react-native-smallcase-gateway.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ Pod::Spec.new do |s|
s.dependency "ReactCommon/turbomodule/core"
end

s.dependency 'SCGateway', '6.1.1'
s.dependency 'SCGateway', '7.0.0'
s.dependency 'SCLoans', '6.0.2'
end
3 changes: 2 additions & 1 deletion smart_investing_react_native/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
# your application. You should enable this flag either if you want
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
newArchEnabled=true
newArchEnabled=false
fabricEnabled=false

# Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead.
Expand Down
31 changes: 27 additions & 4 deletions smart_investing_react_native/app/apis/Functions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<SmallplugRes> {
try {
console.log(`launchSmallPlug start ${JSON.stringify(uiConfig)}`);
const res = await SmallcaseGateway.launchSmallplugWithBranding(
const res: any = await SmallcaseGateway.launchSmallplugWithBranding(
targetEndpoint,
params,
uiConfig.headerColor ?? '',
Expand All @@ -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;
}
}

Expand Down
34 changes: 28 additions & 6 deletions smart_investing_react_native/app/screens/SmtScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import {Button, TextInput, View} from 'react-native';
import {launchSmallPlug} from '../apis/Functions';

const SmtScreen = () => {
const [targetEndpoint, onChangeTargetEndpoint] =
React.useState<string | null>(null);
const [targetEndpoint, onChangeTargetEndpoint] = React.useState<
string | null
>(null);
const [params, onChangeParams] = React.useState<string | null>(null);
const [headerColor, onChangeHeaderColor] = React.useState<string | null>(
null,
Expand All @@ -15,8 +16,9 @@ const SmtScreen = () => {
const [backIconColor, onChangeBackIconColor] = React.useState<string | null>(
null,
);
const [backIconOpacity, onChangeBackIconOpacity] =
React.useState<string | null>(null);
const [backIconOpacity, onChangeBackIconOpacity] = React.useState<
string | null
>(null);
return (
<View>
<TextInput
Expand Down Expand Up @@ -56,7 +58,7 @@ const SmtScreen = () => {
}}
/>
<Button
onPress={() => {
onPress={async () => {
console.log(`SmtScreen - ${headerColor} ${headerOpacity}`);
let ho = getFloatFromString(headerOpacity, 1);
let bo = getFloatFromString(backIconOpacity, 1);
Expand All @@ -67,7 +69,27 @@ const SmtScreen = () => {
backIconColor: backIconColor,
backIconOpacity: bo,
};
launchSmallPlug(targetEndpoint, params, config);

try {
const result = await launchSmallPlug(
targetEndpoint,
params,
config,
);
console.log('✅ Smallplug Success:', result);
if (result?.data?.userInfo) {
console.log(' User Info:', result.data.userInfo);
// You can use the userInfo object here, for example, show an alert
// alert(`Success! User phone: ${result.data.userInfo.phoneNumber}`);
}
} catch (error: any) {
console.error(' Smallplug Error:', error);
if (error?.data?.userInfo) {
console.log(' User Info from error:', error.data.userInfo);
// You can use the userInfo object here
// alert(`Failure! User phone: ${error.data.userInfo.phoneNumber}`);
}
}
}}
title={'SmallPlug'}
accessibilityLabel="Learn more about this purple button"
Expand Down
Loading