@circle-fin/w3s-pw-react-native-sdk 1.1.5 → 2.0.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.
Files changed (114) hide show
  1. package/BARE_REACT_NATIVE_GUIDE.md +397 -0
  2. package/LICENSE +1 -1
  3. package/README.md +196 -90
  4. package/android/build.gradle +43 -126
  5. package/android/src/main/AndroidManifest.xml +12 -16
  6. package/android/src/main/java/com/circlefin/programmablewalletrnsdk/ProgrammablewalletRnSdkModule.kt +414 -244
  7. package/android/src/main/java/com/circlefin/programmablewalletrnsdk/PromiseCallback.kt +76 -74
  8. package/android/src/main/java/com/circlefin/programmablewalletrnsdk/RecordsHelper.kt +602 -0
  9. package/android/src/main/java/com/circlefin/programmablewalletrnsdk/models/Records.kt +43 -0
  10. package/android/src/main/java/com/circlefin/programmablewalletrnsdk/pwcustom/RnImageSetter.kt +55 -33
  11. package/android/src/main/java/com/circlefin/programmablewalletrnsdk/pwcustom/RnLayoutProvider.kt +81 -79
  12. package/android/src/main/java/com/circlefin/programmablewalletrnsdk/pwcustom/RnViewSetterProvider.kt +93 -63
  13. package/app.json +8 -0
  14. package/build/ProgrammablewalletRnSdkModule.d.ts +44 -0
  15. package/build/ProgrammablewalletRnSdkModule.d.ts.map +1 -0
  16. package/build/ProgrammablewalletRnSdkModule.js +21 -0
  17. package/build/ProgrammablewalletRnSdkModule.js.map +1 -0
  18. package/build/WalletSdk.d.ts +20 -0
  19. package/build/WalletSdk.d.ts.map +1 -0
  20. package/build/WalletSdk.js +303 -0
  21. package/build/WalletSdk.js.map +1 -0
  22. package/build/bridgeSafe.d.ts +50 -0
  23. package/build/bridgeSafe.d.ts.map +1 -0
  24. package/build/bridgeSafe.js +136 -0
  25. package/build/bridgeSafe.js.map +1 -0
  26. package/build/index.d.ts +21 -0
  27. package/build/index.d.ts.map +1 -0
  28. package/build/index.js +21 -0
  29. package/build/index.js.map +1 -0
  30. package/{lib/typescript/src → build}/types.d.ts +72 -43
  31. package/build/types.d.ts.map +1 -0
  32. package/build/types.js +331 -0
  33. package/build/types.js.map +1 -0
  34. package/build/utils/securityQuestionUtils.d.ts +43 -0
  35. package/build/utils/securityQuestionUtils.d.ts.map +1 -0
  36. package/build/utils/securityQuestionUtils.js +109 -0
  37. package/build/utils/securityQuestionUtils.js.map +1 -0
  38. package/expo-module.config.json +11 -0
  39. package/ios/Array+Extension.swift +17 -15
  40. package/ios/BridgeHelper.swift +71 -92
  41. package/ios/{RnWalletSdk+CustomizeAdapter.swift → CustomizeAdapter.swift} +19 -29
  42. package/ios/ProgrammablewalletRnSdk.podspec +30 -0
  43. package/ios/ProgrammablewalletRnSdkModule.swift +384 -0
  44. package/ios/TextConfig.swift +17 -15
  45. package/ios/TextKey.swift +17 -15
  46. package/ios/UIApplication+Extension.swift +26 -17
  47. package/ios/UIColor+Extension.swift +34 -28
  48. package/ios/UITextField+Extension.swift +31 -0
  49. package/ios/UIView+Extension.swift +24 -17
  50. package/package.json +70 -136
  51. package/plugins/apple-signin-entitlements.js +16 -0
  52. package/plugins/infoplist-config.js +77 -0
  53. package/plugins/infoplist-config.md +72 -0
  54. package/plugins/podfile-modifier.js +84 -0
  55. package/plugins/podfile-modifier.md +33 -0
  56. package/plugins/withCopyFiles.js +132 -0
  57. package/plugins/withCopyFiles.md +81 -0
  58. package/src/ProgrammablewalletRnSdkModule.ts +68 -38
  59. package/src/WalletSdk.ts +297 -155
  60. package/src/bridgeSafe.ts +156 -0
  61. package/src/index.ts +21 -0
  62. package/src/types.ts +133 -110
  63. package/src/utils/securityQuestionUtils.ts +121 -0
  64. package/COPYRIGHT +0 -10
  65. package/android/gradle.properties +0 -21
  66. package/android/src/main/AndroidManifestNew.xml +0 -22
  67. package/android/src/main/java/com/circlefin/programmablewalletrnsdk/BridgeHelper.kt +0 -399
  68. package/android/src/main/java/com/circlefin/programmablewalletrnsdk/ProgrammablewalletRnSdkPackage.kt +0 -49
  69. package/android/src/main/java/com/circlefin/programmablewalletrnsdk/PromiseCallback2.kt +0 -65
  70. package/android/src/main/java/com/circlefin/programmablewalletrnsdk/PromiseLogoutCallback.kt +0 -47
  71. package/android/src/main/java/com/circlefin/programmablewalletrnsdk/PromiseSocialCallback.kt +0 -53
  72. package/android/src/main/java/com/circlefin/programmablewalletrnsdk/TestHelper.kt +0 -37
  73. package/android/src/main/java/com/circlefin/programmablewalletrnsdk/annotation/ExcludeFromGeneratedCCReport.kt +0 -33
  74. package/android/src/newarch/ProgrammablewalletRnSdkSpec.kt +0 -29
  75. package/android/src/oldarch/ProgrammablewalletRnSdkSpec.kt +0 -76
  76. package/circlefin-w3s-pw-react-native-sdk.podspec +0 -41
  77. package/ios/EventEmitter.swift +0 -49
  78. package/ios/ProgrammablewalletRnSdk.h +0 -29
  79. package/ios/ProgrammablewalletRnSdk.mm +0 -162
  80. package/ios/ReactNativeEventEmitter.m +0 -27
  81. package/ios/ReactNativeEventEmitter.swift +0 -37
  82. package/ios/RnWalletSdk.swift +0 -385
  83. package/ios/programmablewallet-rn-sdk-Bridging-Header.h +0 -22
  84. package/lib/commonjs/NativeProgrammablewalletRnSdk.js +0 -24
  85. package/lib/commonjs/NativeProgrammablewalletRnSdk.js.map +0 -1
  86. package/lib/commonjs/ProgrammablewalletRnSdkModule.js +0 -38
  87. package/lib/commonjs/ProgrammablewalletRnSdkModule.js.map +0 -1
  88. package/lib/commonjs/WalletSdk.js +0 -206
  89. package/lib/commonjs/WalletSdk.js.map +0 -1
  90. package/lib/commonjs/index.js +0 -74
  91. package/lib/commonjs/index.js.map +0 -1
  92. package/lib/commonjs/types.js +0 -342
  93. package/lib/commonjs/types.js.map +0 -1
  94. package/lib/module/NativeProgrammablewalletRnSdk.js +0 -19
  95. package/lib/module/NativeProgrammablewalletRnSdk.js.map +0 -1
  96. package/lib/module/ProgrammablewalletRnSdkModule.js +0 -31
  97. package/lib/module/ProgrammablewalletRnSdkModule.js.map +0 -1
  98. package/lib/module/WalletSdk.js +0 -198
  99. package/lib/module/WalletSdk.js.map +0 -1
  100. package/lib/module/index.js +0 -18
  101. package/lib/module/index.js.map +0 -1
  102. package/lib/module/types.js +0 -334
  103. package/lib/module/types.js.map +0 -1
  104. package/lib/typescript/src/NativeProgrammablewalletRnSdk.d.ts +0 -28
  105. package/lib/typescript/src/NativeProgrammablewalletRnSdk.d.ts.map +0 -1
  106. package/lib/typescript/src/ProgrammablewalletRnSdkModule.d.ts +0 -3
  107. package/lib/typescript/src/ProgrammablewalletRnSdkModule.d.ts.map +0 -1
  108. package/lib/typescript/src/WalletSdk.d.ts +0 -3
  109. package/lib/typescript/src/WalletSdk.d.ts.map +0 -1
  110. package/lib/typescript/src/index.d.ts +0 -4
  111. package/lib/typescript/src/index.d.ts.map +0 -1
  112. package/lib/typescript/src/types.d.ts.map +0 -1
  113. package/src/NativeProgrammablewalletRnSdk.ts +0 -77
  114. package/src/index.tsx +0 -29
