Skip to content

Mixpanel callback added #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ await SmallcaseGateway.setConfigEnvironment({
});

// initialize session
await SmallcaseGateway.init(sdkToken);
await SmallcaseGateway.initSDK(sdkToken);

// execute a transaction
const res = await SmallcaseGateway.triggerTransaction(transactionId);
Expand Down
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:4.1.0'
implementation 'com.smallcase.gateway:sdk-mixpanelCallbackTwo:4.2.2-3176-release'
implementation 'com.smallcase.loans:sdk:3.1.0'
implementation "androidx.core:core-ktx:1.3.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand Down
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SmallcaseGateway_kotlinVersion=1.7.0
SmallcaseGateway_minSdkVersion=21
SmallcaseGateway_minSdkVersion=23
SmallcaseGateway_targetSdkVersion=31
SmallcaseGateway_compileSdkVersion=31
SmallcaseGateway_ndkversion=21.4.7075529
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.reactnativesmallcasegateway

import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.modules.core.DeviceEventManagerModule
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import com.smallcase.gateway.portal.EventPublisher
import android.util.Log


class EventBridgeModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {

private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)

companion object {
const val TAG = "EventBridgeModule"
}

override fun getName(): String {
return "EventBridge"
}

init {
observeEvents()
}

private fun observeEvents() {
scope.launch {
EventPublisher.eventFlow.collect { event ->
sendEventToReactNative(event)
}
}
}

private fun sendEventToReactNative(event: Map<String, Any>) {
val eventName = event["eventName"] as? String // Safe cast to String?

if (eventName != null) { // Check if the eventName is not null
reactApplicationContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
.emit(eventName, event)
} else {
// Handle the case where the eventName is null, if necessary
Log.e("EventBridgeModule", "Event name is null!")
}
}


override fun onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy()
scope.cancel() // Clean up coroutine scope
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// package com.reactnativesmallcasegateway
// import com.facebook.react.ReactPackage
// import com.facebook.react.bridge.NativeModule
// import com.facebook.react.bridge.ReactApplicationContext
// import com.facebook.react.uimanager.ViewManager

// class EventBridgePackage : ReactPackage {
// override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
// return listOf(EventBridgeModule(reactContext))
// }

// override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
// return emptyList()
// }
// }
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import com.facebook.react.uimanager.ViewManager

class SmallcaseGatewayPackage : ReactPackage {
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
return listOf(SmallcaseGatewayModule(reactContext))
return listOf(EventBridgeModule(reactContext),
SmallcaseGatewayModule(reactContext)
)
}

override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
Expand Down
2 changes: 1 addition & 1 deletion example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const App = () => {
const init = useCallback(async () => {
setLog((p) => p + '\n starting init');
try {
await SmallcaseGateway.init(sdkToken);
await SmallcaseGateway.initSDK(sdkToken);
setLog((p) => p + '\n init success');
} catch (err: any) {
setLog((p) => p + '\n error during init' + JSON.stringify(err.userInfo));
Expand Down
14 changes: 14 additions & 0 deletions ios/EventBridge.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// EventBridge.m
// SmallcaseGateway
//
// Created by Aaditya Singh on 20/11/24.
// Copyright © 2024 Facebook. All rights reserved.
//

#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>

@interface RCT_EXTERN_MODULE(EventBridge, RCTEventEmitter)
RCT_EXTERN_METHOD(supportedEvents)
@end
77 changes: 77 additions & 0 deletions ios/EventBridge.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// EventBridge.swift
// SmallcaseGateway
//
// Created by Aaditya Singh on 19/11/24.
// Copyright © 2024 Facebook. All rights reserved.
//

import Combine
import React
import SCGateway

struct MixpanelConstants {
static let EVENT_TRANSACTION_TRIGGERED = "SDK - Transaction triggered"
static let EVENT_GATEWAY_CONNECT_VIEWED = "SDK - Gateway connect viewed"
static let EVENT_BROKER_CHOOSER_VIEWED = "SDK - Broker-chooser viewed"
static let EVENT_BROKER_SELECTED = "SDK - Broker selected"
static let EVENT_NATIVE_APP_LAUNCHED = "SDK - Native App Launched"
static let EVENT_NATIVE_LOGIN_FALLBACK = "SDK - Triggered native login fallback"
static let EVENT_NATIVE_LOGIN_FALLBACK_USER_CANCELLED = "SDK - User closed"
static let EVENT_BROKER_PLATFORM_OPENED = "SDK - Broker Platform Opened"
static let EVENT_BROKER_PLATFORM_LOADED = "SDK - Broker Platform Loaded"
static let EVENT_TRANSACTION_STATUS_FETCHED = "SDK - Transaction Status Fetched"
static let EVENT_SDK_INTENT_RETURNED = "SDK - Intent Returned"
static let EVENT_BP_RESPONSE_TO_PARTNER = "SDK - Response to partner"
static let EVENT_LAUNCHED_LEAD_GEN_FROM_BROKER_CHOOSER = "SDK - Launched LeadGen from broker chooser"
static let EVENT_DEVICE_BACK_BUTTON_CLICKED = "SDK - Device Back Button Clicked"
static let EVENT_USER_CLOSED = "SDK - User closed"
}

@objc(EventBridge)
class EventBridge: RCTEventEmitter {
private var cancellable: AnyCancellable?

override init() {
super.init()

print("AD::: EventBridge has been initialized")
// Observe the Combine publisher
cancellable = EventPublisher.shared.eventSubject
.sink { [weak self] event in
self?.sendEventToReactNative(event: event)
}
}

func sendEventToReactNative(event: [String: Any]) {
if let bridge = bridge {
self.sendEvent(withName: event["eventName"] as? String ?? "unknownEvent", body: event)
}
}

// MARK: - Required Methods
override func supportedEvents() -> [String]! {
return [
MixpanelConstants.EVENT_TRANSACTION_TRIGGERED,
MixpanelConstants.EVENT_GATEWAY_CONNECT_VIEWED,
MixpanelConstants.EVENT_BROKER_CHOOSER_VIEWED,
MixpanelConstants.EVENT_BROKER_SELECTED,
MixpanelConstants.EVENT_BROKER_PLATFORM_OPENED,
MixpanelConstants.EVENT_SDK_INTENT_RETURNED,
MixpanelConstants.EVENT_BP_RESPONSE_TO_PARTNER,
MixpanelConstants.EVENT_LAUNCHED_LEAD_GEN_FROM_BROKER_CHOOSER,
MixpanelConstants.EVENT_USER_CLOSED,
MixpanelConstants.EVENT_NATIVE_APP_LAUNCHED,
MixpanelConstants.EVENT_NATIVE_LOGIN_FALLBACK,
MixpanelConstants.EVENT_NATIVE_LOGIN_FALLBACK_USER_CANCELLED,
MixpanelConstants.EVENT_BROKER_PLATFORM_LOADED,
MixpanelConstants.EVENT_TRANSACTION_STATUS_FETCHED,
MixpanelConstants.EVENT_DEVICE_BACK_BUTTON_CLICKED
]

}

deinit {
cancellable?.cancel()
}
}
3 changes: 2 additions & 1 deletion ios/SmallcaseGateway-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#import <React/RCTBridgeModule.h>
#import <React/RCTViewManager.h>
#import <React/RCTBridgeModule.h>

Loading