Updated on 2026-08-14
This commit is contained in:
parent
c1ca73561d
commit
af7f6547db
8 changed files with 101 additions and 52 deletions
|
|
@ -8,6 +8,7 @@ import com.tangem.core.analytics.api.AnalyticsEventHandler
|
|||
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.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.combinedReference
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.core.ui.extensions.stringReference
|
||||
|
|
@ -17,7 +18,7 @@ import com.tangem.domain.models.currency.CryptoCurrencyStatus
|
|||
import com.tangem.domain.models.network.TxInfo
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
|
||||
import com.tangem.domain.tokens.FetchCurrencyStatusUseCase
|
||||
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.usecase.YieldSupplyActivateUseCase
|
||||
|
|
@ -50,7 +51,7 @@ internal class YieldSupplyModel @Inject constructor(
|
|||
private val appRouter: AppRouter,
|
||||
private val getUserWalletUseCase: GetUserWalletUseCase,
|
||||
private val getSingleCryptoCurrencyStatusUseCase: GetSingleCryptoCurrencyStatusUseCase,
|
||||
private val fetchCurrencyStatusUseCase: FetchCurrencyStatusUseCase,
|
||||
private val singleNetworkStatusFetcher: SingleNetworkStatusFetcher,
|
||||
@DelayedWork private val coroutineScope: CoroutineScope,
|
||||
private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase,
|
||||
private val yieldSupplyGetTokenStatusUseCase: YieldSupplyGetTokenStatusUseCase,
|
||||
|
|
@ -95,7 +96,12 @@ internal class YieldSupplyModel @Inject constructor(
|
|||
}
|
||||
coroutineScope.launch(dispatchers.io) {
|
||||
delay(PROCESSING_UPDATE_DELAY)
|
||||
fetchCurrencyStatusUseCase(userWalletId = userWallet.walletId, cryptoCurrency.id)
|
||||
singleNetworkStatusFetcher(
|
||||
params = SingleNetworkStatusFetcher.Params(
|
||||
userWalletId = userWallet.walletId,
|
||||
network = cryptoCurrency.network,
|
||||
),
|
||||
)
|
||||
}
|
||||
}.launchIn(modelScope)
|
||||
yieldSupplyProtocolListener.enterProtocolTriggerFlow.onEach {
|
||||
|
|
@ -104,7 +110,12 @@ internal class YieldSupplyModel @Inject constructor(
|
|||
}
|
||||
coroutineScope.launch(dispatchers.io) {
|
||||
delay(PROCESSING_UPDATE_DELAY)
|
||||
fetchCurrencyStatusUseCase(userWalletId = userWallet.walletId, cryptoCurrency.id)
|
||||
singleNetworkStatusFetcher(
|
||||
params = SingleNetworkStatusFetcher.Params(
|
||||
userWalletId = userWallet.walletId,
|
||||
network = cryptoCurrency.network,
|
||||
),
|
||||
)
|
||||
}
|
||||
}.launchIn(modelScope)
|
||||
}
|
||||
|
|
@ -130,6 +141,7 @@ internal class YieldSupplyModel @Inject constructor(
|
|||
currencyId = cryptoCurrency.id,
|
||||
isSingleWalletWithTokens = false,
|
||||
).onEach { maybeCryptoCurrency ->
|
||||
Timber.tag("getSingleCryptoCurrencyStatusUseCase").d("update $maybeCryptoCurrency")
|
||||
maybeCryptoCurrency.fold(
|
||||
ifRight = { cryptoCurrencyStatus ->
|
||||
cryptoCurrencyStatusFlow.update { cryptoCurrencyStatus }
|
||||
|
|
@ -211,7 +223,12 @@ internal class YieldSupplyModel @Inject constructor(
|
|||
hasActiveTransaction && yieldTransaction != null -> {
|
||||
coroutineScope.launch(dispatchers.io) {
|
||||
delay(PROCESSING_UPDATE_DELAY)
|
||||
fetchCurrencyStatusUseCase(userWalletId = userWallet.walletId, cryptoCurrency.id)
|
||||
singleNetworkStatusFetcher(
|
||||
params = SingleNetworkStatusFetcher.Params(
|
||||
userWalletId = userWallet.walletId,
|
||||
network = cryptoCurrency.network,
|
||||
),
|
||||
)
|
||||
}
|
||||
uiState.update {
|
||||
when (yieldTransaction) {
|
||||
|
|
@ -230,33 +247,10 @@ internal class YieldSupplyModel @Inject constructor(
|
|||
),
|
||||
)
|
||||
}
|
||||
modelScope.launch(dispatchers.default) {
|
||||
yieldSupplyGetTokenStatusUseCase(cryptoCurrencyToken)
|
||||
.onRight { tokenStatus ->
|
||||
uiState.update {
|
||||
YieldSupplyUM.Content(
|
||||
title = resourceReference(
|
||||
R.string.yield_module_token_details_earn_notification_earning_on_your_balance_title,
|
||||
),
|
||||
subtitle = resourceReference(
|
||||
R.string.yield_module_token_details_earn_notification_earning_on_your_balance_subtitle,
|
||||
),
|
||||
rewardsApy = combinedReference(
|
||||
resourceReference(
|
||||
R.string.yield_module_token_details_earn_notification_apy,
|
||||
),
|
||||
stringReference(" ${tokenStatus.apy}%"),
|
||||
),
|
||||
onClick = ::onActiveClick,
|
||||
isAllowedToSpend = yieldSupplyStatus.isAllowedToSpend,
|
||||
apy = tokenStatus.apy.toString(),
|
||||
)
|
||||
}
|
||||
}.onLeft {
|
||||
Timber.e(it)
|
||||
uiState.update { YieldSupplyUM.Loading }
|
||||
}
|
||||
}
|
||||
loadActiveState(
|
||||
cryptoCurrencyToken = cryptoCurrencyToken,
|
||||
yieldSupplyStatus = yieldSupplyStatus,
|
||||
)
|
||||
}
|
||||
|
||||
else -> {
|
||||
|
|
@ -265,6 +259,49 @@ internal class YieldSupplyModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun loadActiveState(cryptoCurrencyToken: CryptoCurrency.Token, yieldSupplyStatus: YieldSupplyStatus) {
|
||||
modelScope.launch(dispatchers.default) {
|
||||
yieldSupplyGetTokenStatusUseCase(cryptoCurrencyToken)
|
||||
.onRight { tokenStatus ->
|
||||
uiState.update {
|
||||
YieldSupplyUM.Content(
|
||||
title = resourceReference(
|
||||
R.string.yield_module_token_details_earn_notification_earning_on_your_balance_title,
|
||||
),
|
||||
subtitle = resourceReference(
|
||||
R.string.yield_module_token_details_earn_notification_earning_on_your_balance_subtitle,
|
||||
),
|
||||
rewardsApy = combinedReference(
|
||||
resourceReference(
|
||||
R.string.yield_module_token_details_earn_notification_apy,
|
||||
),
|
||||
stringReference(" ${tokenStatus.apy}%"),
|
||||
),
|
||||
onClick = ::onActiveClick,
|
||||
isAllowedToSpend = yieldSupplyStatus.isAllowedToSpend,
|
||||
apy = tokenStatus.apy.toString(),
|
||||
)
|
||||
}
|
||||
}.onLeft {
|
||||
Timber.e(it)
|
||||
uiState.update {
|
||||
YieldSupplyUM.Content(
|
||||
title = resourceReference(
|
||||
R.string.yield_module_token_details_earn_notification_earning_on_your_balance_title,
|
||||
),
|
||||
subtitle = resourceReference(
|
||||
R.string.yield_module_token_details_earn_notification_earning_on_your_balance_subtitle,
|
||||
),
|
||||
rewardsApy = TextReference.EMPTY,
|
||||
onClick = ::onActiveClick,
|
||||
isAllowedToSpend = yieldSupplyStatus.isAllowedToSpend,
|
||||
apy = "",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendInfoAboutProtocolStatus(cryptoCurrencyStatus: CryptoCurrencyStatus) {
|
||||
if (lastYieldSupplyStatus == cryptoCurrencyStatus.value.yieldSupplyStatus) return
|
||||
val token = cryptoCurrency as? CryptoCurrency.Token ?: return
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ internal class YieldSupplyActiveModel @Inject constructor(
|
|||
|
||||
val isHighFee = if (currentFee != null && maxFee != null) currentFee > maxFee else false
|
||||
|
||||
val maxFiatFee = cryptoStatus.value.fiatRate?.multiply(maxFee)
|
||||
val maxFiatFee = maxFee?.multiply(cryptoStatus.value.fiatRate)
|
||||
.format { fiat(appCurrency.code, appCurrency.symbol) }
|
||||
val feeDescription = if (isHighFee) {
|
||||
resourceReference(R.string.yield_module_earn_sheet_high_fee_description, wrappedList(maxFiatFee))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue