@circle-fin/w3s-pw-react-native-sdk 1.1.7 → 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 -116
- 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 -159
- 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 -390
- 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 -211
- 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 -203
- 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,259 +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) => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
status: successResult.result?.status,
|
|
104
|
-
})
|
|
142
|
+
// If Promise resolves but no event was fired, call success callback
|
|
143
|
+
console.debug('[WalletSdk] Promise resolved')
|
|
105
144
|
successCallback(successResult)
|
|
145
|
+
cleanup()
|
|
106
146
|
})
|
|
107
147
|
.catch((e: Error) => {
|
|
148
|
+
// If Promise rejects but no event was fired, call error callback
|
|
149
|
+
console.debug('[WalletSdk] Promise rejected:', e)
|
|
108
150
|
errorCallback(e)
|
|
109
|
-
|
|
110
|
-
.finally(() => {
|
|
111
|
-
emitter.removeAllListeners(EVENT_NAME_ON_SUCCESS)
|
|
112
|
-
emitter.removeAllListeners(EVENT_NAME_ON_ERROR)
|
|
151
|
+
cleanup()
|
|
113
152
|
})
|
|
114
153
|
},
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
154
|
+
verifyOTP(
|
|
155
|
+
otpToken: string,
|
|
156
|
+
deviceToken: string,
|
|
157
|
+
deviceEncryptionKey: string,
|
|
158
|
+
successCallback: LoginSuccessCallback,
|
|
159
|
+
errorCallback: ErrorCallback,
|
|
120
160
|
): void {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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)
|
|
126
176
|
})
|
|
127
177
|
.catch((e: Error) => {
|
|
128
178
|
errorCallback(e)
|
|
129
179
|
})
|
|
130
180
|
.finally(() => {
|
|
131
|
-
|
|
132
|
-
emitter.removeAllListeners(EVENT_NAME_ON_ERROR)
|
|
181
|
+
ProgrammablewalletRnSdk.removeAllListeners(EVENT_NAME_ON_ERROR)
|
|
133
182
|
})
|
|
134
183
|
},
|
|
135
|
-
performLogin(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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)
|
|
139
202
|
})
|
|
140
203
|
.catch((e: Error) => {
|
|
204
|
+
console.debug('[WalletSdk] performLogin Promise rejected:', e)
|
|
141
205
|
errorCallback(e)
|
|
142
206
|
})
|
|
143
207
|
},
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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()
|
|
149
217
|
})
|
|
150
218
|
.catch((e: Error) => {
|
|
219
|
+
console.debug('[WalletSdk] performLogout Promise rejected:', e)
|
|
151
220
|
errorCallback(e)
|
|
152
221
|
})
|
|
153
|
-
.finally(() => {
|
|
154
|
-
emitter.removeAllListeners(EVENT_NAME_ON_ERROR)
|
|
155
|
-
})
|
|
156
222
|
},
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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()
|
|
161
270
|
})
|
|
162
271
|
.catch((e: Error) => {
|
|
272
|
+
// If Promise rejects but no event was fired, call error callback
|
|
273
|
+
console.debug('[WalletSdk] setBiometricsPin Promise rejected:', e)
|
|
163
274
|
errorCallback(e)
|
|
275
|
+
cleanup()
|
|
164
276
|
})
|
|
165
277
|
},
|
|
278
|
+
|
|
166
279
|
setDismissOnCallbackMap(map: Map<ErrorCode, boolean>): void {
|
|
167
280
|
try {
|
|
168
|
-
|
|
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)
|
|
169
284
|
} catch (e) {
|
|
170
|
-
console.error(e)
|
|
285
|
+
console.error('setDismissOnCallbackMap failed:', e)
|
|
171
286
|
}
|
|
172
287
|
},
|
|
173
288
|
moveTaskToFront(): void {
|
|
174
|
-
|
|
289
|
+
try {
|
|
290
|
+
ProgrammablewalletRnSdk.moveTaskToFront()
|
|
291
|
+
} catch (e) {
|
|
292
|
+
console.error('moveTaskToFront failed:', e)
|
|
293
|
+
}
|
|
175
294
|
},
|
|
176
295
|
moveRnTaskToFront(): void {
|
|
177
|
-
|
|
296
|
+
try {
|
|
297
|
+
ProgrammablewalletRnSdk.moveRnTaskToFront()
|
|
298
|
+
} catch (e) {
|
|
299
|
+
console.error('moveRnTaskToFront failed:', e)
|
|
300
|
+
}
|
|
178
301
|
},
|
|
179
302
|
setTextConfigsMap(map: Map<TextsKey, TextConfig[]>): void {
|
|
180
303
|
try {
|
|
181
|
-
|
|
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)
|
|
182
307
|
} catch (e) {
|
|
183
|
-
console.error(e)
|
|
308
|
+
console.error('setTextConfigsMap failed:', e)
|
|
184
309
|
}
|
|
185
310
|
},
|
|
311
|
+
|
|
186
312
|
setIconTextConfigsMap(
|
|
187
|
-
rawMap: Map<IconTextsKey, Array<IconTextConfig
|
|
313
|
+
rawMap: Map<IconTextsKey, Array<IconTextConfig>>,
|
|
188
314
|
): void {
|
|
189
315
|
try {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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)
|
|
201
334
|
} catch (e) {
|
|
202
|
-
console.error(e)
|
|
335
|
+
console.error('setIconTextConfigsMap Error:', e)
|
|
203
336
|
}
|
|
204
337
|
},
|
|
205
338
|
setTextConfigMap(map: Map<TextKey, TextConfig>): void {
|
|
206
339
|
try {
|
|
207
|
-
|
|
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)
|
|
208
343
|
} catch (e) {
|
|
209
|
-
console.error(e)
|
|
344
|
+
console.error('setTextConfigMap failed:', e)
|
|
210
345
|
}
|
|
211
346
|
},
|
|
212
|
-
|
|
347
|
+
|
|
348
|
+
setImageMap(map: Map<ImageKey, ImageSourcePropType>): void {
|
|
213
349
|
try {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
350
|
+
// Process image URLs, this part needs to be preserved
|
|
351
|
+
const processedMap = new Map<ImageKey, string>()
|
|
352
|
+
|
|
353
|
+
map.forEach((value, key) => {
|
|
217
354
|
const url = getImageUrl(value)
|
|
218
|
-
|
|
219
|
-
|
|
355
|
+
// Only keep non-null URLs
|
|
356
|
+
if (url !== null) {
|
|
357
|
+
processedMap.set(key, url)
|
|
220
358
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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)
|
|
225
364
|
} catch (e) {
|
|
226
|
-
console.error(e)
|
|
365
|
+
console.error('setImageMap failed:', e)
|
|
227
366
|
}
|
|
228
367
|
},
|
|
229
368
|
setDateFormat(format: DateFormat): void {
|
|
230
|
-
|
|
369
|
+
try {
|
|
370
|
+
ProgrammablewalletRnSdk.setDateFormat(format)
|
|
371
|
+
} catch (e) {
|
|
372
|
+
console.error('setDateFormat failed:', e)
|
|
373
|
+
}
|
|
231
374
|
},
|
|
232
375
|
setDebugging(debugging: boolean): void {
|
|
233
|
-
|
|
376
|
+
try {
|
|
377
|
+
ProgrammablewalletRnSdk.setDebugging(debugging)
|
|
378
|
+
} catch (e) {
|
|
379
|
+
console.error('setDebugging failed:', e)
|
|
380
|
+
}
|
|
234
381
|
},
|
|
235
382
|
setCustomUserAgent(userAgent: string): void {
|
|
236
|
-
|
|
383
|
+
ProgrammablewalletRnSdk.setCustomUserAgent(
|
|
384
|
+
defaultUserAgentRn + ' | ' + userAgent,
|
|
385
|
+
)
|
|
237
386
|
},
|
|
238
387
|
setErrorStringMap(map: Map<ErrorCode, string>): void {
|
|
239
388
|
try {
|
|
240
|
-
|
|
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)
|
|
241
392
|
} catch (e) {
|
|
242
|
-
console.error(e)
|
|
393
|
+
console.error('setErrorStringMap failed:', e)
|
|
243
394
|
}
|
|
244
|
-
}
|
|
395
|
+
},
|
|
245
396
|
}
|
|
246
397
|
})()
|
|
247
|
-
|
|
248
|
-
function getImageUrl(source: ImageSourcePropType): string | null {
|
|
249
|
-
if (!source) {
|
|
250
|
-
return null
|
|
251
|
-
}
|
|
252
|
-
// @ts-ignore
|
|
253
|
-
const resolved = Image.resolveAssetSource(source)
|
|
254
|
-
if (!resolved || !resolved.uri) {
|
|
255
|
-
return null
|
|
256
|
-
}
|
|
257
|
-
// @ts-ignore
|
|
258
|
-
return resolved.uri
|
|
259
|
-
}
|