diff --git a/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt b/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt index e4bf1086bd..2712e8375d 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt @@ -4,6 +4,7 @@ import com.tangem.blockchain.common.AmountType import com.tangem.domain.feedback.models.BlockchainErrorInfo import com.tangem.domain.redux.LegacyAction import com.tangem.domain.utils.convertToSdkAmount +import com.tangem.tap.common.extensions.dispatchWithMain import com.tangem.tap.common.extensions.inject import com.tangem.tap.common.extensions.stripZeroPlainString import com.tangem.tap.common.feedback.FeedbackEmail @@ -11,13 +12,23 @@ import com.tangem.tap.common.feedback.RateCanBeBetterEmail import com.tangem.tap.common.feedback.SendTransactionFailedEmail import com.tangem.tap.common.redux.AppState import com.tangem.tap.common.redux.global.GlobalAction +import com.tangem.tap.features.details.redux.DetailsAction import com.tangem.tap.proxy.redux.DaggerGraphState import com.tangem.tap.scope import com.tangem.tap.store +import com.tangem.utils.coroutines.JobHolder +import com.tangem.utils.coroutines.saveIn +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import org.rekotlin.Middleware internal object LegacyMiddleware { + private val prepareDetailsScreenJobHolder = JobHolder() + val legacyMiddleware: Middleware = { _, _ -> { next -> { action -> @@ -85,6 +96,24 @@ internal object LegacyMiddleware { } } } + is LegacyAction.PrepareDetailsScreen -> { + val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager) + val walletsRepository = store.inject(DaggerGraphState::walletsRepository) + + userWalletsListManager.selectedUserWallet + .distinctUntilChanged() + .onEach { selectedUserWallet -> + store.dispatchWithMain( + DetailsAction.PrepareScreen( + scanResponse = selectedUserWallet.scanResponse, + shouldSaveUserWallets = walletsRepository.shouldSaveUserWalletsSync(), + ), + ) + } + .flowOn(Dispatchers.IO) + .launchIn(scope) + .saveIn(prepareDetailsScreenJobHolder) + } } next(action) } diff --git a/domain/legacy/src/main/java/com/tangem/domain/redux/LegacyAction.kt b/domain/legacy/src/main/java/com/tangem/domain/redux/LegacyAction.kt index ab0183d09e..29003a8330 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/redux/LegacyAction.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/redux/LegacyAction.kt @@ -38,4 +38,6 @@ sealed interface LegacyAction : Action { val errorMessage: String, val scanResponse: ScanResponse, ) : LegacyAction + + data object PrepareDetailsScreen : LegacyAction } \ No newline at end of file diff --git a/features/details/impl/src/main/kotlin/com/tangem/features/details/model/DetailsModel.kt b/features/details/impl/src/main/kotlin/com/tangem/features/details/model/DetailsModel.kt index 884ee4f78a..9903c588e9 100644 --- a/features/details/impl/src/main/kotlin/com/tangem/features/details/model/DetailsModel.kt +++ b/features/details/impl/src/main/kotlin/com/tangem/features/details/model/DetailsModel.kt @@ -61,6 +61,9 @@ internal class DetailsModel @Inject constructor( ) init { + // Use to save compatibility with screens that using Redux states + bootstrapScreenState() + items .onEach(::updateState) .launchIn(modelScope) @@ -82,6 +85,10 @@ internal class DetailsModel @Inject constructor( ) } + private fun bootstrapScreenState() { + appStateHolder.dispatch(LegacyAction.PrepareDetailsScreen) + } + private fun sendFeedback() { modelScope.launch { val scanResponse = getSelectedWalletSyncUseCase().getOrNull()?.scanResponse