Skip to content

Commit c5820a2

Browse files
committed
onActivityResult can hang forever if OK but data == null, and pending promise is not cleared
(cherry picked from commit a330c1ee2261f192103ac4e7a2fa5d86e2c59b7f)
1 parent a17cde7 commit c5820a2

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

android/src/main/java/com/expensify/wallet/WalletModule.kt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,29 @@ class WalletModule internal constructor(context: ReactApplicationContext) :
6969
pendingCreateWalletPromise?.resolve(resultCode == RESULT_OK)
7070
pendingCreateWalletPromise = null
7171
} else if (requestCode == REQUEST_CODE_PUSH_TOKENIZE) {
72+
val localPromise = pendingPushTokenizePromise
73+
pendingPushTokenizePromise = null
7274
if (resultCode == RESULT_OK) {
73-
data?.let {
74-
val tokenId = it.getStringExtra(TapAndPay.EXTRA_ISSUER_TOKEN_ID).toString()
75-
sendEvent(
76-
context,
77-
OnCardActivatedEvent.NAME,
78-
OnCardActivatedEvent("active", tokenId).toMap()
79-
)
80-
pendingPushTokenizePromise?.resolve(TokenizationStatus.SUCCESS.code)
75+
if (data == null) {
76+
localPromise?.reject(E_OPERATION_FAILED, "Tokenization returned RESULT_OK but intent data was null")
77+
return
8178
}
79+
val tokenId = data.getStringExtra(TapAndPay.EXTRA_ISSUER_TOKEN_ID).toString()
80+
sendEvent(
81+
context,
82+
OnCardActivatedEvent.NAME,
83+
OnCardActivatedEvent("active", tokenId).toMap()
84+
)
85+
localPromise?.resolve(TokenizationStatus.SUCCESS.code)
8286
} else if (resultCode == RESULT_CANCELED) {
8387
sendEvent(
8488
context,
8589
OnCardActivatedEvent.NAME,
8690
OnCardActivatedEvent("canceled", null).toMap()
8791
)
88-
pendingPushTokenizePromise?.resolve(TokenizationStatus.CANCELED.code)
92+
localPromise?.resolve(TokenizationStatus.CANCELED.code)
93+
} else {
94+
localPromise?.reject(E_OPERATION_FAILED, "Tokenization failed with resultCode=$resultCode")
8995
}
9096
}
9197
}

0 commit comments

Comments
 (0)