Updated on 2026-08-14

This commit is contained in:
Tangem 2026-01-22 17:05:04 +03:00
commit 21ae19f625
938 changed files with 40685 additions and 7487 deletions

View file

@ -0,0 +1,17 @@
package com.tangem.features.yield.supply.api
import com.tangem.core.decompose.factory.ComponentFactory
import com.tangem.core.ui.decompose.ComposableContentComponent
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.wallet.UserWalletId
interface YieldSupplyEntryComponent : ComposableContentComponent {
data class Params(
val userWalletId: UserWalletId,
val cryptoCurrency: CryptoCurrency,
val apy: String,
)
interface Factory : ComponentFactory<Params, YieldSupplyEntryComponent>
}

View file

@ -3,4 +3,5 @@ package com.tangem.features.yield.supply.api
interface YieldSupplyFeatureToggles {
val isYieldSupplyFeatureEnabled: Boolean
val isYieldSupplyPendingTransactionsEnabled: Boolean
}

View file

@ -0,0 +1,24 @@
package com.tangem.features.yield.supply.api.entry
import com.tangem.core.decompose.navigation.Route
import com.tangem.domain.models.currency.CryptoCurrency
/**
* Route for switching yield supply promo and active flows.
*/
sealed class YieldSupplyEntryRoute : Route {
/** Initial empty route with no UI */
data object Empty : YieldSupplyEntryRoute()
/** Route to yield supply promo screen */
data class Promo(
val cryptoCurrency: CryptoCurrency,
val apy: String,
) : YieldSupplyEntryRoute()
/** Route to yield supply active screen */
data class Active(
val cryptoCurrency: CryptoCurrency,
) : YieldSupplyEntryRoute()
}

View file

@ -8,4 +8,7 @@ internal class DefaultYieldSupplyFeatureToggles(
) : YieldSupplyFeatureToggles {
override val isYieldSupplyFeatureEnabled: Boolean
get() = featureToggles.isFeatureEnabled("YIELD_SUPPLY_FEATURE_ENABLED")
override val isYieldSupplyPendingTransactionsEnabled: Boolean
get() = featureToggles.isFeatureEnabled("YIELD_SUPPLY_PENDING_TRANSACTIONS_ENABLED")
}

View file

@ -0,0 +1,124 @@
package com.tangem.features.yield.supply.impl.entry
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import com.arkivanov.decompose.extensions.compose.stack.Children
import com.arkivanov.decompose.extensions.compose.stack.animation.fade
import com.arkivanov.decompose.extensions.compose.stack.animation.stackAnimation
import com.arkivanov.decompose.extensions.compose.subscribeAsState
import com.arkivanov.decompose.router.stack.StackNavigation
import com.arkivanov.decompose.router.stack.childStack
import com.arkivanov.decompose.router.stack.pop
import com.tangem.core.decompose.context.AppComponentContext
import com.tangem.core.decompose.context.childByContext
import com.tangem.core.decompose.model.getOrCreateModel
import com.tangem.core.decompose.navigation.inner.InnerRouter
import com.tangem.core.ui.decompose.ComposableContentComponent
import com.tangem.features.yield.supply.api.YieldSupplyActiveComponent
import com.tangem.features.yield.supply.api.YieldSupplyEntryComponent
import com.tangem.features.yield.supply.api.YieldSupplyPromoComponent
import com.tangem.features.yield.supply.api.entry.YieldSupplyEntryRoute
import com.tangem.features.yield.supply.impl.entry.model.YieldSupplyEntryModel
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
internal class DefaultYieldSupplyEntryComponent @AssistedInject constructor(
@Assisted appComponentContext: AppComponentContext,
@Assisted private val params: YieldSupplyEntryComponent.Params,
private val yieldSupplyPromoComponentFactory: YieldSupplyPromoComponent.Factory,
private val yieldSupplyActiveComponentFactory: YieldSupplyActiveComponent.Factory,
) : YieldSupplyEntryComponent, AppComponentContext by appComponentContext {
private val stackNavigation = StackNavigation<YieldSupplyEntryRoute>()
private val innerRouter = InnerRouter<YieldSupplyEntryRoute>(
stackNavigation = stackNavigation,
popCallback = { onChildBack() },
)
private val model: YieldSupplyEntryModel = getOrCreateModel(
params = params,
router = innerRouter,
)
private val childStack = childStack(
key = "yieldSupplyEntryStack",
source = stackNavigation,
serializer = null,
initialConfiguration = model.initialRoute,
handleBackButton = true,
childFactory = { configuration, factoryContext ->
getChildComponent(
configuration = configuration,
factoryContext = childByContext(
componentContext = factoryContext,
router = innerRouter,
),
)
},
)
@Composable
override fun Content(modifier: Modifier) {
val childStackValue by childStack.subscribeAsState()
Children(
stack = childStackValue,
modifier = modifier,
animation = stackAnimation { fade() },
) { child ->
child.instance.Content(Modifier.fillMaxSize())
}
}
private fun getChildComponent(
configuration: YieldSupplyEntryRoute,
factoryContext: AppComponentContext,
): ComposableContentComponent = when (configuration) {
is YieldSupplyEntryRoute.Empty -> EmptyComponent
is YieldSupplyEntryRoute.Promo -> yieldSupplyPromoComponentFactory.create(
context = factoryContext,
params = YieldSupplyPromoComponent.Params(
userWalletId = params.userWalletId,
currency = configuration.cryptoCurrency,
apy = configuration.apy,
),
)
is YieldSupplyEntryRoute.Active -> yieldSupplyActiveComponentFactory.create(
context = factoryContext,
params = YieldSupplyActiveComponent.Params(
userWalletId = params.userWalletId,
cryptoCurrency = configuration.cryptoCurrency,
),
)
}
private object EmptyComponent : ComposableContentComponent {
@Composable
override fun Content(modifier: Modifier) {
Box(modifier = modifier)
}
}
private fun onChildBack() {
if (childStack.value.backStack.isEmpty() ||
childStack.value.backStack.last().configuration is YieldSupplyEntryRoute.Empty
) {
router.pop()
} else {
stackNavigation.pop()
}
}
@AssistedFactory
interface Factory : YieldSupplyEntryComponent.Factory {
override fun create(
context: AppComponentContext,
params: YieldSupplyEntryComponent.Params,
): DefaultYieldSupplyEntryComponent
}
}

