Updated on 2026-08-14
This commit is contained in:
parent
d594af91fc
commit
c3f5ea4284
10 changed files with 496 additions and 43 deletions
|
|
@ -31,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
|
||||
|
|
@ -55,7 +52,6 @@ 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,
|
||||
|
|
@ -75,7 +71,6 @@ internal class YieldSupplyModel @Inject constructor(
|
|||
var userWallet: UserWallet by Delegates.notNull()
|
||||
private var latestCryptoCurrencyStatus: CryptoCurrencyStatus? = null
|
||||
|
||||
private val fetchCurrencyJobHolder = JobHolder()
|
||||
private val loadStatusJobHolder = JobHolder()
|
||||
|
||||
private val isFirstCryptoCurrencyStatusEmission = AtomicBoolean(true)
|
||||
|
|
@ -201,7 +196,6 @@ internal class YieldSupplyModel @Inject constructor(
|
|||
is YieldSupplyPendingStatus.Exit -> YieldSupplyUM.Processing.Exit
|
||||
}
|
||||
}
|
||||
fetchCurrencyWithDelay()
|
||||
}
|
||||
|
||||
private suspend fun loadStatus(cryptoCurrencyStatus: CryptoCurrencyStatus) {
|
||||
|
|
@ -216,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,
|
||||
|
|
@ -334,8 +314,4 @@ internal class YieldSupplyModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val PROCESSING_UPDATE_DELAY = 10_000L
|
||||
}
|
||||
}
|
||||
|
|
@ -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()
|
||||
|
|
@ -291,6 +292,11 @@ internal class YieldSupplyStartEarningModel @Inject constructor(
|
|||
}
|
||||
|
||||
modelScope.launch {
|
||||
yieldSupplyPendingTracker.addPending(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
txIds = txsData,
|
||||
)
|
||||
params.callback.onTransactionSent()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import com.tangem.domain.yield.supply.YieldSupplyRepository
|
|||
import com.tangem.domain.yield.supply.increaseGasLimitBy
|
||||
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()
|
||||
|
|
@ -203,6 +205,11 @@ internal class YieldSupplyStopEarningModel @Inject constructor(
|
|||
}
|
||||
|
||||
modelScope.launch {
|
||||
yieldSupplyPendingTracker.addPending(
|
||||
userWalletId = userWallet.walletId,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
txIds = listOf(txId),
|
||||
)
|
||||
params.callback.onStopEarningTransactionSent()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue