@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.
- package/BARE_REACT_NATIVE_GUIDE.md +397 -0
- package/LICENSE +1 -1
- package/README.md +196 -90
- package/android/build.gradle +43 -126
- package/android/src/main/AndroidManifest.xml +12 -16
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/ProgrammablewalletRnSdkModule.kt +414 -244
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/PromiseCallback.kt +76 -74
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/RecordsHelper.kt +602 -0
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/models/Records.kt +43 -0
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/pwcustom/RnImageSetter.kt +55 -33
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/pwcustom/RnLayoutProvider.kt +81 -79
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/pwcustom/RnViewSetterProvider.kt +93 -63
- package/app.json +8 -0
- package/build/ProgrammablewalletRnSdkModule.d.ts +44 -0
- package/build/ProgrammablewalletRnSdkModule.d.ts.map +1 -0
- package/build/ProgrammablewalletRnSdkModule.js +21 -0
- package/build/ProgrammablewalletRnSdkModule.js.map +1 -0
- package/build/WalletSdk.d.ts +20 -0
- package/build/WalletSdk.d.ts.map +1 -0
- package/build/WalletSdk.js +303 -0
- package/build/WalletSdk.js.map +1 -0
- package/build/bridgeSafe.d.ts +50 -0
- package/build/bridgeSafe.d.ts.map +1 -0
- package/build/bridgeSafe.js +136 -0
- package/build/bridgeSafe.js.map +1 -0
- package/build/index.d.ts +21 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +21 -0
- package/build/index.js.map +1 -0
- package/{lib/typescript/src → build}/types.d.ts +72 -43
- package/build/types.d.ts.map +1 -0
- package/build/types.js +331 -0
- package/build/types.js.map +1 -0
- package/build/utils/securityQuestionUtils.d.ts +43 -0
- package/build/utils/securityQuestionUtils.d.ts.map +1 -0
- package/build/utils/securityQuestionUtils.js +109 -0
- package/build/utils/securityQuestionUtils.js.map +1 -0
- package/expo-module.config.json +11 -0
- package/ios/Array+Extension.swift +17 -15
- package/ios/BridgeHelper.swift +71 -92
- package/ios/{RnWalletSdk+CustomizeAdapter.swift → CustomizeAdapter.swift} +19 -29
- package/ios/ProgrammablewalletRnSdk.podspec +30 -0
- package/ios/ProgrammablewalletRnSdkModule.swift +384 -0
- package/ios/TextConfig.swift +17 -15
- package/ios/TextKey.swift +17 -15
- package/ios/UIApplication+Extension.swift +26 -17
- package/ios/UIColor+Extension.swift +34 -28
- package/ios/UITextField+Extension.swift +31 -0
- package/ios/UIView+Extension.swift +24 -17
- package/package.json +70 -136
- package/plugins/apple-signin-entitlements.js +16 -0
- package/plugins/infoplist-config.js +77 -0
- package/plugins/infoplist-config.md +72 -0
- package/plugins/podfile-modifier.js +84 -0
- package/plugins/podfile-modifier.md +33 -0
- package/plugins/withCopyFiles.js +132 -0
- package/plugins/withCopyFiles.md +81 -0
- package/src/ProgrammablewalletRnSdkModule.ts +68 -38
- package/src/WalletSdk.ts +297 -155
- package/src/bridgeSafe.ts +156 -0
- package/src/index.ts +21 -0
- package/src/types.ts +133 -110
- package/src/utils/securityQuestionUtils.ts +121 -0
- package/COPYRIGHT +0 -10
- package/android/gradle.properties +0 -21
- package/android/src/main/AndroidManifestNew.xml +0 -22
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/BridgeHelper.kt +0 -399
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/ProgrammablewalletRnSdkPackage.kt +0 -49
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/PromiseCallback2.kt +0 -65
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/PromiseLogoutCallback.kt +0 -47
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/PromiseSocialCallback.kt +0 -53
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/TestHelper.kt +0 -37
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/annotation/ExcludeFromGeneratedCCReport.kt +0 -33
- package/android/src/newarch/ProgrammablewalletRnSdkSpec.kt +0 -29
- package/android/src/oldarch/ProgrammablewalletRnSdkSpec.kt +0 -76
- package/circlefin-w3s-pw-react-native-sdk.podspec +0 -41
- package/ios/EventEmitter.swift +0 -49
- package/ios/ProgrammablewalletRnSdk.h +0 -29
- package/ios/ProgrammablewalletRnSdk.mm +0 -162
- package/ios/ReactNativeEventEmitter.m +0 -27
- package/ios/ReactNativeEventEmitter.swift +0 -37
- package/ios/RnWalletSdk.swift +0 -385
- package/ios/programmablewallet-rn-sdk-Bridging-Header.h +0 -22
- package/lib/commonjs/NativeProgrammablewalletRnSdk.js +0 -24
- package/lib/commonjs/NativeProgrammablewalletRnSdk.js.map +0 -1
- package/lib/commonjs/ProgrammablewalletRnSdkModule.js +0 -38
- package/lib/commonjs/ProgrammablewalletRnSdkModule.js.map +0 -1
- package/lib/commonjs/WalletSdk.js +0 -206
- package/lib/commonjs/WalletSdk.js.map +0 -1
- package/lib/commonjs/index.js +0 -74
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/types.js +0 -342
- package/lib/commonjs/types.js.map +0 -1
- package/lib/module/NativeProgrammablewalletRnSdk.js +0 -19
- package/lib/module/NativeProgrammablewalletRnSdk.js.map +0 -1
- package/lib/module/ProgrammablewalletRnSdkModule.js +0 -31
- package/lib/module/ProgrammablewalletRnSdkModule.js.map +0 -1
- package/lib/module/WalletSdk.js +0 -198
- package/lib/module/WalletSdk.js.map +0 -1
- package/lib/module/index.js +0 -18
- package/lib/module/index.js.map +0 -1
- package/lib/module/types.js +0 -334
- package/lib/module/types.js.map +0 -1
- package/lib/typescript/src/NativeProgrammablewalletRnSdk.d.ts +0 -28
- package/lib/typescript/src/NativeProgrammablewalletRnSdk.d.ts.map +0 -1
- package/lib/typescript/src/ProgrammablewalletRnSdkModule.d.ts +0 -3
- package/lib/typescript/src/ProgrammablewalletRnSdkModule.d.ts.map +0 -1
- package/lib/typescript/src/WalletSdk.d.ts +0 -3
- package/lib/typescript/src/WalletSdk.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts +0 -4
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/lib/typescript/src/types.d.ts.map +0 -1
- package/src/NativeProgrammablewalletRnSdk.ts +0 -77
- package/src/index.tsx +0 -29
package/src/WalletSdk.ts
CHANGED
|
@@ -1,255 +1,397 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
type LoginResult,
|
|
37
|
+
SecurityQuestion,
|
|
38
|
+
InputType,
|
|
47
39
|
} from './types'
|
|
48
|
-
import
|
|
40
|
+
import { bridgeSafe } from './bridgeSafe'
|
|
41
|
+
const packageJson = require('../package.json')
|
|
49
42
|
|
|
50
|
-
|
|
43
|
+
import ProgrammablewalletRnSdk from './ProgrammablewalletRnSdkModule'
|
|
44
|
+
import { ImageSourcePropType, Image } from 'react-native'
|
|
51
45
|
|
|
52
|
-
|
|
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:
|
|
78
|
+
native: ProgrammablewalletRnSdk.sdkVersion,
|
|
70
79
|
rn: packageJson.version,
|
|
71
80
|
},
|
|
72
|
-
|
|
81
|
+
get deviceId() {
|
|
82
|
+
return ProgrammablewalletRnSdk.getDeviceId()
|
|
83
|
+
},
|
|
84
|
+
getDeviceId: ProgrammablewalletRnSdk.getDeviceId,
|
|
73
85
|
init(configuration: Configuration): Promise<void> {
|
|
74
|
-
const promise =
|
|
75
|
-
|
|
86
|
+
const promise = ProgrammablewalletRnSdk.initSdk(configuration)
|
|
87
|
+
ProgrammablewalletRnSdk.setCustomUserAgent(defaultUserAgentRn)
|
|
76
88
|
return promise
|
|
77
89
|
},
|
|
78
|
-
setSecurityQuestions(securityQuestions:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
154
|
+
verifyOTP(
|
|
155
|
+
otpToken: string,
|
|
156
|
+
deviceToken: string,
|
|
157
|
+
deviceEncryptionKey: string,
|
|
158
|
+
successCallback: LoginSuccessCallback,
|
|
159
|
+
errorCallback: ErrorCallback,
|
|
116
160
|
): void {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
128
|
-
emitter.removeAllListeners(EVENT_NAME_ON_ERROR)
|
|
181
|
+
ProgrammablewalletRnSdk.removeAllListeners(EVENT_NAME_ON_ERROR)
|
|
129
182
|
})
|
|
130
183
|
},
|
|
131
|
-
performLogin(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
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
|
-
|
|
289
|
+
try {
|
|
290
|
+
ProgrammablewalletRnSdk.moveTaskToFront()
|
|
291
|
+
} catch (e) {
|
|
292
|
+
console.error('moveTaskToFront failed:', e)
|
|
293
|
+
}
|
|
171
294
|
},
|
|
172
295
|
moveRnTaskToFront(): void {
|
|
173
|
-
|
|
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
|
-
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
|
|
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
|
-
|
|
347
|
+
|
|
348
|
+
setImageMap(map: Map<ImageKey, ImageSourcePropType>): void {
|
|
209
349
|
try {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
215
|
-
|
|
355
|
+
// Only keep non-null URLs
|
|
356
|
+
if (url !== null) {
|
|
357
|
+
processedMap.set(key, url)
|
|
216
358
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
383
|
+
ProgrammablewalletRnSdk.setCustomUserAgent(
|
|
384
|
+
defaultUserAgentRn + ' | ' + userAgent,
|
|
385
|
+
)
|
|
233
386
|
},
|
|
234
387
|
setErrorStringMap(map: Map<ErrorCode, string>): void {
|
|
235
388
|
try {
|
|
236
|
-
|
|
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
|
-
}
|