Skip to content

Commit

Permalink
update imports and onResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
al-af committed Nov 6, 2024
1 parent 2f1fcf7 commit 3bfd90c
Showing 1 changed file with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

import android.util.Log;

import com.appsflyer.api.PurchaseClient;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableArray;

import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
import java.util.Arrays;
Expand Down Expand Up @@ -96,16 +97,8 @@ public void onFailure(String result, Throwable error) {
@Override
public void onResponse(Map<String, Object> response) {
if (response != null) {
WritableArray writableArray = Arguments.createArray();
for (Map.Entry<String, Object> entry : response.entrySet()) {
if (entry.getValue() instanceof Map<?, ?>) {
Map<String, Object> productData = (Map<String, Object>) entry.getValue();
WritableMap writableMap = RNUtil.toWritableMap(productData);
writableArray.pushMap(writableMap);
}
}

handleSuccess(EVENT_SUBSCRIPTION_VALIDATION_SUCCESS, writableArray);
WritableMap writableMap = RNUtil.toWritableMap(response);
handleSuccess(EVENT_SUBSCRIPTION_VALIDATION_SUCCESS, writableMap);
}
}
};
Expand Down Expand Up @@ -137,16 +130,16 @@ private void handleError(String eventName, String result, Throwable error) {
}

private void sendEvent(String eventName, Object params) {
ReactApplicationContext context = reactContext.get(); // Retrieve the context from WeakReference

if (context != null && context.hasActiveReactInstance()) { // Ensure context is not null and active
Log.d("ReactNativeJS", "Event: " + eventName + ", params: " + params.toString());
context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
} else {
Log.d("ReactNativeJS", "Skipping event: " + eventName + " (ReactContext is null or inactive)");
ReactApplicationContext context = reactContext.get(); // Retrieve the context from WeakReference
if (context != null && context.hasActiveReactInstance()) { // Ensure context is not null and active
Log.d("ReactNativeJS", "Event: " + eventName + ", params: " + params.toString());
context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
} else {
Log.d("ReactNativeJS", "Skipping event: " + eventName + " (ReactContext is null or inactive)");
}
}
}

private WritableMap errorToMap(Throwable error) {
JSONObject errorJson = new JSONObject(this.throwableToMap(error));
WritableMap errorMap = RNUtil.jsonToWritableMap(errorJson);
Expand Down

0 comments on commit 3bfd90c

Please sign in to comment.