Skip to content

Commit bc365b4

Browse files
committed
Avoid unscoped coroutine leakage in getSecureWalletInfo() (cancel on invalidate)
(cherry picked from commit 4f2c4cecc238a4e66df4d74829bd53abf98b2839)
1 parent a17cde7 commit bc365b4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import com.google.android.gms.tapandpay.issuer.PushTokenizeRequest
2121
import kotlinx.coroutines.CoroutineScope
2222
import kotlinx.coroutines.Dispatchers
2323
import kotlinx.coroutines.launch
24+
import kotlinx.coroutines.SupervisorJob
25+
import kotlinx.coroutines.cancel
2426
import com.expensify.wallet.Utils.getAsyncResult
2527
import com.expensify.wallet.Utils.toCardData
2628
import com.expensify.wallet.error.InvalidNetworkError
@@ -50,6 +52,7 @@ class WalletModule internal constructor(context: ReactApplicationContext) :
5052
private val tapAndPayClient: TapAndPayClient = TapAndPay.getClient(activity)
5153
private var pendingCreateWalletPromise: Promise? = null
5254
private var pendingPushTokenizePromise: Promise? = null
55+
private val moduleScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
5356

5457
override fun initialize() {
5558
super.initialize()
@@ -58,6 +61,7 @@ class WalletModule internal constructor(context: ReactApplicationContext) :
5861

5962
override fun invalidate() {
6063
super.invalidate()
64+
moduleScope.cancel()
6165
reactApplicationContext.removeActivityEventListener(cardListener)
6266
}
6367

@@ -119,7 +123,7 @@ class WalletModule internal constructor(context: ReactApplicationContext) :
119123

120124
@ReactMethod
121125
override fun getSecureWalletInfo(promise: Promise) {
122-
CoroutineScope(Dispatchers.Main).launch {
126+
moduleScope.launch {
123127
try {
124128
val walletId = getWalletIdAsync()
125129
val hardwareId = getHardwareIdAsync()

0 commit comments

Comments
 (0)