View file

@ -0,0 +1,34 @@
package com.tangem.features.yield.supply.impl.entry.di
import com.tangem.core.decompose.di.ModelComponent
import com.tangem.core.decompose.model.Model
import com.tangem.features.yield.supply.api.YieldSupplyEntryComponent
import com.tangem.features.yield.supply.impl.entry.DefaultYieldSupplyEntryComponent
import com.tangem.features.yield.supply.impl.entry.model.YieldSupplyEntryModel
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import dagger.multibindings.ClassKey
import dagger.multibindings.IntoMap
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
internal interface YieldSupplyEntryBindsModule {
@Binds
@Singleton
fun provideYieldSupplyEntryComponentFactory(
impl: DefaultYieldSupplyEntryComponent.Factory,
): YieldSupplyEntryComponent.Factory
}
@Module
@InstallIn(ModelComponent::class)
internal interface YieldSupplyEntryModelModule {
@Binds
@IntoMap
@ClassKey(YieldSupplyEntryModel::class)
fun provideYieldSupplyEntryModel(impl: YieldSupplyEntryModel): Model
}

View file

@ -0,0 +1,90 @@
package com.tangem.features.yield.supply.impl.entry.model
import com.tangem.common.routing.AppRoute
import com.tangem.core.decompose.di.ModelScoped
import com.tangem.core.decompose.model.Model
import com.tangem.core.decompose.model.ParamsContainer
import com.tangem.core.decompose.navigation.Router
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.model.details.NavigationAction
import com.tangem.domain.yield.supply.usecase.YieldSupplyEnterStatusUseCase
import com.tangem.features.yield.supply.api.YieldSupplyEntryComponent
import com.tangem.features.yield.supply.api.entry.YieldSupplyEntryRoute
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject
@ModelScoped
internal class YieldSupplyEntryModel @Inject constructor(
paramsContainer: ParamsContainer,
override val dispatchers: CoroutineDispatcherProvider,
private val router: Router,
private val yieldSupplyEnterStatusUseCase: YieldSupplyEnterStatusUseCase,
private val getSingleCryptoCurrencyStatusUseCase: GetSingleCryptoCurrencyStatusUseCase,
) : Model() {
private val params = paramsContainer.require<YieldSupplyEntryComponent.Params>()
val initialRoute: YieldSupplyEntryRoute = YieldSupplyEntryRoute.Empty
init {
navigateToInitialRoute()
}
private fun navigateToInitialRoute() {
val userWalletId = params.userWalletId
val cryptoCurrency = params.cryptoCurrency
modelScope.launch(dispatchers.default) {
getSingleCryptoCurrencyStatusUseCase.invokeMultiWalletSync(
userWalletId = userWalletId,
cryptoCurrencyId = cryptoCurrency.id,
).onLeft { error ->
Timber.e("Failed to get CryptoCurrencyStatus: $error")
router.pop()
}.onRight { cryptoCurrencyStatus ->
val route = getInitialRoute(cryptoCurrencyStatus)
if (route != null) {
router.replaceCurrent(route)
}
}
}
}
private suspend fun getInitialRoute(cryptoCurrencyStatus: CryptoCurrencyStatus): YieldSupplyEntryRoute? {
val userWalletId = params.userWalletId
val cryptoCurrency = params.cryptoCurrency
val token = cryptoCurrency as? CryptoCurrency.Token
if (token == null) {
router.pop()
return null
}
val tokenEnterStatus = yieldSupplyEnterStatusUseCase(
userWalletId = userWalletId,
cryptoCurrencyStatus = cryptoCurrencyStatus,
).getOrNull()
val isActiveYield = cryptoCurrencyStatus.value.yieldSupplyStatus?.isActive == true
if (tokenEnterStatus != null) {
router.replaceCurrent(
AppRoute.CurrencyDetails(
userWalletId = userWalletId,
currency = token,
navigationAction = NavigationAction.YieldSupply(
isActive = isActiveYield,
),
),
)
return null
}
return if (isActiveYield) {
YieldSupplyEntryRoute.Active(cryptoCurrency = token)
} else {
YieldSupplyEntryRoute.Promo(cryptoCurrency = token, apy = params.apy)
}
}
}

