react-native-hyperkyc-sdk 2.7.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,7 +56,7 @@ repositories {
56
56
  dependencies {
57
57
  //noinspection GradleDynamicVersion
58
58
  implementation "com.facebook.react:react-native:+" // From node_modules
59
- implementation('co.hyperverge:hyperkyc:2.7.0@aar', {
59
+ implementation('co.hyperverge:hyperkyc:2.8.0@aar', {
60
60
  transitive = true
61
61
  exclude group: 'co.hyperverge', module: 'hyperdocdetect'
62
62
  exclude group: 'co.hyperverge', module: 'hypersnap-pdf'
@@ -37,10 +37,41 @@ public class HyperkycSdkModule extends ReactContextBaseJavaModule {
37
37
  private final ReactApplicationContext reactContext;
38
38
  private final int HYPERKYC_REQUEST_CODE = 56455;
39
39
  private boolean isEventListenerAdded = false;
40
+ /* volatile because
41
+ 1. the pendingCallback is written on JS bridge thread (launch()),
42
+ 2. read/nulled on main thread (onActivityResult),
43
+ 3. nulled on teardown thread (invalidate()).
44
+ Without volatile, the JMM provides no happens-before guarantee — the main thread may cache a stale null
45
+ and silently drop the KYC result. Works in practice without volatile (user spending more time in completing the workflow between write and read),
46
+ but timing is not a JMM guarantee. */
47
+ private volatile Callback pendingCallback = null;
48
+ /* Contract is stateless — createIntent and parseResult carry no per-launch state. */
49
+ private final HyperKyc.Contract contract = new HyperKyc.Contract();
50
+ /* Registered once at construction; never re-registered. Accumulation is impossible. */
51
+ private final ActivityEventListener kycActivityListener = new ActivityEventListener() {
52
+ @Override
53
+ public void onActivityResult(Activity activity, int requestCode,
54
+ int resultCode, Intent data) {
55
+ if (requestCode != HYPERKYC_REQUEST_CODE) return;
56
+ Callback cb = pendingCallback;
57
+ if (cb == null) return;
58
+ pendingCallback = null;
59
+ HyperKycResult result = contract.parseResult(resultCode, data);
60
+ if (result == null) {
61
+ cb.invoke(getDummyResultMap());
62
+ } else {
63
+ parseKYCResult(result, cb);
64
+ }
65
+ }
66
+
67
+ @Override
68
+ public void onNewIntent(Intent intent) {}
69
+ };
40
70
 
41
71
  public HyperkycSdkModule(ReactApplicationContext reactContext) {
42
72
  super(reactContext);
43
73
  this.reactContext = reactContext;
74
+ reactContext.addActivityEventListener(kycActivityListener);
44
75
  }
45
76
 
46
77
  @Override
@@ -75,28 +106,15 @@ public class HyperkycSdkModule extends ReactContextBaseJavaModule {
75
106
  @ReactMethod
76
107
  public void launch(ReadableMap kycConfig, Callback resultCallback) {
77
108
  ReactActivity currentActivity = (ReactActivity) getCurrentActivity();
78
- assert kycConfig != null;
109
+ if (currentActivity == null || kycConfig == null) {
110
+ resultCallback.invoke(getDummyResultMap());
111
+ return;
112
+ }
79
113
  HyperKycConfig config = getHyperKycConfigFromMap(kycConfig);
80
- HyperKyc.Contract contract = new HyperKyc.Contract();
81
-
82
- reactContext.addActivityEventListener(new ActivityEventListener() {
83
- @Override
84
- public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
85
- if (requestCode == HYPERKYC_REQUEST_CODE) {
86
- HyperKycResult hyperKycResult = contract.parseResult(resultCode, data);
87
- parseKYCResult(hyperKycResult, resultCallback);
88
- } else {
89
- resultCallback.invoke(getDummyResultMap());
90
- }
91
- reactContext.removeActivityEventListener(this);
92
- }
93
-
94
- @Override
95
- public void onNewIntent(Intent intent) {
96
- }
97
- });
98
114
 
115
+ /* Clear any accumulated event listeners before adding a fresh one, so at most one event listener is active at any time. */
99
116
  if (isEventListenerAdded) {
117
+ HyperKyc.removeAllEventListeners();
100
118
  Function1<JSONObject, Unit> listener = jsonObject -> {
101
119
  try {
102
120
  WritableMap eventMap = HyperkycSdkUtils.convertJsonToMap(jsonObject);
@@ -109,12 +127,19 @@ public class HyperkycSdkModule extends ReactContextBaseJavaModule {
109
127
  HyperKyc.addEventListener(listener);
110
128
  }
111
129
 
112
- if (currentActivity != null) {
113
- Intent newIntent = contract.createIntent(currentActivity, config);
114
- currentActivity.startActivityIfNeeded(newIntent, HYPERKYC_REQUEST_CODE);
115
- } else {
116
- resultCallback.invoke(getDummyResultMap());
117
- }
130
+ /* Supersede any prior in-flight session — old callback silently discarded. */
131
+ pendingCallback = resultCallback;
132
+
133
+ Intent newIntent = contract.createIntent(currentActivity, config);
134
+ currentActivity.startActivityIfNeeded(newIntent, HYPERKYC_REQUEST_CODE);
135
+ }
136
+
137
+ /* invalidate() is the correct teardown hook for both old and new RN architecture;
138
+ onCatalystInstanceDestroy() is deprecated and removed in some RN versions. */
139
+ @Override
140
+ public void invalidate() {
141
+ pendingCallback = null;
142
+ reactContext.removeActivityEventListener(kycActivityListener);
118
143
  }
119
144
 
120
145
  private void sendEvent(String eventName, WritableMap eventProperties) {
@@ -181,7 +206,7 @@ public class HyperkycSdkModule extends ReactContextBaseJavaModule {
181
206
  Boolean useLocation = kycConfig.hasKey("useLocation") ? kycConfig.getBoolean("useLocation") : null;
182
207
  String uniqueId = kycConfig.hasKey("uniqueId") ? kycConfig.getString("uniqueId") : null;
183
208
  Map<String, String> metadata = new HashMap<>();
184
- metadata.put("sdk-version", "2.7.0");
209
+ metadata.put("sdk-version", "2.9.0");
185
210
  metadata.put("sdk-type", "React Native");
186
211
  if (accessToken == null) {
187
212
  assert appId != null;
@@ -45,7 +45,7 @@ class Hyperkyc: RCTEventEmitter {
45
45
  let useLocation = _config["useLocation"] as? Bool
46
46
  let uniqueId = _config["uniqueId"] as? String
47
47
  let metadata: [String: String] = [
48
- "sdk-version": "2.7.0",
48
+ "sdk-version": "2.9.0",
49
49
  "sdk-type": "React Native"
50
50
  ]
51
51
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-hyperkyc-sdk",
3
- "version": "2.7.0",
3
+ "version": "2.9.0",
4
4
  "description": "React Native wrapper for HyperKYC SDK",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
17
17
  s.static_framework = true
18
18
 
19
19
  s.dependency "React-Core"
20
- s.dependency "HyperKYC", "1.3.0"
20
+ s.dependency "HyperKYC", "1.4.1"
21
21
  # Need these lines to support HyperKYC framework
22
22
  s.preserve_paths = 'HyperKYC.framework'
23
23
  s.xcconfig = { 'OTHER_LDFLAGS' => '-framework HyperKYC' }