@circle-fin/w3s-pw-react-native-sdk 0.0.175 → 1.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/LICENSE.md +4 -17
- package/android/build.gradle +137 -0
- package/android/gradle.properties +19 -0
- package/android/src/main/AndroidManifest.xml +21 -0
- package/android/src/main/AndroidManifestNew.xml +20 -0
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/BridgeHelper.kt +388 -0
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/ProgrammablewalletRnSdkModule.kt +226 -0
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/ProgrammablewalletRnSdkPackage.kt +47 -0
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/PromiseCallback.kt +87 -0
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/TestHelper.kt +35 -0
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/pwcustom/RnImageSetter.kt +40 -0
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/pwcustom/RnLayoutProvider.kt +86 -0
- package/android/src/main/java/com/circlefin/programmablewalletrnsdk/pwcustom/RnViewSetterProvider.kt +75 -0
- package/android/src/newarch/ProgrammablewalletRnSdkSpec.kt +27 -0
- package/android/src/oldarch/ProgrammablewalletRnSdkSpec.kt +65 -0
- package/circlefin-w3s-pw-react-native-sdk.podspec +41 -0
- package/ios/Array+Extension.swift +25 -0
- package/ios/BridgeHelper.swift +183 -0
- package/ios/EventEmitter.swift +47 -0
- package/ios/ProgrammablewalletRnSdk.h +27 -0
- package/ios/ProgrammablewalletRnSdk.mm +144 -0
- package/ios/ReactNativeEventEmitter.m +25 -0
- package/ios/ReactNativeEventEmitter.swift +34 -0
- package/ios/RnWalletSdk+CustomizeAdapter.swift +367 -0
- package/ios/RnWalletSdk.swift +330 -0
- package/ios/TextConfig.swift +26 -0
- package/ios/TextKey.swift +102 -0
- package/ios/UIApplication+Extension.swift +38 -0
- package/ios/UIColor+Extension.swift +97 -0
- package/ios/UIView+Extension.swift +59 -0
- package/ios/programmablewallet-rn-sdk-Bridging-Header.h +20 -0
- package/lib/commonjs/NativeProgrammablewalletRnSdk.js +13 -0
- package/lib/commonjs/NativeProgrammablewalletRnSdk.js.map +1 -1
- package/lib/commonjs/ProgrammablewalletRnSdkModule.js +14 -0
- package/lib/commonjs/ProgrammablewalletRnSdkModule.js.map +1 -1
- package/lib/commonjs/WalletSdk.js +14 -0
- package/lib/commonjs/WalletSdk.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js +13 -0
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/NativeProgrammablewalletRnSdk.js +14 -0
- package/lib/module/NativeProgrammablewalletRnSdk.js.map +1 -1
- package/lib/module/ProgrammablewalletRnSdkModule.js +13 -0
- package/lib/module/ProgrammablewalletRnSdkModule.js.map +1 -1
- package/lib/module/WalletSdk.js +13 -0
- package/lib/module/WalletSdk.js.map +1 -1
- package/lib/module/index.js +13 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js +14 -0
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/src/NativeProgrammablewalletRnSdk.d.ts.map +1 -1
- package/lib/typescript/src/ProgrammablewalletRnSdkModule.d.ts.map +1 -1
- package/lib/typescript/src/WalletSdk.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +18 -9
- package/src/NativeProgrammablewalletRnSdk.ts +13 -0
- package/src/ProgrammablewalletRnSdkModule.ts +13 -0
- package/src/WalletSdk.ts +13 -0
- package/src/index.tsx +13 -0
- package/src/types.ts +13 -0
package/android/src/main/java/com/circlefin/programmablewalletrnsdk/ProgrammablewalletRnSdkModule.kt
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// Copyright (c) 2024, Circle Technologies, LLC. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
package com.circlefin.programmablewalletrnsdk
|
|
15
|
+
|
|
16
|
+
import android.app.ActivityManager
|
|
17
|
+
import android.content.Context
|
|
18
|
+
import circle.programmablewallet.sdk.WalletSdk
|
|
19
|
+
import circle.programmablewallet.sdk.WalletSdk.execute
|
|
20
|
+
import circle.programmablewallet.sdk.WalletSdk.executeWithUserSecret
|
|
21
|
+
import circle.programmablewallet.sdk.WalletSdk.init
|
|
22
|
+
import circle.programmablewallet.sdk.WalletSdk.setLayoutProvider
|
|
23
|
+
import circle.programmablewallet.sdk.WalletSdk.setSecurityQuestions
|
|
24
|
+
import circle.programmablewallet.sdk.WalletSdk.setViewSetterProvider
|
|
25
|
+
import circle.programmablewallet.sdk.api.ExecuteEvent
|
|
26
|
+
import circle.programmablewallet.sdk.presentation.EventListener
|
|
27
|
+
import com.circlefin.programmablewalletrnsdk.pwcustom.RnLayoutProvider
|
|
28
|
+
import com.circlefin.programmablewalletrnsdk.pwcustom.RnViewSetterProvider
|
|
29
|
+
import com.facebook.react.bridge.Arguments
|
|
30
|
+
import com.facebook.react.bridge.Promise
|
|
31
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
32
|
+
import com.facebook.react.bridge.ReactMethod
|
|
33
|
+
import com.facebook.react.bridge.ReadableArray
|
|
34
|
+
import com.facebook.react.bridge.ReadableMap
|
|
35
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class ProgrammablewalletRnSdkModule internal constructor(context: ReactApplicationContext) :
|
|
39
|
+
ProgrammablewalletRnSdkSpec(context), EventListener {
|
|
40
|
+
private var layoutProvider: RnLayoutProvider =
|
|
41
|
+
RnLayoutProvider
|
|
42
|
+
private var viewSetterProvider: RnViewSetterProvider =
|
|
43
|
+
RnViewSetterProvider
|
|
44
|
+
private var reactContext: ReactApplicationContext
|
|
45
|
+
|
|
46
|
+
init {
|
|
47
|
+
reactContext = context
|
|
48
|
+
setLayoutProvider(layoutProvider)
|
|
49
|
+
setViewSetterProvider(viewSetterProvider)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
override fun getName(): String {
|
|
53
|
+
return NAME
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@ReactMethod
|
|
57
|
+
override fun setIconTextConfigsMap(readableMap: ReadableMap) {
|
|
58
|
+
val map = BridgeHelper.getIconTextConfigsMap(reactContext, readableMap)
|
|
59
|
+
layoutProvider.setIconTextConfigsMap(map)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@ReactMethod
|
|
63
|
+
override fun setTextConfigMap(readableMap: ReadableMap) {
|
|
64
|
+
val map = BridgeHelper.getTextConfigMap(reactContext, readableMap)
|
|
65
|
+
layoutProvider.setTextConfigMap(map)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@ReactMethod
|
|
69
|
+
override fun setImageMap(readableMap: ReadableMap) {
|
|
70
|
+
val map = BridgeHelper.reactNativeMapToStringMap(readableMap)
|
|
71
|
+
viewSetterProvider.setMap(map)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@ReactMethod
|
|
75
|
+
override fun setDateFormat(value: String) {
|
|
76
|
+
layoutProvider.setDateFormat(value)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@ReactMethod
|
|
80
|
+
override fun setDebugging(value: Boolean) {
|
|
81
|
+
layoutProvider.setDebugging(value)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@ReactMethod
|
|
85
|
+
override fun setCustomUserAgent(value: String) {
|
|
86
|
+
WalletSdk.setCustomUserAgent(value)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@ReactMethod
|
|
90
|
+
override fun setErrorStringMap(readableMap: ReadableMap) {
|
|
91
|
+
val map = BridgeHelper.getErrorStringMap(readableMap)
|
|
92
|
+
layoutProvider.setErrorStringMap(map)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@ReactMethod
|
|
96
|
+
override fun setTextConfigsMap(readableMap: ReadableMap) {
|
|
97
|
+
val map = BridgeHelper.getTextConfigsMap(reactContext, readableMap)
|
|
98
|
+
layoutProvider.setTextConfigsMap(map)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@ReactMethod
|
|
102
|
+
override fun setDismissOnCallbackMap(readableMap: ReadableMap) {
|
|
103
|
+
val map = BridgeHelper.getDismissOnCallbackMap(readableMap)
|
|
104
|
+
PromiseCallback.setDismissOnCallbackMap(map)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@ReactMethod
|
|
108
|
+
override fun moveRnTaskToFront() {
|
|
109
|
+
currentActivity?.let {
|
|
110
|
+
try {
|
|
111
|
+
val activityManager = reactContext
|
|
112
|
+
.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
|
113
|
+
activityManager.moveTaskToFront(it.taskId, 0)
|
|
114
|
+
} catch (e: Throwable) {
|
|
115
|
+
e.printStackTrace()
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@ReactMethod
|
|
121
|
+
override fun moveTaskToFront() {
|
|
122
|
+
WalletSdk.moveTaskToFront(reactContext)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@ReactMethod
|
|
126
|
+
override fun setSecurityQuestions(questionArr: ReadableArray) {
|
|
127
|
+
try {
|
|
128
|
+
val questions = BridgeHelper.getSecurityQuestions(questionArr)
|
|
129
|
+
setSecurityQuestions(questions)
|
|
130
|
+
} catch (e: Throwable) {
|
|
131
|
+
e.printStackTrace()
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@ReactMethod
|
|
136
|
+
override fun initSdk(configuration: ReadableMap, promise: Promise) {
|
|
137
|
+
try {
|
|
138
|
+
// Append ending slash if needed
|
|
139
|
+
val endpoint = configuration.getString("endpoint")?.run {
|
|
140
|
+
if (this.endsWith("/")) this else "$this/"
|
|
141
|
+
}
|
|
142
|
+
val appId = configuration.getString("appId")
|
|
143
|
+
val settings = BridgeHelper.getSettingsManagement(configuration)
|
|
144
|
+
WalletSdk.addEventListener(this)
|
|
145
|
+
init(
|
|
146
|
+
reactContext,
|
|
147
|
+
WalletSdk.Configuration(endpoint, appId, settings)
|
|
148
|
+
)
|
|
149
|
+
promise.resolve(Arguments.createMap())
|
|
150
|
+
} catch (e: Throwable) {
|
|
151
|
+
promise.reject(RuntimeException(e.message))
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@ReactMethod
|
|
156
|
+
override fun getDeviceId(): String {
|
|
157
|
+
return WalletSdk.getDeviceId(reactContext) ?: "123"
|
|
158
|
+
}
|
|
159
|
+
@ReactMethod
|
|
160
|
+
override fun execute(
|
|
161
|
+
userToken: String?,
|
|
162
|
+
secretKey: String?,
|
|
163
|
+
challengeIdArr: ReadableArray,
|
|
164
|
+
promise: Promise?
|
|
165
|
+
) {
|
|
166
|
+
val challengeIds = arrayOfNulls<String>(challengeIdArr.size())
|
|
167
|
+
for (i in challengeIds.indices) {
|
|
168
|
+
challengeIds[i] = challengeIdArr.getString(i)
|
|
169
|
+
}
|
|
170
|
+
execute(
|
|
171
|
+
currentActivity,
|
|
172
|
+
userToken,
|
|
173
|
+
secretKey,
|
|
174
|
+
challengeIds,
|
|
175
|
+
PromiseCallback(promise, reactContext)
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@ReactMethod
|
|
180
|
+
override fun executeWithUserSecret(
|
|
181
|
+
userToken: String?,
|
|
182
|
+
secretKey: String?,
|
|
183
|
+
userSecret: String?,
|
|
184
|
+
challengeIdArr: ReadableArray,
|
|
185
|
+
promise: Promise?
|
|
186
|
+
) {
|
|
187
|
+
val challengeIds = arrayOfNulls<String>(challengeIdArr.size())
|
|
188
|
+
for (i in challengeIds.indices) {
|
|
189
|
+
challengeIds[i] = challengeIdArr.getString(i)
|
|
190
|
+
}
|
|
191
|
+
executeWithUserSecret(
|
|
192
|
+
currentActivity,
|
|
193
|
+
userToken,
|
|
194
|
+
secretKey,
|
|
195
|
+
userSecret,
|
|
196
|
+
challengeIds,
|
|
197
|
+
PromiseCallback(promise, reactContext)
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
@ReactMethod
|
|
202
|
+
override fun setBiometricsPin(
|
|
203
|
+
userToken: String?,
|
|
204
|
+
secretKey: String?,
|
|
205
|
+
promise: Promise?
|
|
206
|
+
) {
|
|
207
|
+
WalletSdk.setBiometricsPin(
|
|
208
|
+
currentActivity,
|
|
209
|
+
userToken,
|
|
210
|
+
secretKey,
|
|
211
|
+
PromiseCallback(promise, reactContext)
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
companion object {
|
|
216
|
+
const val NAME = "ProgrammablewalletRnSdk"
|
|
217
|
+
const val EVENT_NAME_ON_EVENT = "CirclePwOnEvent"
|
|
218
|
+
const val EVENT_NAME_ON_SUCCESS = "CirclePwOnSuccess"
|
|
219
|
+
const val EVENT_NAME_ON_ERROR = "CirclePwOnError"
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
override fun onEvent(event: ExecuteEvent) {
|
|
223
|
+
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
224
|
+
.emit(EVENT_NAME_ON_EVENT, event.name)
|
|
225
|
+
}
|
|
226
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Copyright (c) 2024, Circle Technologies, LLC. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
package com.circlefin.programmablewalletrnsdk
|
|
15
|
+
|
|
16
|
+
import com.facebook.react.TurboReactPackage
|
|
17
|
+
import com.facebook.react.bridge.NativeModule
|
|
18
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
19
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
20
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
21
|
+
|
|
22
|
+
class ProgrammablewalletRnSdkPackage : TurboReactPackage() {
|
|
23
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
24
|
+
return if (name == ProgrammablewalletRnSdkModule.NAME) {
|
|
25
|
+
ProgrammablewalletRnSdkModule(reactContext)
|
|
26
|
+
} else {
|
|
27
|
+
null
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
32
|
+
return ReactModuleInfoProvider {
|
|
33
|
+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
34
|
+
val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
|
|
35
|
+
moduleInfos[ProgrammablewalletRnSdkModule.NAME] = ReactModuleInfo(
|
|
36
|
+
ProgrammablewalletRnSdkModule.NAME,
|
|
37
|
+
ProgrammablewalletRnSdkModule.NAME,
|
|
38
|
+
false, // canOverrideExistingModule
|
|
39
|
+
false, // needsEagerInit
|
|
40
|
+
true, // hasConstants
|
|
41
|
+
false, // isCxxModule
|
|
42
|
+
isTurboModule // isTurboModule
|
|
43
|
+
)
|
|
44
|
+
moduleInfos
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Copyright (c) 2024, Circle Technologies, LLC. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
package com.circlefin.programmablewalletrnsdk
|
|
15
|
+
|
|
16
|
+
import android.util.Log
|
|
17
|
+
import circle.programmablewallet.sdk.api.ApiError
|
|
18
|
+
import circle.programmablewallet.sdk.api.Callback
|
|
19
|
+
import circle.programmablewallet.sdk.api.ExecuteWarning
|
|
20
|
+
import com.circlefin.programmablewalletrnsdk.BridgeHelper.objectToMap
|
|
21
|
+
import com.facebook.react.bridge.Arguments
|
|
22
|
+
import com.facebook.react.bridge.Promise
|
|
23
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
24
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
25
|
+
|
|
26
|
+
class PromiseCallback<R> internal constructor(
|
|
27
|
+
private val promise: Promise?,
|
|
28
|
+
private val context: ReactApplicationContext
|
|
29
|
+
) : Callback<R> {
|
|
30
|
+
private var result: R? = null
|
|
31
|
+
override fun onError(error: Throwable): Boolean {
|
|
32
|
+
Log.w(TAG, "onError: ", error)
|
|
33
|
+
if (error is ApiError) {
|
|
34
|
+
val isDismiss = java.lang.Boolean.TRUE == dismissOnCallbackMap[error.code.value]
|
|
35
|
+
if (isDismiss) {
|
|
36
|
+
promise?.reject(error.code.value.toString(), error.message, error)
|
|
37
|
+
} else {
|
|
38
|
+
val map = objectToMap(error)
|
|
39
|
+
context.getJSModule(
|
|
40
|
+
DeviceEventManagerModule.RCTDeviceEventEmitter::class.java
|
|
41
|
+
)
|
|
42
|
+
.emit(ProgrammablewalletRnSdkModule.EVENT_NAME_ON_ERROR, map)
|
|
43
|
+
}
|
|
44
|
+
return !isDismiss
|
|
45
|
+
} else {
|
|
46
|
+
promise?.reject(RuntimeException(error.message))
|
|
47
|
+
}
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override fun onResult(result: R) {
|
|
52
|
+
promise ?: return
|
|
53
|
+
val map = Arguments.createMap()
|
|
54
|
+
map.putMap("result", objectToMap(result))
|
|
55
|
+
promise.resolve(map)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
override fun onWarning(warning: ExecuteWarning, result: R?): Boolean {
|
|
59
|
+
val isDismiss = java.lang.Boolean.TRUE == dismissOnCallbackMap[warning.warningType]
|
|
60
|
+
val map = Arguments.createMap()
|
|
61
|
+
if (result == null) {
|
|
62
|
+
map.putMap("result", objectToMap(this.result))
|
|
63
|
+
} else {
|
|
64
|
+
this.result = result
|
|
65
|
+
map.putMap("result", objectToMap(result))
|
|
66
|
+
}
|
|
67
|
+
map.putMap("warning", objectToMap(warning))
|
|
68
|
+
if (isDismiss) {
|
|
69
|
+
promise?.resolve(map)
|
|
70
|
+
} else {
|
|
71
|
+
context.getJSModule(
|
|
72
|
+
DeviceEventManagerModule.RCTDeviceEventEmitter::class.java
|
|
73
|
+
)
|
|
74
|
+
.emit(ProgrammablewalletRnSdkModule.EVENT_NAME_ON_SUCCESS, map)
|
|
75
|
+
}
|
|
76
|
+
return !isDismiss
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
companion object {
|
|
80
|
+
private val TAG = PromiseCallback::class.java.simpleName
|
|
81
|
+
val dismissOnCallbackMap: MutableMap<Int, Boolean> = HashMap()
|
|
82
|
+
fun setDismissOnCallbackMap(map: Map<Int, Boolean>) {
|
|
83
|
+
dismissOnCallbackMap.clear()
|
|
84
|
+
dismissOnCallbackMap.putAll(map)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright (c) 2024, Circle Technologies, LLC. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
package com.circlefin.programmablewalletrnsdk
|
|
15
|
+
|
|
16
|
+
import android.widget.ImageView
|
|
17
|
+
import androidx.appcompat.widget.Toolbar
|
|
18
|
+
|
|
19
|
+
object TestHelper {
|
|
20
|
+
private val TAG = TestHelper::class.java.simpleName
|
|
21
|
+
|
|
22
|
+
fun addTagForTest(iv: ImageView, tag: String) {
|
|
23
|
+
if (!BuildConfig.DEBUG) {
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
iv.tag = tag
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
fun addTagForTest(toolbar: Toolbar?, tag: String) {
|
|
30
|
+
if (!BuildConfig.DEBUG) {
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
toolbar?.tag = tag
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright (c) 2024, Circle Technologies, LLC. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
package com.circlefin.programmablewalletrnsdk.pwcustom
|
|
15
|
+
|
|
16
|
+
import android.widget.ImageView
|
|
17
|
+
import circle.programmablewallet.sdk.presentation.IImageViewSetter
|
|
18
|
+
import com.bumptech.glide.Glide
|
|
19
|
+
import com.circlefin.programmablewalletrnsdk.TestHelper
|
|
20
|
+
|
|
21
|
+
class RnImageSetter(val value: String?) : IImageViewSetter {
|
|
22
|
+
override fun apply(iv: ImageView?) {
|
|
23
|
+
try {
|
|
24
|
+
iv ?: return
|
|
25
|
+
value ?: return
|
|
26
|
+
val context = iv.context
|
|
27
|
+
if (value.startsWith("http")) {
|
|
28
|
+
Glide.with(context).load(value).centerCrop().into(iv)
|
|
29
|
+
TestHelper.addTagForTest(iv, value)
|
|
30
|
+
} else {
|
|
31
|
+
val resourceId =
|
|
32
|
+
context.resources.getIdentifier(value, "drawable", context.packageName)
|
|
33
|
+
iv.setImageResource(resourceId)
|
|
34
|
+
TestHelper.addTagForTest(iv, "$resourceId")
|
|
35
|
+
}
|
|
36
|
+
} catch (e: Exception) {
|
|
37
|
+
e.printStackTrace()
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
package/android/src/main/java/com/circlefin/programmablewalletrnsdk/pwcustom/RnLayoutProvider.kt
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Copyright (c) 2024, Circle Technologies, LLC. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
package com.circlefin.programmablewalletrnsdk.pwcustom
|
|
15
|
+
|
|
16
|
+
import circle.programmablewallet.sdk.api.ApiError
|
|
17
|
+
import circle.programmablewallet.sdk.presentation.IconTextConfig
|
|
18
|
+
import circle.programmablewallet.sdk.presentation.LayoutProvider
|
|
19
|
+
import circle.programmablewallet.sdk.presentation.Resource
|
|
20
|
+
import circle.programmablewallet.sdk.presentation.TextConfig
|
|
21
|
+
import java.util.Locale
|
|
22
|
+
|
|
23
|
+
object RnLayoutProvider : LayoutProvider() {
|
|
24
|
+
val textConfigsMap: MutableMap<String, Array<TextConfig?>> = HashMap()
|
|
25
|
+
val textConfigMap: MutableMap<String, TextConfig> = HashMap()
|
|
26
|
+
val iconTextsMap: MutableMap<Resource.IconTextsKey, Array<IconTextConfig?>> = HashMap()
|
|
27
|
+
val errorStringMap: MutableMap<Int, String> = HashMap()
|
|
28
|
+
var _dateFormat: String? = null
|
|
29
|
+
var _debugging = true
|
|
30
|
+
fun setTextConfigsMap(textConfigsMap: Map<String, Array<TextConfig?>>) {
|
|
31
|
+
this.textConfigsMap.clear()
|
|
32
|
+
this.textConfigsMap.putAll(textConfigsMap)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fun setErrorStringMap(errorStringMap: Map<Int, String>) {
|
|
36
|
+
this.errorStringMap.clear()
|
|
37
|
+
this.errorStringMap.putAll(errorStringMap)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fun setTextConfigMap(textConfigMap: Map<String, TextConfig>) {
|
|
41
|
+
this.textConfigMap.clear()
|
|
42
|
+
this.textConfigMap.putAll(textConfigMap)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
fun setIconTextConfigsMap(textConfigsMap: Map<Resource.IconTextsKey, Array<IconTextConfig?>>) {
|
|
46
|
+
iconTextsMap.clear()
|
|
47
|
+
iconTextsMap.putAll(textConfigsMap)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
fun setDateFormat(format: String?) {
|
|
51
|
+
format?.let {
|
|
52
|
+
_dateFormat = it.uppercase(Locale.getDefault())
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fun setDebugging(debugging: Boolean) {
|
|
57
|
+
this._debugging = debugging
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
override fun getTextConfig(key: String): TextConfig? {
|
|
61
|
+
return textConfigMap[key] ?: return super.getTextConfig(key)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
override fun getIconTextConfigs(key: Resource.IconTextsKey): Array<IconTextConfig?>? {
|
|
65
|
+
return iconTextsMap[key]
|
|
66
|
+
?: return super.getIconTextConfigs(key)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
override fun getTextConfigs(key: Resource.TextsKey): Array<TextConfig?>? {
|
|
70
|
+
return textConfigsMap[key.name] ?: return super.getTextConfigs(key)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
override fun getErrorString(code: ApiError.ErrorCode): String? {
|
|
74
|
+
return errorStringMap[code.value] ?: super.getErrorString(code)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
override fun getDateFormat(): String? {
|
|
78
|
+
return if (_dateFormat == null) {
|
|
79
|
+
super.getDateFormat()
|
|
80
|
+
} else _dateFormat
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
override fun isDebugging(): Boolean {
|
|
84
|
+
return _debugging
|
|
85
|
+
}
|
|
86
|
+
}
|
package/android/src/main/java/com/circlefin/programmablewalletrnsdk/pwcustom/RnViewSetterProvider.kt
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright (c) 2024, Circle Technologies, LLC. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
package com.circlefin.programmablewalletrnsdk.pwcustom
|
|
15
|
+
|
|
16
|
+
import android.graphics.drawable.Drawable
|
|
17
|
+
import androidx.appcompat.widget.Toolbar
|
|
18
|
+
import circle.programmablewallet.sdk.presentation.IImageViewSetter
|
|
19
|
+
import circle.programmablewallet.sdk.presentation.IToolbarSetter
|
|
20
|
+
import circle.programmablewallet.sdk.presentation.Resource
|
|
21
|
+
import circle.programmablewallet.sdk.presentation.ViewSetterProvider
|
|
22
|
+
import com.bumptech.glide.Glide
|
|
23
|
+
import com.bumptech.glide.request.target.CustomTarget
|
|
24
|
+
import com.bumptech.glide.request.transition.Transition
|
|
25
|
+
import com.circlefin.programmablewalletrnsdk.TestHelper
|
|
26
|
+
|
|
27
|
+
object RnViewSetterProvider : ViewSetterProvider() {
|
|
28
|
+
val map: MutableMap<String, String> = HashMap()
|
|
29
|
+
fun setMap(map: Map<String, String>) {
|
|
30
|
+
this.map.clear()
|
|
31
|
+
this.map.putAll(map)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override fun getImageSetter(icon: Resource.Icon): IImageViewSetter {
|
|
35
|
+
val key = String.format("%s", icon.name)
|
|
36
|
+
val value = map[key]
|
|
37
|
+
return RnImageSetter(value)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
override fun getToolbarImageSetter(toolbarIcon: Resource.ToolbarIcon): IToolbarSetter {
|
|
41
|
+
return object : IToolbarSetter {
|
|
42
|
+
override fun apply(toolbar: Toolbar?) {
|
|
43
|
+
try {
|
|
44
|
+
if (toolbar == null) {
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
val context = toolbar.context
|
|
48
|
+
val key = String.format("%s", toolbarIcon.name)
|
|
49
|
+
val value = map[key] ?: return
|
|
50
|
+
if (value.startsWith("http")) {
|
|
51
|
+
Glide.with(context).asDrawable().load(value)
|
|
52
|
+
.into(object : CustomTarget<Drawable?>() {
|
|
53
|
+
override fun onResourceReady(
|
|
54
|
+
resource: Drawable,
|
|
55
|
+
transition: Transition<in Drawable?>?
|
|
56
|
+
) {
|
|
57
|
+
toolbar.navigationIcon = resource
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
override fun onLoadCleared(placeholder: Drawable?) {}
|
|
61
|
+
})
|
|
62
|
+
TestHelper.addTagForTest(toolbar, value)
|
|
63
|
+
} else {
|
|
64
|
+
val resourceId =
|
|
65
|
+
context.resources.getIdentifier(value, "drawable", context.packageName)
|
|
66
|
+
toolbar.setNavigationIcon(resourceId)
|
|
67
|
+
TestHelper.addTagForTest(toolbar, "$resourceId")
|
|
68
|
+
}
|
|
69
|
+
} catch (e: Exception) {
|
|
70
|
+
e.printStackTrace()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright (c) 2024, Circle Technologies, LLC. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
package com.circlefin.programmablewalletrnsdk
|
|
15
|
+
|
|
16
|
+
import circle.programmablewallet.sdk.WalletSdk
|
|
17
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
18
|
+
|
|
19
|
+
abstract class ProgrammablewalletRnSdkSpec internal constructor(context: ReactApplicationContext) :
|
|
20
|
+
NativeProgrammablewalletRnSdkSpec(context) {
|
|
21
|
+
|
|
22
|
+
override fun getTypedExportedConstants(): MutableMap<String, Any> {
|
|
23
|
+
val constants: MutableMap<String, Any> = HashMap()
|
|
24
|
+
constants["sdkVersion"] = WalletSdk.sdkVersion()
|
|
25
|
+
return constants
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Copyright (c) 2024, Circle Technologies, LLC. All rights reserved.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
package com.circlefin.programmablewalletrnsdk
|
|
15
|
+
|
|
16
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
17
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
18
|
+
import com.facebook.react.bridge.Promise
|
|
19
|
+
import com.facebook.react.bridge.ReadableArray
|
|
20
|
+
import com.facebook.react.bridge.ReadableMap
|
|
21
|
+
import circle.programmablewallet.sdk.WalletSdk
|
|
22
|
+
|
|
23
|
+
abstract class ProgrammablewalletRnSdkSpec internal constructor(val context: ReactApplicationContext) :
|
|
24
|
+
ReactContextBaseJavaModule(context) {
|
|
25
|
+
|
|
26
|
+
abstract fun initSdk(configuration: ReadableMap, promise: Promise)
|
|
27
|
+
abstract fun setSecurityQuestions(questionArr: ReadableArray)
|
|
28
|
+
abstract fun getDeviceId(): String
|
|
29
|
+
abstract fun execute(
|
|
30
|
+
userToken: String?,
|
|
31
|
+
secretKey: String?,
|
|
32
|
+
challengeIdArr: ReadableArray,
|
|
33
|
+
promise: Promise?
|
|
34
|
+
)
|
|
35
|
+
abstract fun executeWithUserSecret(
|
|
36
|
+
userToken: String?,
|
|
37
|
+
secretKey: String?,
|
|
38
|
+
userSecret: String?,
|
|
39
|
+
challengeIdArr: ReadableArray,
|
|
40
|
+
promise: Promise?
|
|
41
|
+
)
|
|
42
|
+
abstract fun setBiometricsPin(
|
|
43
|
+
userToken: String?,
|
|
44
|
+
secretKey: String?,
|
|
45
|
+
promise: Promise?
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
abstract fun setDismissOnCallbackMap(readableMap: ReadableMap)
|
|
49
|
+
abstract fun moveTaskToFront()
|
|
50
|
+
abstract fun moveRnTaskToFront()
|
|
51
|
+
abstract fun setTextConfigsMap(readableMap: ReadableMap)
|
|
52
|
+
abstract fun setIconTextConfigsMap(readableMap: ReadableMap)
|
|
53
|
+
abstract fun setTextConfigMap(readableMap: ReadableMap)
|
|
54
|
+
abstract fun setImageMap(readableMap: ReadableMap)
|
|
55
|
+
abstract fun setDateFormat(value: String)
|
|
56
|
+
abstract fun setDebugging(value: Boolean)
|
|
57
|
+
abstract fun setCustomUserAgent(value: String)
|
|
58
|
+
abstract fun setErrorStringMap(readableMap: ReadableMap)
|
|
59
|
+
override fun getConstants(): MutableMap<String, Any> {
|
|
60
|
+
val constants: MutableMap<String, Any> = HashMap()
|
|
61
|
+
constants["sdkVersion"] = WalletSdk.sdkVersion()
|
|
62
|
+
constants["deviceId"] = WalletSdk.getDeviceId(context) ?: ""
|
|
63
|
+
return constants
|
|
64
|
+
}
|
|
65
|
+
}
|