@expensify/react-native-wallet 0.1.36 → 0.1.38

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.
@@ -1,8 +1,8 @@
1
1
  package com.expensify.wallet
2
2
 
3
3
  import com.facebook.react.bridge.Promise
4
+ import com.facebook.react.bridge.PromiseImpl
4
5
  import com.facebook.react.bridge.ReadableMap
5
- import com.facebook.react.bridge.WritableMap
6
6
  import com.google.android.gms.tapandpay.issuer.UserAddress
7
7
  import com.expensify.wallet.model.CardData
8
8
  import kotlinx.coroutines.Deferred
@@ -45,100 +45,23 @@ object Utils {
45
45
  async {
46
46
  withContext(Dispatchers.IO) {
47
47
  suspendCancellableCoroutine { continuation ->
48
- val promise = object : Promise {
49
- @Deprecated(
50
- "Prefer passing a module-specific error code to JS. Using this method will pass the error code UNSPECIFIED",
51
- replaceWith = ReplaceWith("reject(code, message)")
52
- )
53
- override fun reject(message: String) {
54
- continuation.resumeWithException(
55
- Exception("Error: $message")
56
- )
57
- }
58
-
59
- override fun reject(code: String?, userInfo: WritableMap) {
60
- val errorMessage = "Error: ${code ?: "Unknown code"}\nUserInfo: $userInfo"
61
- continuation.resumeWithException(
62
- Exception(errorMessage)
63
- )
64
- }
65
-
66
- override fun reject(code: String?, message: String?) {
67
- val errorMessage = "Error: ${code ?: "Unknown code"}\nMessage: ${message ?: "No message provided"}"
68
- continuation.resumeWithException(
69
- Exception(errorMessage)
70
- )
71
- }
72
-
73
- override fun reject(code: String?, message: String?, userInfo: WritableMap) {
74
- val errorMessage =
75
- "Error: ${code ?: "Unknown code"}\nMessage: ${message ?: "No message provided"}\nUserInfo: $userInfo"
76
- continuation.resumeWithException(
77
- Exception(errorMessage)
78
- )
79
- }
80
-
81
- override fun reject(code: String?, message: String?, throwable: Throwable?) {
82
- val errorMessage = "Error: ${code ?: "Unknown code"}\nMessage: ${message ?: "No message provided"}"
83
- continuation.resumeWithException(
84
- throwable ?: Exception(errorMessage)
85
- )
86
- }
87
-
88
- override fun reject(code: String?, throwable: Throwable?) {
89
- val errorMessage = "Error: ${code ?: "Unknown code"}"
48
+ val promise = PromiseImpl({ args ->
49
+ val value = args.getOrNull(0)
50
+ if (resultType.isInstance(value)) {
51
+ continuation.resume(value as String)
52
+ } else {
90
53
  continuation.resumeWithException(
91
- throwable ?: Exception(errorMessage)
54
+ RuntimeException("Expected result of type ${resultType.simpleName}, but got ${value?.javaClass?.simpleName}")
92
55
  )
93
56
  }
94
-
95
- override fun reject(code: String?, throwable: Throwable?, userInfo: WritableMap) {
96
- val errorMessage = "Error: ${code ?: "Unknown code"}\nUserInfo: $userInfo"
97
- continuation.resumeWithException(
98
- throwable ?: Exception(errorMessage)
99
- )
100
- }
101
-
102
- override fun reject(
103
- code: String?,
104
- message: String?,
105
- throwable: Throwable?,
106
- userInfo: WritableMap?
107
- ) {
108
- val errorMessage = buildString {
109
- append("Error: ${code ?: "Unknown code"}")
110
- if (message != null) append("\nMessage: $message")
111
- if (userInfo != null) append("\nUserInfo: $userInfo")
112
- }
113
- continuation.resumeWithException(
114
- throwable ?: Exception(errorMessage)
115
- )
116
- }
117
-
118
- override fun reject(throwable: Throwable) {
119
- continuation.resumeWithException(
120
- throwable
121
- )
122
- }
123
-
124
- override fun reject(throwable: Throwable, userInfo: WritableMap) {
125
- val errorMessage = "Exception occurred\nUserInfo: $userInfo"
126
- continuation.resumeWithException(
127
- Exception(errorMessage, throwable)
128
- )
129
- }
130
-
131
- override fun resolve(value: Any?) {
132
- if (resultType.isInstance(value)) {
133
- continuation.resume(value as String)
134
- } else {
135
- continuation.resumeWithException(
136
- RuntimeException("Expected result of type ${resultType.simpleName}, but got ${value?.javaClass?.simpleName}")
137
- )
138
- }
139
- }
140
-
141
- }
57
+ }, { args ->
58
+ val error = args.getOrNull(0) as? ReadableMap
59
+ val code = error?.getString("code") ?: "Unknown code"
60
+ val message = error?.getString("message") ?: "No message provided"
61
+ continuation.resumeWithException(
62
+ Exception("Error: $code\nMessage: $message")
63
+ )
64
+ })
142
65
  getPromiseOperation(promise)
143
66
  }
144
67
  }
@@ -76,6 +76,8 @@ class WalletModule internal constructor(context: ReactApplicationContext) :
76
76
  pendingCreateWalletPromise?.resolve(resultCode == RESULT_OK)
77
77
  pendingCreateWalletPromise = null
78
78
  } else if (requestCode == REQUEST_CODE_PUSH_TOKENIZE) {
79
+ val localPromise = pendingPushTokenizePromise
80
+ pendingPushTokenizePromise = null
79
81
  if (resultCode == RESULT_OK) {
80
82
  data?.let {
81
83
  val tokenId = it.getStringExtra(TapAndPay.EXTRA_ISSUER_TOKEN_ID).toString()
@@ -84,7 +86,7 @@ class WalletModule internal constructor(context: ReactApplicationContext) :
84
86
  OnCardActivatedEvent.NAME,
85
87
  OnCardActivatedEvent("activated", tokenId).toMap()
86
88
  )
87
- pendingPushTokenizePromise?.resolve(TokenizationStatus.SUCCESS.code)
89
+ localPromise?.resolve(TokenizationStatus.SUCCESS.code)
88
90
  }
89
91
  } else if (resultCode == RESULT_CANCELED) {
90
92
  sendEvent(
@@ -92,7 +94,7 @@ class WalletModule internal constructor(context: ReactApplicationContext) :
92
94
  OnCardActivatedEvent.NAME,
93
95
  OnCardActivatedEvent("canceled", null).toMap()
94
96
  )
95
- pendingPushTokenizePromise?.resolve(TokenizationStatus.CANCELED.code)
97
+ localPromise?.resolve(TokenizationStatus.CANCELED.code)
96
98
  }
97
99
  }
98
100
  }
