diff --git a/app/src/main/java/com/tangem/tap/MainActivity.kt b/app/src/main/java/com/tangem/tap/MainActivity.kt index 60676fa1f7..27403d8cd3 100644 --- a/app/src/main/java/com/tangem/tap/MainActivity.kt +++ b/app/src/main/java/com/tangem/tap/MainActivity.kt @@ -108,11 +108,11 @@ internal var lockUserWalletsTimer: LockUserWalletsTimer? = null var notificationsHandler: NotificationsHandler? = null private val coroutineContext: CoroutineContext - get() = Job() + Dispatchers.IO + FeatureCoroutineExceptionHandler.create("scope") + get() = SupervisorJob() + Dispatchers.IO + FeatureCoroutineExceptionHandler.create("scope") val scope = CoroutineScope(coroutineContext) private val mainCoroutineContext: CoroutineContext - get() = Job() + Dispatchers.Main + FeatureCoroutineExceptionHandler.create("mainScope") + get() = SupervisorJob() + Dispatchers.Main + FeatureCoroutineExceptionHandler.create("mainScope") val mainScope = CoroutineScope(mainCoroutineContext) @Suppress("LargeClass") diff --git a/app/src/main/java/com/tangem/tap/features/welcome/model/WelcomeModel.kt b/app/src/main/java/com/tangem/tap/features/welcome/model/WelcomeModel.kt index 7d15881d39..45fc140480 100644 --- a/app/src/main/java/com/tangem/tap/features/welcome/model/WelcomeModel.kt +++ b/app/src/main/java/com/tangem/tap/features/welcome/model/WelcomeModel.kt @@ -15,7 +15,6 @@ import com.tangem.tap.features.welcome.redux.WelcomeAction import com.tangem.tap.features.welcome.redux.WelcomeState import com.tangem.tap.features.welcome.ui.WelcomeScreenState import com.tangem.tap.features.welcome.ui.model.WarningModel -import com.tangem.tap.mainScope import com.tangem.tap.store import com.tangem.utils.coroutines.CoroutineDispatcherProvider import kotlinx.coroutines.flow.MutableStateFlow @@ -42,8 +41,6 @@ internal class WelcomeModel @Inject constructor( val state: MutableStateFlow = MutableStateFlow(initialState) init { - store.dispatch(WelcomeAction.SetCoroutineScope(mainScope)) - subscribeToStoreChanges() initGlobalState() @@ -89,7 +86,6 @@ internal class WelcomeModel @Inject constructor( } override fun onDestroy() { - store.dispatch(WelcomeAction.ClearCoroutineScope) store.unsubscribe(subscriber = this) super.onDestroy() diff --git a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeAction.kt b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeAction.kt index fbae455ce2..bd88693c6b 100644 --- a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeAction.kt +++ b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeAction.kt @@ -2,15 +2,10 @@ package com.tangem.tap.features.welcome.redux import android.content.Intent import com.tangem.common.core.TangemError -import kotlinx.coroutines.CoroutineScope import org.rekotlin.Action internal sealed interface WelcomeAction : Action { - data class SetCoroutineScope(val scope: CoroutineScope) : WelcomeAction - - object ClearCoroutineScope : WelcomeAction - data class ProceedWithBiometrics(val afterUnlockIntent: Intent? = null) : WelcomeAction { object Success : WelcomeAction data class Error(val error: TangemError) : WelcomeAction diff --git a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeMiddleware.kt b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeMiddleware.kt index b9f8660cf1..2c0548f38d 100644 --- a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeMiddleware.kt @@ -23,6 +23,7 @@ import com.tangem.tap.common.extensions.* import com.tangem.tap.common.redux.AppState import com.tangem.tap.features.intentHandler.handlers.BackgroundScanIntentHandler import com.tangem.tap.features.intentHandler.handlers.WalletConnectLinkIntentHandler +import com.tangem.tap.mainScope import com.tangem.tap.proxy.redux.DaggerGraphState import com.tangem.tap.scope import com.tangem.tap.store @@ -46,7 +47,7 @@ internal class WelcomeMiddleware { } private fun handleAction(action: WelcomeAction, state: WelcomeState) { - state.scope?.launch { + mainScope.launch { when (action) { is WelcomeAction.ProceedWithIntent -> proceedWithIntent(action.intent, scope = this) is WelcomeAction.ProceedWithBiometrics -> proceedWithBiometrics( diff --git a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeReducer.kt b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeReducer.kt index 35f81371fa..1f475f9a80 100644 --- a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeReducer.kt +++ b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeReducer.kt @@ -14,8 +14,6 @@ internal object WelcomeReducer { private fun internalReduce(action: WelcomeAction, state: WelcomeState): WelcomeState { return when (action) { - is WelcomeAction.SetCoroutineScope -> state.copy(scope = action.scope) - is WelcomeAction.ClearCoroutineScope -> state.copy(scope = null) is WelcomeAction.ProceedWithIntent -> state.copy(intent = action.intent) is WelcomeAction.ProceedWithBiometrics -> state.copy(isUnlockWithBiometricsInProgress = true) is WelcomeAction.ProceedWithCard -> state.copy(isUnlockWithCardInProgress = true) diff --git a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeState.kt b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeState.kt index 951fa1e673..a8a55d3984 100644 --- a/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeState.kt +++ b/app/src/main/java/com/tangem/tap/features/welcome/redux/WelcomeState.kt @@ -2,11 +2,9 @@ package com.tangem.tap.features.welcome.redux import android.content.Intent import com.tangem.common.core.TangemError -import kotlinx.coroutines.CoroutineScope import org.rekotlin.StateType data class WelcomeState( - val scope: CoroutineScope? = null, val isUnlockWithBiometricsInProgress: Boolean = false, val isUnlockWithCardInProgress: Boolean = false, val intent: Intent? = null,