View file

@ -2,8 +2,6 @@ package com.tangem.features.yield.supply.impl.main.model
import arrow.core.getOrElse
import com.tangem.common.routing.AppRoute
import android.os.SystemClock
import com.tangem.common.routing.AppRoute.YieldSupplyPromo
import com.tangem.common.routing.AppRouter
import com.tangem.core.analytics.api.AnalyticsEventHandler
import com.tangem.core.decompose.di.ModelScoped
@ -25,8 +23,7 @@ import com.tangem.domain.models.yield.supply.YieldSupplyStatus
import com.tangem.domain.networks.single.SingleNetworkStatusFetcher
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
import com.tangem.domain.yield.supply.YieldSupplyRepository
import com.tangem.domain.yield.supply.models.YieldSupplyEnterStatus
import com.tangem.domain.yield.supply.models.YieldSupplyPendingStatus
import com.tangem.domain.yield.supply.usecase.*
import com.tangem.features.yield.supply.api.YieldSupplyComponent
import com.tangem.features.yield.supply.api.analytics.YieldSupplyAnalytics
@ -34,12 +31,9 @@ import com.tangem.features.yield.supply.impl.R
import com.tangem.features.yield.supply.impl.main.entity.YieldSupplyUM
import com.tangem.features.yield.supply.impl.main.model.transformers.YieldSupplyTokenStatusSuccessTransformer
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import com.tangem.utils.coroutines.DelayedWork
import com.tangem.utils.coroutines.JobHolder
import com.tangem.utils.coroutines.saveIn
import com.tangem.utils.transformer.update
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import timber.log.Timber
@ -58,12 +52,11 @@ internal class YieldSupplyModel @Inject constructor(
private val getUserWalletUseCase: GetUserWalletUseCase,
private val getSingleCryptoCurrencyStatusUseCase: GetSingleCryptoCurrencyStatusUseCase,
private val singleNetworkStatusFetcher: SingleNetworkStatusFetcher,
@DelayedWork private val coroutineScope: CoroutineScope,
private val yieldSupplyGetTokenStatusUseCase: YieldSupplyGetTokenStatusUseCase,
private val yieldSupplyIsAvailableUseCase: YieldSupplyIsAvailableUseCase,
private val yieldSupplyActivateUseCase: YieldSupplyActivateUseCase,
private val yieldSupplyDeactivateUseCase: YieldSupplyDeactivateUseCase,
private val yieldSupplyRepository: YieldSupplyRepository,
private val yieldSupplyEnterStatusUseCase: YieldSupplyEnterStatusUseCase,
private val yieldSupplyMinAmountUseCase: YieldSupplyMinAmountUseCase,
private val yieldSupplyGetDustMinAmountUseCase: YieldSupplyGetDustMinAmountUseCase,
) : Model(), YieldSupplyClickIntents {
@ -76,11 +69,10 @@ internal class YieldSupplyModel @Inject constructor(
private val cryptoCurrency = params.cryptoCurrency
private var appCurrency: AppCurrency = AppCurrency.Default
var userWallet: UserWallet by Delegates.notNull()
private var latestCryptoCurrencyStatus: CryptoCurrencyStatus? = null
private val fetchCurrencyJobHolder = JobHolder()
private val loadStatusJobHolder = JobHolder()
private var lastStatusCheckTimestamp = 0L
private val isFirstCryptoCurrencyStatusEmission = AtomicBoolean(true)
init {
@ -116,6 +108,7 @@ internal class YieldSupplyModel @Inject constructor(
).onEach { maybeCryptoCurrency ->
maybeCryptoCurrency.fold(
ifRight = { cryptoCurrencyStatus ->
latestCryptoCurrencyStatus = cryptoCurrencyStatus
if (isFirstCryptoCurrencyStatusEmission.compareAndSet(true, false)) {
sendInfoAboutProtocolStatus(cryptoCurrencyStatus)
}
@ -152,108 +145,61 @@ internal class YieldSupplyModel @Inject constructor(
}
override fun onStartEarningClick() {
val apy = when (val yieldSupplyUM = uiState.value) {
is YieldSupplyUM.Available -> yieldSupplyUM.apy
is YieldSupplyUM.Content -> yieldSupplyUM.apy
else -> ""
}
appRouter.push(
YieldSupplyPromo(
userWalletId = params.userWalletId,
cryptoCurrency = params.cryptoCurrency,
apy = apy,
),
)
navigateToYieldSupplyEntry()
}
override fun onActiveClick() {
navigateToYieldSupplyEntry()
}
private fun navigateToYieldSupplyEntry() {
val cryptoCurrencyStatus = latestCryptoCurrencyStatus ?: return
val apy = when (val yieldSupplyUM = uiState.value) {
is YieldSupplyUM.Available -> yieldSupplyUM.apy
is YieldSupplyUM.Content -> yieldSupplyUM.apy
else -> ""
}
appRouter.push(
AppRoute.YieldSupplyActive(
AppRoute.YieldSupplyEntry(
userWalletId = params.userWalletId,
cryptoCurrency = params.cryptoCurrency,
cryptoCurrency = cryptoCurrencyStatus.currency,
apy = apy,
),
)
}
@Suppress("MaximumLineLength")
private fun onCryptoCurrencyStatusUpdated(cryptoCurrencyStatus: CryptoCurrencyStatus) = modelScope.launch(
dispatchers.default,
) {
val yieldSupplyStatus = cryptoCurrencyStatus.value.yieldSupplyStatus
val tokenProtocolStatus = yieldSupplyRepository.getTokenProtocolStatus(
userWallet.walletId,
cryptoCurrency,
)
val tokenPendingStatus = yieldSupplyRepository.getTokenPendingStatus(
userWallet.walletId,
cryptoCurrencyStatus,
)
val isActive = yieldSupplyStatus?.isActive == true
val isCryptoCurrencyStatusFromCache = cryptoCurrencyStatus.value.sources.networkSource != StatusSource.ACTUAL
val processing = uiState.value is YieldSupplyUM.Processing
Timber.d(
"YIELD " +
"yieldSupplyStatus $yieldSupplyStatus " +
"tokenProtocolStatus $tokenProtocolStatus " +
"tokenPendingStatus $tokenPendingStatus " +
"isActive $isActive " +
"processing $processing " +
"isCryptoCurrencyStatusFromCache $isCryptoCurrencyStatusFromCache",
)
if (isCryptoCurrencyStatusFromCache && processing) {
return@launch
}
when {
tokenProtocolStatus != null && tokenPendingStatus != null -> {
showProcessing(tokenPendingStatus)
lastStatusCheckTimestamp = 0L
}
tokenProtocolStatus == YieldSupplyEnterStatus.Exit && isActive ||
tokenProtocolStatus == YieldSupplyEnterStatus.Enter && !isActive -> {
if (lastStatusCheckTimestamp != 0L) {
if (SystemClock.elapsedRealtime() - lastStatusCheckTimestamp > MAX_STATUS_CHECK_LIMIT) {
loadStatus(cryptoCurrencyStatus)
lastStatusCheckTimestamp = 0L
} else {
showProcessing(tokenProtocolStatus)
}
} else {
showProcessing(tokenProtocolStatus)
lastStatusCheckTimestamp = SystemClock.elapsedRealtime()
}
}
else -> {
loadStatus(cryptoCurrencyStatus)
lastStatusCheckTimestamp = 0L
}
val pendingStatus = yieldSupplyEnterStatusUseCase(
userWalletId = userWallet.walletId,
cryptoCurrencyStatus = cryptoCurrencyStatus,
).getOrNull()
if (pendingStatus != null) {
showProcessing(pendingStatus)
} else {
loadStatus(cryptoCurrencyStatus)
}
}.saveIn(loadStatusJobHolder)
private fun showProcessing(status: YieldSupplyEnterStatus) {
private fun showProcessing(status: YieldSupplyPendingStatus) {
uiState.update {
when (status) {
YieldSupplyEnterStatus.Enter -> YieldSupplyUM.Processing.Enter
YieldSupplyEnterStatus.Exit -> YieldSupplyUM.Processing.Exit
is YieldSupplyPendingStatus.Enter -> YieldSupplyUM.Processing.Enter
is YieldSupplyPendingStatus.Exit -> YieldSupplyUM.Processing.Exit
}
}
fetchCurrencyWithDelay()
}
private suspend fun loadStatus(cryptoCurrencyStatus: CryptoCurrencyStatus) {
val yieldSupplyStatus = cryptoCurrencyStatus.value.yieldSupplyStatus
yieldSupplyRepository.saveTokenProtocolStatus(
userWalletId = userWallet.walletId,
cryptoCurrency = cryptoCurrency,
yieldSupplyEnterStatus = null,
)
if (yieldSupplyStatus?.isActive == true) {
loadActiveState(
cryptoCurrencyStatus = cryptoCurrencyStatus,
@ -264,20 +210,6 @@ internal class YieldSupplyModel @Inject constructor(
}
}
private fun fetchCurrencyWithDelay() {
coroutineScope.launch(dispatchers.io) {
delay(PROCESSING_UPDATE_DELAY)
singleNetworkStatusFetcher(
params = SingleNetworkStatusFetcher.Params(
userWalletId = userWallet.walletId,
network = cryptoCurrency.network,
),
).onLeft {
fetchCurrencyWithDelay()
}
}.saveIn(fetchCurrencyJobHolder)
}
private suspend fun loadActiveState(
cryptoCurrencyStatus: CryptoCurrencyStatus,
yieldSupplyStatus: YieldSupplyStatus,
@ -382,9 +314,4 @@ internal class YieldSupplyModel @Inject constructor(
}
}
}
private companion object {
const val PROCESSING_UPDATE_DELAY = 10_000L
const val MAX_STATUS_CHECK_LIMIT = 10_000L
}
}

View file

@ -54,7 +54,7 @@ internal class YieldSupplyNotificationsModel @Inject constructor(
fee = data.feeValue.orZero(),
userWalletId = params.userWalletId,
tokenStatus = cryptoCurrencyStatus,
coinStatus = feeCryptoCurrencyStatus,
feeStatus = feeCryptoCurrencyStatus,
).getOrNull()
addExceedsBalanceNotification(

View file

@ -21,7 +21,7 @@ import com.tangem.domain.transaction.error.GetFeeError
import com.tangem.domain.transaction.usecase.SendTransactionUseCase
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
import com.tangem.domain.yield.supply.YieldSupplyRepository
import com.tangem.domain.yield.supply.models.YieldSupplyEnterStatus
import com.tangem.domain.yield.supply.models.YieldSupplyPendingStatus
import com.tangem.domain.yield.supply.usecase.*
import com.tangem.features.yield.supply.api.analytics.YieldSupplyAnalytics
import com.tangem.features.yield.supply.impl.R
@ -65,6 +65,7 @@ internal class YieldSupplyStartEarningModel @Inject constructor(
private val yieldSupplyGetMaxFeeUseCase: YieldSupplyGetMaxFeeUseCase,
private val yieldSupplyGetCurrentFeeUseCase: YieldSupplyGetCurrentFeeUseCase,
private val yieldSupplyRepository: YieldSupplyRepository,
private val yieldSupplyPendingTracker: YieldSupplyPendingTracker,
) : Model(), YieldSupplyNotificationsComponent.ModelCallback {
private val params: YieldSupplyStartEarningComponent.Params = paramsContainer.require()
@ -245,18 +246,21 @@ internal class YieldSupplyStartEarningModel @Inject constructor(
},
)
},
ifRight = {
onStartEarningTransactionSuccess(yieldSupplyFeeUM)
ifRight = { txsData ->
onStartEarningTransactionSuccess(yieldSupplyFeeUM, txsData)
},
)
}
}
private suspend fun onStartEarningTransactionSuccess(yieldSupplyFeeUM: YieldSupplyFeeUM.Content) {
yieldSupplyRepository.saveTokenProtocolStatus(
userWalletId,
cryptoCurrency,
YieldSupplyEnterStatus.Enter,
private suspend fun onStartEarningTransactionSuccess(
yieldSupplyFeeUM: YieldSupplyFeeUM.Content,
txsData: List<String>,
) {
yieldSupplyRepository.saveTokenProtocolPendingStatus(
userWalletId = userWalletId,
cryptoCurrency = cryptoCurrency,
yieldSupplyPendingStatus = YieldSupplyPendingStatus.Enter(txsData),
)
val event = AnalyticsParam.TxSentFrom.Earning(
blockchain = cryptoCurrency.network.name,
@ -288,6 +292,11 @@ internal class YieldSupplyStartEarningModel @Inject constructor(
}
modelScope.launch {
yieldSupplyPendingTracker.addPending(
userWalletId = userWalletId,
cryptoCurrency = cryptoCurrency,
txIds = txsData,
)
params.callback.onTransactionSent()
}
}

View file

@ -21,8 +21,9 @@ import com.tangem.domain.transaction.usecase.SendTransactionUseCase
import com.tangem.domain.yield.supply.INCREASE_GAS_LIMIT_FOR_SUPPLY
import com.tangem.domain.yield.supply.YieldSupplyRepository
import com.tangem.domain.yield.supply.increaseGasLimitBy
import com.tangem.domain.yield.supply.models.YieldSupplyEnterStatus
import com.tangem.domain.yield.supply.models.YieldSupplyPendingStatus
import com.tangem.domain.yield.supply.usecase.YieldSupplyDeactivateUseCase
import com.tangem.domain.yield.supply.usecase.YieldSupplyPendingTracker
import com.tangem.domain.yield.supply.usecase.YieldSupplyStopEarningUseCase
import com.tangem.features.yield.supply.api.analytics.YieldSupplyAnalytics
import com.tangem.features.yield.supply.impl.R
@ -61,6 +62,7 @@ internal class YieldSupplyStopEarningModel @Inject constructor(
private val yieldSupplyAlertFactory: YieldSupplyAlertFactory,
private val yieldSupplyDeactivateUseCase: YieldSupplyDeactivateUseCase,
private val yieldSupplyRepository: YieldSupplyRepository,
private val yieldSupplyPendingTracker: YieldSupplyPendingTracker,
) : Model(), YieldSupplyNotificationsComponent.ModelCallback {
private val params: YieldSupplyStopEarningComponent.Params = paramsContainer.require()
@ -167,18 +169,18 @@ internal class YieldSupplyStopEarningModel @Inject constructor(
)
params.callback.onTransactionProgress(false)
},
ifRight = {
onStopEarningTransactionSuccess()
ifRight = { txData ->
onStopEarningTransactionSuccess(txData)
},
)
}
}
private suspend fun onStopEarningTransactionSuccess() {
yieldSupplyRepository.saveTokenProtocolStatus(
userWallet.walletId,
cryptoCurrency,
YieldSupplyEnterStatus.Exit,
private suspend fun onStopEarningTransactionSuccess(txId: String) {
yieldSupplyRepository.saveTokenProtocolPendingStatus(
userWalletId = userWallet.walletId,
cryptoCurrency = cryptoCurrency,
yieldSupplyPendingStatus = YieldSupplyPendingStatus.Exit(listOf(txId)),
)
analytics.send(
YieldSupplyAnalytics.FundsWithdrawn(
@ -203,6 +205,11 @@ internal class YieldSupplyStopEarningModel @Inject constructor(
}
modelScope.launch {
yieldSupplyPendingTracker.addPending(
userWalletId = userWallet.walletId,
cryptoCurrency = cryptoCurrency,
txIds = listOf(txId),
)
params.callback.onStopEarningTransactionSent()
}
}