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:6.0.0'
implementation 'com.smallcase.gateway:sdk:6.0.1'
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 @@ -25,7 +25,6 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext) : ReactConte

@ReactMethod
fun setConfigEnvironment(envName: String, gateway: String, isLeprechaunActive: Boolean, isAmoEnabled: Boolean, preProvidedBrokers: ReadableArray, promise: Promise) {

try {
val brokerList = ArrayList<String>()
for (index in 0 until preProvidedBrokers.size()) {
Expand All @@ -38,6 +37,11 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext) : ReactConte
val protocol = getProtocol(envName)

val env = Environment(gateway = gateway, buildType = protocol, isAmoEnabled = isAmoEnabled, preProvidedBrokers = brokerList, isLeprachaunActive = isLeprechaunActive)

// Set userIdentification if provided - For Now, we are not accepting this on Gateway SDK
// if (!userId.isNullOrEmpty()) {
// env.userId = userIdentification
// }

SmallcaseGatewaySdk.setConfigEnvironment(environment = env, smallcaseGatewayListeners = object : SmallcaseGatewayListeners {
override fun onGatewaySetupSuccessfull() {
Expand Down Expand Up @@ -66,8 +70,9 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext) : ReactConte
}

@ReactMethod
fun init(sdkToken: String, promise: Promise) {

fun init(sdkToken: String, externalMeta: ReadableMap?, promise: Promise) {
// externalMeta is accepted but not used on Android (iOS only feature)
// Extract externalIdentifier if needed in future
val initReq = InitRequest(sdkToken)
SmallcaseGatewaySdk.init(authRequest = initReq, gatewayInitialisationListener = object : DataListener<InitialisationResponse> {
override fun onFailure(errorCode: Int, errorMessage: String, data: String?) {
Expand Down
9 changes: 6 additions & 3 deletions ios/SmallcaseGateway.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ @interface RCT_EXTERN_MODULE(SmallcaseGateway, NSObject)
isLeprechaunActive:isLeprechaunActive
isAmoEnabled:isAmoEnabled];

[SCGateway.shared setupWithConfig: config completion:^(BOOL success,NSError * error) {
[SCGateway.shared setupWithConfig:config completion:^(BOOL success, NSError *error) {
if(success) {
resolve(@(YES));
} else {
Expand All @@ -65,16 +65,19 @@ @interface RCT_EXTERN_MODULE(SmallcaseGateway, NSObject)

reject(@"setConfigEnvironment", @"Env setup failed", err);
}

}];
}

//MARK: SDK init
RCT_REMAP_METHOD(init,
sdkToken:(NSString *)sdkToken
externalMeta:(NSDictionary *)externalMeta
initWithResolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
[SCGateway.shared initializeGatewayWithSdkToken:sdkToken completion:^(BOOL success, NSError * error) {

[SCGateway.shared initializeGatewayWithSdkToken:sdkToken
externalMeta:externalMeta
completion:^(BOOL success, NSError *error) {
if(success) {
resolve(@(YES));
} else {
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', '7.0.0'
s.dependency 'SCGateway', '7.0.1'
s.dependency 'SCLoans', '6.0.2'
end
13 changes: 13 additions & 0 deletions smart_investing_react_native/app/apis/Functions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ async function setEnvironment(
}
const initGatewayResponse = await SmallcaseGateway.init(
authJwtResult.authJwt,
{
externalIdentifier: {
userId: "testValue", // Replace with actual userId if needed
},
},
);
console.log('initGatewayResponse: ' + initGatewayResponse);
alert('Set Environment', 'Successful!!');
Expand All @@ -94,6 +99,7 @@ async function connect(env: Environment, userId: string): Promise<Boolean> {
null,
null,
);
console.log(`Transaction ID: ${transactionId}, Intent: ${transactionType.connect}`);
console.log('transactionId: ' + transactionId);
const transactionResponse = await SmallcaseGateway.triggerTransaction(
transactionId,
Expand Down Expand Up @@ -123,6 +129,7 @@ async function connect(env: Environment, userId: string): Promise<Boolean> {

async function triggerMftxn(env: Environment, transactionId: string) {
try {
console.log(`Transaction ID: ${transactionId}, Intent: MF_HOLDINGS_IMPORT`);
console.log('triggerMftxn txn id: ' + transactionId);
const res = await SmallcaseGateway.triggerMfTransaction(transactionId);
console.log('triggerMftxn res: ' + JSON.stringify(res));
Expand All @@ -148,6 +155,7 @@ async function placeSstOrder(
null,
null,
);
console.log(`Transaction ID: ${transactionId}, Intent: ${transactionType.transaction}`);
console.log('sst txn id: ' + transactionId);
const res = await SmallcaseGateway.triggerTransaction(transactionId, {
test: 'test',
Expand Down Expand Up @@ -180,6 +188,7 @@ async function authorizeHoldings(env: Environment, userId: string) {
null,
null,
);
console.log(`Transaction ID: ${transactionId}, Intent: ${transactionType.authorizeHoldings}`);
console.log('authorizeHoldings txn id: ' + transactionId);
const res = await SmallcaseGateway.triggerTransaction(transactionId, {
test: 'test',
Expand All @@ -204,6 +213,7 @@ async function reconcileHoldings(env: Environment, userId: string) {
null,
null,
);
console.log(`Transaction ID: ${transactionId}, Intent: ${transactionType.transaction} (RECONCILIATION)`);
const res = await SmallcaseGateway.triggerTransaction(transactionId);
console.log('reconcileHoldings res: ' + JSON.stringify(res));
alert('Reconcile Holdings', JSON.stringify(res));
Expand Down Expand Up @@ -238,6 +248,7 @@ async function importHoldings(
assetConfig,
null,
);
console.log(`Transaction ID: ${transactionId}, Intent: ${transactionType.holdingsImport}`);
console.log('importHoldings txn id: ' + transactionId);
const res = await SmallcaseGateway.triggerTransaction(transactionId, {
test: 'test',
Expand Down Expand Up @@ -396,6 +407,7 @@ async function fetchFunds(env: Environment, userId: string): Promise<number> {
null,
null,
);
console.log(`Transaction ID: ${transactionId}, Intent: ${transactionType.fetchFunds}`);
console.log('fetchFunds txn id: ' + transactionId);
const res = await SmallcaseGateway.triggerTransaction(transactionId, {
test: 'test',
Expand Down Expand Up @@ -504,6 +516,7 @@ async function logout() {

async function triggerTxn(txnId: string) {
try {
console.log(`Transaction ID: ${txnId}, Intent: MANUAL_TRIGGER`);
const res = await SmallcaseGateway.triggerTransaction(txnId, {
test: 'test',
});
Expand Down
8 changes: 6 additions & 2 deletions src/SmallcaseGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,14 @@ const setConfigEnvironment = async (envConfig) => {
*
* note: this must be called after `setConfigEnvironment()`
* @param {string} sdkToken
* @param {Object} [externalMeta] - external metadata (iOS only, optional)
* @param {Object} [externalMeta.externalIdentifier] - key-value pairs for external identifiers (e.g., { userId: '123' })
*/
const init = async (sdkToken) => {
const init = async (sdkToken, externalMeta) => {
const safeToken = typeof sdkToken === 'string' ? sdkToken : '';
return SmallcaseGatewayNative.init(safeToken);
const safeExternalMeta = externalMeta && typeof externalMeta === 'object' ? externalMeta : null;

return SmallcaseGatewayNative.init(safeToken, safeExternalMeta);
};

/**
Expand Down
22 changes: 16 additions & 6 deletions src/__tests__/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,32 @@ describe('init', () => {

test('valid', async () => {
await SmallcaseGateway.init('test-token');
expect(initFn).toHaveBeenNthCalledWith(1, 'test-token');
expect(initFn).toHaveBeenNthCalledWith(1, 'test-token', null);
});

test('valid with externalMeta', async () => {
const externalMeta = {
externalIdentifier: {
userId: 'user123'
}
};
await SmallcaseGateway.init('test-token', externalMeta);
expect(initFn).toHaveBeenNthCalledWith(2, 'test-token', externalMeta);
});

test('empty', async () => {
await SmallcaseGateway.init();
expect(initFn).toHaveBeenNthCalledWith(2, '');
expect(initFn).toHaveBeenNthCalledWith(3, '', null);
});

test('invalid', async () => {
await SmallcaseGateway.init(undefined);
expect(initFn).toHaveBeenNthCalledWith(3, '');
expect(initFn).toHaveBeenNthCalledWith(4, '', null);

await SmallcaseGateway.init({});
expect(initFn).toHaveBeenNthCalledWith(4, '');
await SmallcaseGateway.init('test-token', {});
expect(initFn).toHaveBeenNthCalledWith(5, 'test-token', {});

await SmallcaseGateway.init(123);
expect(initFn).toHaveBeenNthCalledWith(5, '');
expect(initFn).toHaveBeenNthCalledWith(6, '', null);
});
});
4 changes: 3 additions & 1 deletion types/SmallcaseGateway.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ declare namespace SmallcaseGateway {
*
* note: this must be called after `setConfigEnvironment()`
* @param {string} sdkToken
* @param {Object} [externalMeta] - external metadata (iOS only, optional)
* @param {Object} [externalMeta.externalIdentifier] - key-value pairs for external identifiers (e.g., { userId: '123' })
*/
declare function init(sdkToken: string): unknown;
declare function init(sdkToken: string, externalMeta?: { externalIdentifier?: { [key: string]: string } }): unknown;
/**
* Logs the user out and removes the web session.
*
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ declare const _default: {
authorizeHoldings: string;
mfHoldingsImport: string;
};
init: (sdkToken: string) => unknown;
init: (sdkToken: string, externalMeta?: { externalIdentifier?: { [key: string]: string } }) => unknown;
logoutUser: () => Promise;
triggerLeadGen: (userDetails?: import("./SmallcaseGateway").userDetails, utmParams?: any) => any;
triggerLeadGenWithStatus: (userDetails?: import("./SmallcaseGateway").userDetails) => Promise;
Expand Down