@@ -185,6 +187,9 @@ class WalletModule internal constructor(context: ReactApplicationContext) :
185
187
  override fun addCardToGoogleWallet(
186
188
  data: ReadableMap, promise: Promise
187
189
  ) {
190
+ if (pendingPushTokenizePromise != null) {
191
+ return promise.reject(E_OPERATION_FAILED, "A tokenization request is already in progress")
192
+ }
188
193
  try {
189
194
  val cardData = data.toCardData() ?: return promise.reject(E_INVALID_DATA, "Insufficient data")
190
195
  val cardNetwork = getCardNetwork(cardData.network)
@@ -205,12 +210,16 @@ class WalletModule internal constructor(context: ReactApplicationContext) :
205
210
  activity, pushTokenizeRequest, REQUEST_CODE_PUSH_TOKENIZE
206
211
  )
207
212
  } catch (e: java.lang.Exception) {
213
+ pendingPushTokenizePromise = null
208
214
  promise.reject(e)
209
215
  }
210
216
  }
211
217
 
212
218
  @ReactMethod
213
219
  override fun resumeAddCardToGoogleWallet(data: ReadableMap, promise: Promise) {
220
+ if (pendingPushTokenizePromise != null) {
221
+ return promise.reject(E_OPERATION_FAILED, "A tokenization request is already in progress")
222
+ }
214
223
  try {
215
224
  val tokenReferenceID = data.getString("tokenReferenceID")
216
225
  ?: return promise.reject(E_INVALID_DATA, "Missing tokenReferenceID")
@@ -232,6 +241,7 @@ class WalletModule internal constructor(context: ReactApplicationContext) :
232
241
  REQUEST_CODE_PUSH_TOKENIZE
233
242
  )
234
243
  } catch (e: java.lang.Exception) {
244
+ pendingPushTokenizePromise = null
235
245
  promise.reject(e)
236
246
  }
237
247
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expensify/react-native-wallet",
3
- "version": "0.1.36",
3
+ "version": "0.1.38",
4
4
  "description": "A React Native module designed for seamless integration of Card Push Provisioning into Apple Wallet and Google Wallet, enabling easy and secure addition of payment cards directly from your application.",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "lib/commonjs/index",