package/src/WalletSdk.ts CHANGED
@@ -1,255 +1,397 @@
1
- // Copyright (c) 2024, Circle Internet Financial, LTD. All rights reserved.
2
- //
3
- // SPDX-License-Identifier: Apache-2.0
4
- //
5
- // Licensed under the Apache License, Version 2.0 (the "License");
6
- // you may not use this file except in compliance with the License.
7
- // You may obtain a copy of the License at
8
- //
9
- // http://www.apache.org/licenses/LICENSE-2.0
10
- //
11
- // Unless required by applicable law or agreed to in writing, software
12
- // distributed under the License is distributed on an "AS IS" BASIS,
13
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- // See the License for the specific language governing permissions and
15
- // limitations under the License.
16
- import WalletSdkModule from './ProgrammablewalletRnSdkModule'
1
+ /**
2
+ * Copyright 2025 Circle Internet Group, Inc. All rights reserved.
3
+ *
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
17
18
 
18
19
  import {
19
- DeviceEventEmitter,
20
- Image,
21
- NativeEventEmitter,
22
- NativeModules,
23
- Platform,
24
- } from 'react-native'
25
- import type { ImageSourcePropType } from 'react-native/Libraries/Image/Image'
26
- import {
27
- type Configuration,
28
- type ErrorCode,
29
- type EventListener,
30
- type IconTextConfig,
31
- type IconTextsKey,
32
- type ImageKey,
33
- type IWalletSdk,
34
- type SecurityQuestion,
35
- type SuccessResult,
36
- type TextConfig,
37
- type TextKey,
38
- type TextsKey,
39
- type ErrorCallback,
40
- type SuccessCallback,
41
- type Error,
20
+ IWalletSdk,
21
+ Configuration,
22
+ TextsKey,
23
+ IconTextsKey,
24
+ TextKey,
25
+ ImageKey,
42
26
  DateFormat,
27
+ ErrorCode,
28
+ SuccessCallback,
29
+ LoginSuccessCallback,
30
+ CompletedCallback,
31
+ ErrorCallback,
32
+ SuccessResult,
33
+ LoginResult,
34
+ IconTextConfig,
35
+ TextConfig,
43
36
  SocialProvider,
44
- type LoginSuccessCallback,
45
- type CompleteCallback,
46
- type LoginResult,
37
+ SecurityQuestion,
38
+ InputType,
47
39
  } from './types'
48
- import packageJson from '../package.json'
40
+ import { bridgeSafe } from './bridgeSafe'
41
+ const packageJson = require('../package.json')
49
42
 
50
- const { ReactNativeEventEmitter } = NativeModules
43
+ import ProgrammablewalletRnSdk from './ProgrammablewalletRnSdkModule'
44
+ import { ImageSourcePropType, Image } from 'react-native'
51
45
 
52
- if (!WalletSdkModule) {
53
- throw new Error(`NativeModule: ProgrammablewalletRnSdkModule is null.`)
54
- }
55
- const emitter =
56
- Platform.OS === 'ios'
57
- ? new NativeEventEmitter(ReactNativeEventEmitter)
58
- : DeviceEventEmitter
59
- const EVENT_NAME_ON_EVENT = 'CirclePwOnEvent'
46
+ // SDK event identifiers
60
47
  const EVENT_NAME_ON_SUCCESS = 'CirclePwOnSuccess'
61
48
  const EVENT_NAME_ON_ERROR = 'CirclePwOnError'
62
49
  const USER_AGENT_RN = 'Circle-Programmable-Wallet-SDK-RN'
63
50
 
51
+ /**
52
+ * Resolves React Native image sources to URI strings for native bridge
53
+ * @param source - React Native image source
54
+ * @returns Resolved URI string or null
55
+ */
56
+ function getImageUrl(source: ImageSourcePropType): string | null {
57
+ if (!source) {
58
+ return null
59
+ }
60
+ const resolved = Image.resolveAssetSource(source)
61
+ if (
62
+ !resolved ||
63
+ typeof resolved.uri !== 'string' ||
64
+ resolved.uri.trim() === ''
65
+ ) {
66
+ return null
67
+ }
68
+ return resolved.uri
69
+ }
70
+
71
+ // Import security question utility functions
72
+ import { toPlainSecurityQuestion } from './utils/securityQuestionUtils'
73
+
64
74
  export const WalletSdk = ((): IWalletSdk => {
65
- const constants = WalletSdkModule.getConstants()
66
75
  const defaultUserAgentRn = USER_AGENT_RN + '/' + packageJson.version
67
76
  return {
68
77
  sdkVersion: {
69
- native: constants.sdkVersion,
78
+ native: ProgrammablewalletRnSdk.sdkVersion,
70
79
  rn: packageJson.version,
71
80
  },
72
- deviceId: Platform.OS === 'ios' ? constants.deviceId : (WalletSdkModule.getDeviceId() ?? constants.deviceId),
81
+ get deviceId() {
82
+ return ProgrammablewalletRnSdk.getDeviceId()
83
+ },
84
+ getDeviceId: ProgrammablewalletRnSdk.getDeviceId,
73
85
  init(configuration: Configuration): Promise<void> {
74
- const promise = WalletSdkModule.initSdk(configuration)
75
- WalletSdkModule.setCustomUserAgent(defaultUserAgentRn)
86
+ const promise = ProgrammablewalletRnSdk.initSdk(configuration)
87
+ ProgrammablewalletRnSdk.setCustomUserAgent(defaultUserAgentRn)
76
88
  return promise
77
89
  },
78
- setSecurityQuestions(securityQuestions: SecurityQuestion[]): void {
79
- WalletSdkModule.setSecurityQuestions(securityQuestions)
80
- },
81
- addListener(listener: EventListener): void {
82
- emitter.addListener(EVENT_NAME_ON_EVENT, listener)
83
- },
84
- removeAllListeners(): void {
85
- emitter.removeAllListeners(EVENT_NAME_ON_EVENT)
86
- },
87
- getDeviceId(): string {
88
- return Platform.OS === 'ios' ? constants.deviceId : (WalletSdkModule.getDeviceId() ?? constants.deviceId)
90
+ setSecurityQuestions(securityQuestions: Array<{ title: string; inputType?: InputType | string | number }>): void {
91
+ try {
92
+ // Convert each input to a proper SecurityQuestion object
93
+ const normalized: SecurityQuestion[] = (securityQuestions || []).map(q => toPlainSecurityQuestion(q))
94
+
95
+ // toPlainSecurityQuestion already performs the necessary serialization
96
+ // No need for bridgeSafe here as each question has been converted to a plain object
97
+ // with only primitive properties (string title and enum inputType)
98
+ ProgrammablewalletRnSdk.setSecurityQuestions(normalized)
99
+ } catch (e) {
100
+ console.error('setSecurityQuestions failed:', e)
101
+ }
89
102
  },
90
103
  execute(
91
104
  userToken: string,
92
105
  encryptionKey: string,
93
106
  challengeIds: string[],
94
107
  successCallback: SuccessCallback,
95
- errorCallback: ErrorCallback
108
+ errorCallback: ErrorCallback,
96
109
  ): void {
97
- emitter.addListener(EVENT_NAME_ON_SUCCESS, successCallback)
98
- emitter.addListener(EVENT_NAME_ON_ERROR, errorCallback)
99
- WalletSdkModule.execute(userToken, encryptionKey, challengeIds)
110
+ const successListener = ProgrammablewalletRnSdk.addListener(
111
+ EVENT_NAME_ON_SUCCESS,
112
+ (event: unknown) => {
113
+ console.debug('[WalletSdk] Execute result')
114
+ successCallback(event as SuccessResult)
115
+ cleanup()
116
+ },
117
+ )
118
+
119
+ const errorListener = ProgrammablewalletRnSdk.addListener(
120
+ EVENT_NAME_ON_ERROR,
121
+ (event: unknown) => {
122
+ console.debug('[WalletSdk] Error event received:', event)
123
+ // Convert event to Error object if needed
124
+ const error =
125
+ event instanceof Error
126
+ ? event
127
+ : new Error((event as { message?: string })?.message || 'Unknown error')
128
+ errorCallback(error)
129
+ cleanup()
130
+ },
131
+ )
132
+
133
+ // Cleanup function to remove listeners
134
+ const cleanup = () => {
135
+ successListener?.remove()
136
+ errorListener?.remove()
137
+ }
138
+
139
+ // Call native execute method
140
+ ProgrammablewalletRnSdk.execute(userToken, encryptionKey, challengeIds)
100
141
  .then((successResult: SuccessResult) => {
142
+ // If Promise resolves but no event was fired, call success callback
143
+ console.debug('[WalletSdk] Promise resolved')
101
144
  successCallback(successResult)
145
+ cleanup()
102
146
  })
103
147
  .catch((e: Error) => {
148
+ // If Promise rejects but no event was fired, call error callback
149
+ console.debug('[WalletSdk] Promise rejected:', e)
104
150
  errorCallback(e)
105
- })
106
- .finally(() => {
107
- emitter.removeAllListeners(EVENT_NAME_ON_SUCCESS)
108
- emitter.removeAllListeners(EVENT_NAME_ON_ERROR)
151
+ cleanup()
109
152
  })
110
153
  },
111
- setBiometricsPin(
112
- userToken: string,
113
- encryptionKey: string,
114
- successCallback: SuccessCallback,
115
- errorCallback: ErrorCallback
154
+ verifyOTP(
155
+ otpToken: string,
156
+ deviceToken: string,
157
+ deviceEncryptionKey: string,
158
+ successCallback: LoginSuccessCallback,
159
+ errorCallback: ErrorCallback,
116
160
  ): void {
117
- emitter.addListener(EVENT_NAME_ON_SUCCESS, successCallback)
118
- emitter.addListener(EVENT_NAME_ON_ERROR, errorCallback)
119
- WalletSdkModule.setBiometricsPin(userToken, encryptionKey)
120
- .then((successResult: SuccessResult) => {
121
- successCallback(successResult)
161
+ ProgrammablewalletRnSdk.addListener(EVENT_NAME_ON_ERROR, (event: unknown) => {
162
+ // Convert event to Error object if needed
163
+ const error =
164
+ event instanceof Error
165
+ ? event
166
+ : new Error((event as { message?: string })?.message || 'Unknown error')
167
+ errorCallback(error)
168
+ })
169
+ ProgrammablewalletRnSdk.verifyOTP(
170
+ otpToken,
171
+ deviceToken,
172
+ deviceEncryptionKey,
173
+ )
174
+ .then((result: LoginResult) => {
175
+ successCallback(result)
122
176
  })
123
177
  .catch((e: Error) => {
124
178
  errorCallback(e)
125
179
  })
126
180
  .finally(() => {
127
- emitter.removeAllListeners(EVENT_NAME_ON_SUCCESS)
128
- emitter.removeAllListeners(EVENT_NAME_ON_ERROR)
181
+ ProgrammablewalletRnSdk.removeAllListeners(EVENT_NAME_ON_ERROR)
129
182
  })
130
183
  },
131
- performLogin(provider: SocialProvider, deviceToken: string, deviceEncryptionKey: string, successCallback: LoginSuccessCallback, errorCallback: ErrorCallback): void {
132
- WalletSdkModule.performLogin(provider, deviceToken, deviceEncryptionKey)
133
- .then((result: LoginResult) => {
134
- successCallback(result)
184
+ performLogin(
185
+ provider: SocialProvider,
186
+ deviceToken: string,
187
+ deviceEncryptionKey: string,
188
+ successCallback: LoginSuccessCallback,
189
+ errorCallback: ErrorCallback,
190
+ ): void {
191
+ ProgrammablewalletRnSdk.performLogin(
192
+ provider,
193
+ deviceToken,
194
+ deviceEncryptionKey,
195
+ )
196
+ .then((successResult: LoginResult) => {
197
+ console.debug(
198
+ '[WalletSdk] performLogin Promise resolved:',
199
+ successResult,
200
+ )
201
+ successCallback(successResult)
135
202
  })
136
203
  .catch((e: Error) => {
204
+ console.debug('[WalletSdk] performLogin Promise rejected:', e)
137
205
  errorCallback(e)
138
206
  })
139
207
  },
140
- verifyOTP(otpToken: string, deviceToken: string, deviceEncryptionKey: string, successCallback: LoginSuccessCallback, errorCallback: ErrorCallback): void {
141
- emitter.addListener(EVENT_NAME_ON_ERROR, errorCallback)
142
- WalletSdkModule.verifyOTP(otpToken, deviceToken, deviceEncryptionKey)
143
- .then((result: LoginResult) => {
144
- successCallback(result)
208
+ performLogout(
209
+ provider: SocialProvider,
210
+ completedCallback: CompletedCallback,
211
+ errorCallback: ErrorCallback,
212
+ ): void {
213
+ ProgrammablewalletRnSdk.performLogout(provider)
214
+ .then(() => {
215
+ console.debug('[WalletSdk] performLogout Promise resolved')
216
+ completedCallback()
145
217
  })
146
218
  .catch((e: Error) => {
219
+ console.debug('[WalletSdk] performLogout Promise rejected:', e)
147
220
  errorCallback(e)
148
221
  })
149
- .finally(() => {
150
- emitter.removeAllListeners(EVENT_NAME_ON_ERROR)
151
- })
152
222
  },
153
- performLogout(provider: SocialProvider, completeCallback: CompleteCallback, errorCallback: ErrorCallback): void {
154
- WalletSdkModule.performLogout(provider)
155
- .then(() => {
156
- completeCallback()
223
+ setBiometricsPin(
224
+ userToken: string,
225
+ encryptionKey: string,
226
+ successCallback: SuccessCallback,
227
+ errorCallback: ErrorCallback,
228
+ ): void {
229
+ const successListener = ProgrammablewalletRnSdk.addListener(
230
+ EVENT_NAME_ON_SUCCESS,
231
+ (event: unknown) => {
232
+ successCallback(event as SuccessResult)
233
+ cleanup()
234
+ },
235
+ )
236
+
237
+ const errorListener = ProgrammablewalletRnSdk.addListener(
238
+ EVENT_NAME_ON_ERROR,
239
+ (event: unknown) => {
240
+ console.debug(
241
+ '[WalletSdk] setBiometricsPin Error event received:',
242
+ event,
243
+ )
244
+ // Convert event to Error object if needed
245
+ const error =
246
+ event instanceof Error
247
+ ? event
248
+ : new Error((event as { message?: string })?.message || 'Unknown error')
249
+ errorCallback(error)
250
+ cleanup()
251
+ },
252
+ )
253
+
254
+ // Cleanup function to remove listeners
255
+ const cleanup = () => {
256
+ successListener?.remove()
257
+ errorListener?.remove()
258
+ }
259
+
260
+ // Call native setBiometricsPin method
261
+ ProgrammablewalletRnSdk.setBiometricsPin(userToken, encryptionKey)
262
+ .then((successResult: SuccessResult) => {
263
+ // If Promise resolves but no event was fired, call success callback
264
+ console.debug(
265
+ '[WalletSdk] setBiometricsPin Promise resolved:',
266
+ successResult,
267
+ )
268
+ successCallback(successResult)
269
+ cleanup()
157
270
  })
158
271
  .catch((e: Error) => {
272
+ // If Promise rejects but no event was fired, call error callback
273
+ console.debug('[WalletSdk] setBiometricsPin Promise rejected:', e)
159
274
  errorCallback(e)
275
+ cleanup()
160
276
  })
161
277
  },
278
+
162
279
  setDismissOnCallbackMap(map: Map<ErrorCode, boolean>): void {
163
280
  try {
164
- WalletSdkModule.setDismissOnCallbackMap(Object.fromEntries(map))
281
+ // Use bridgeSafe for serialization and ensure the result is a non-null object
282
+ const serialized = bridgeSafe(map) as Record<string, boolean>
283
+ ProgrammablewalletRnSdk.setDismissOnCallbackMap(serialized)
165
284
  } catch (e) {
166
- console.error(e)
285
+ console.error('setDismissOnCallbackMap failed:', e)
167
286
  }
168
287
  },
169
288
  moveTaskToFront(): void {
170
- WalletSdkModule.moveTaskToFront()
289
+ try {
290
+ ProgrammablewalletRnSdk.moveTaskToFront()
291
+ } catch (e) {
292
+ console.error('moveTaskToFront failed:', e)
293
+ }
171
294
  },
172
295
  moveRnTaskToFront(): void {
173
- WalletSdkModule.moveRnTaskToFront()
296
+ try {
297
+ ProgrammablewalletRnSdk.moveRnTaskToFront()
298
+ } catch (e) {
299
+ console.error('moveRnTaskToFront failed:', e)
300
+ }
174
301
  },
175
302
  setTextConfigsMap(map: Map<TextsKey, TextConfig[]>): void {
176
303
  try {
177
- WalletSdkModule.setTextConfigsMap(Object.fromEntries(map))
304
+ // Use bridgeSafe for serialization and ensure the result is a non-null object
305
+ const serialized = bridgeSafe(map) as Record<string, TextConfig[]>
306
+ ProgrammablewalletRnSdk.setTextConfigsMap(serialized)
178
307
  } catch (e) {
179
- console.error(e)
308
+ console.error('setTextConfigsMap failed:', e)
180
309
  }
181
310
  },
311
+
182
312
  setIconTextConfigsMap(
183
- rawMap: Map<IconTextsKey, Array<IconTextConfig>>
313
+ rawMap: Map<IconTextsKey, Array<IconTextConfig>>,
184
314
  ): void {
185
315
  try {
186
- const map = {}
187
- for (const [key, configs] of rawMap) {
188
- const newConfigs = []
189
- for (const config of configs) {
190
- const url = getImageUrl(config.image)
191
- newConfigs.push({ image: url, textConfig: config.textConfig })
192
- }
193
- // @ts-ignore
194
- map[key] = newConfigs
195
- }
196
- WalletSdkModule.setIconTextConfigsMap(map)
316
+ // Create a transformed plain object instead of a Map
317
+ const processedObj: Record<string, Array<{ image: string | null; textConfig: TextConfig }>> = {}
318
+
319
+ Array.from(rawMap.entries()).forEach(([key, configs]) => {
320
+ const processedConfigs = configs.map(config => {
321
+ const { image, textConfig = {} } = config as IconTextConfig
322
+ // Process image URL, as this is React Native specific logic
323
+ return {
324
+ image: image ? getImageUrl(image) : null,
325
+ textConfig,
326
+ }
327
+ })
328
+ processedObj[String(key)] = processedConfigs
329
+ })
330
+
331
+ // Use bridgeSafe for serialization and ensure the result is a non-null object
332
+ const serialized = bridgeSafe(processedObj) as Record<string, unknown>
333
+ ProgrammablewalletRnSdk.setIconTextConfigsMap(serialized)
197
334
  } catch (e) {
198
- console.error(e)
335
+ console.error('setIconTextConfigsMap Error:', e)
199
336
  }
200
337
  },
201
338
  setTextConfigMap(map: Map<TextKey, TextConfig>): void {
202
339
  try {
203
- WalletSdkModule.setTextConfigMap(Object.fromEntries(map))
340
+ // Use bridgeSafe for serialization and ensure the result is a non-null object
341
+ const serialized = bridgeSafe(map) as Record<string, TextConfig>
342
+ ProgrammablewalletRnSdk.setTextConfigMap(serialized)
204
343
  } catch (e) {
205
- console.error(e)
344
+ console.error('setTextConfigMap failed:', e)
206
345
  }
207
346
  },
208
- setImageMap(rawMap: Map<ImageKey, ImageSourcePropType>): void {
347
+
348
+ setImageMap(map: Map<ImageKey, ImageSourcePropType>): void {
209
349
  try {
210
- const map = {}
211
- for (const [key, value] of rawMap) {
212
- // @ts-ignore
350
+ // Process image URLs, this part needs to be preserved
351
+ const processedMap = new Map<ImageKey, string>()
352
+
353
+ map.forEach((value, key) => {
213
354
  const url = getImageUrl(value)
214
- if (url == null) {
215
- continue
355
+ // Only keep non-null URLs
356
+ if (url !== null) {
357
+ processedMap.set(key, url)
216
358
  }
217
- // @ts-ignore
218
- map[key] = url
219
- }
220
- WalletSdkModule.setImageMap(map)
359
+ })
360
+
361
+ // Use bridgeSafe for serialization and ensure the result is a non-null object
362
+ const serialized = bridgeSafe(processedMap) as Record<string, string>
363
+ ProgrammablewalletRnSdk.setImageMap(serialized)
221
364
  } catch (e) {
222
- console.error(e)
365
+ console.error('setImageMap failed:', e)
223
366
  }
224
367
  },
225
368
  setDateFormat(format: DateFormat): void {
226
- WalletSdkModule.setDateFormat(format)
369
+ try {
370
+ ProgrammablewalletRnSdk.setDateFormat(format)
371
+ } catch (e) {
372
+ console.error('setDateFormat failed:', e)
373
+ }
227
374
  },
228
375
  setDebugging(debugging: boolean): void {
229
- WalletSdkModule.setDebugging(debugging)
376
+ try {
377
+ ProgrammablewalletRnSdk.setDebugging(debugging)
378
+ } catch (e) {
379
+ console.error('setDebugging failed:', e)
380
+ }
230
381
  },
231
382
  setCustomUserAgent(userAgent: string): void {
232
- WalletSdkModule.setCustomUserAgent(defaultUserAgentRn + ' | ' + userAgent)
383
+ ProgrammablewalletRnSdk.setCustomUserAgent(
384
+ defaultUserAgentRn + ' | ' + userAgent,
385
+ )
233
386
  },
234
387
  setErrorStringMap(map: Map<ErrorCode, string>): void {
235
388
  try {
236
- WalletSdkModule.setErrorStringMap(Object.fromEntries(map))
389
+ // Use bridgeSafe for serialization and ensure the result is a non-null object
390
+ const serialized = bridgeSafe(map) as Record<string, string>
391
+ ProgrammablewalletRnSdk.setErrorStringMap(serialized)
237
392
  } catch (e) {
238
- console.error(e)
393
+ console.error('setErrorStringMap failed:', e)
239
394
  }
240
- }
395
+ },
241
396
  }
242
397
  })()
243
-
244
- function getImageUrl(source: ImageSourcePropType): string | null {
245
- if (!source) {
246
- return null
247
- }
248
- // @ts-ignore
249
- const resolved = Image.resolveAssetSource(source)
250
- if (!resolved || !resolved.uri) {
251
- return null
252
- }
253
- // @ts-ignore
254
- return resolved.uri
255
- }