Updated on 2026-08-14

This commit is contained in:
Tangem 2024-09-20 12:27:29 +03:00
parent 3ebfda2513
commit 48f8f9e2ee
3 changed files with 38 additions and 0 deletions

View file

@ -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<AppState> = { _, _ ->
{ 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)
}

View file

@ -38,4 +38,6 @@ sealed interface LegacyAction : Action {
val errorMessage: String,
val scanResponse: ScanResponse,
) : LegacyAction
data object PrepareDetailsScreen : LegacyAction
}

View file

@ -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