Updated on 2026-08-14
This commit is contained in:
parent
dc097a7815
commit
6901522cf7
6 changed files with 66 additions and 29 deletions
|
|
@ -27,7 +27,7 @@ import com.tangem.utils.isNullOrZero
|
|||
import java.math.BigDecimal
|
||||
|
||||
internal class TokenDetailsStakingInfoConverter(
|
||||
private val cryptoCurrencyStatusProvider: Provider<CryptoCurrencyStatus?>,
|
||||
private val cryptoCurrencyStatus: CryptoCurrencyStatus,
|
||||
private val appCurrencyProvider: Provider<AppCurrency>,
|
||||
private val clickIntents: TokenDetailsClickIntents,
|
||||
private val currentState: TokenDetailsState,
|
||||
|
|
@ -35,7 +35,6 @@ internal class TokenDetailsStakingInfoConverter(
|
|||
) : Converter<StakingAvailability, TokenDetailsState> {
|
||||
|
||||
override fun convert(value: StakingAvailability): TokenDetailsState {
|
||||
val cryptoCurrencyStatus = cryptoCurrencyStatusProvider.invoke() ?: return currentState
|
||||
return currentState.copy(
|
||||
stakingBlocksState = getYieldBalance(cryptoCurrencyStatus, currentState, value),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -129,10 +129,11 @@ internal class TokenDetailsStateFactory(
|
|||
state: TokenDetailsState,
|
||||
stakingEntryInfo: StakingEntryInfo?,
|
||||
stakingAvailability: StakingAvailability,
|
||||
cryptoCurrencyStatus: CryptoCurrencyStatus,
|
||||
): TokenDetailsState {
|
||||
return TokenDetailsStakingInfoConverter(
|
||||
currentState = state,
|
||||
cryptoCurrencyStatusProvider = cryptoCurrencyStatusProvider,
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
clickIntents = clickIntents,
|
||||
appCurrencyProvider = appCurrencyProvider,
|
||||
stakingEntryInfo = stakingEntryInfo,
|
||||
|
|
|
|||
|
|
@ -321,9 +321,9 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
cryptoCurrencyStatus = status
|
||||
updateButtons(currencyStatus = status)
|
||||
updateWarnings(status)
|
||||
subscribeOnUpdateStakingInfo(status)
|
||||
}
|
||||
currencyStatusAnalyticsSender.send(maybeCurrencyStatus)
|
||||
subscribeOnUpdateStakingInfo()
|
||||
}
|
||||
.flowOn(dispatchers.main)
|
||||
.launchIn(viewModelScope)
|
||||
|
|
@ -409,7 +409,7 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun subscribeOnUpdateStakingInfo() {
|
||||
private fun subscribeOnUpdateStakingInfo(cryptoCurrencyStatus: CryptoCurrencyStatus) {
|
||||
getStakingAvailabilityUseCase(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
|
|
@ -417,16 +417,22 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
.map { it.getOrElse { StakingAvailability.Unavailable } }
|
||||
.distinctUntilChanged()
|
||||
.onEach {
|
||||
if (it is StakingAvailability.Available) {
|
||||
val stakingInfo = getStakingEntryInfoUseCase(
|
||||
val stakingEntryInfo = if (it is StakingAvailability.Available) {
|
||||
getStakingEntryInfoUseCase(
|
||||
cryptoCurrencyId = cryptoCurrency.id,
|
||||
symbol = cryptoCurrency.symbol,
|
||||
)
|
||||
).getOrNull()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val stakingEntryInfo = stakingInfo.getOrNull()
|
||||
internalUiState.update { state ->
|
||||
stateFactory.getStakingInfoState(state, stakingEntryInfo, it)
|
||||
}
|
||||
internalUiState.update { state ->
|
||||
stateFactory.getStakingInfoState(
|
||||
state = state,
|
||||
stakingEntryInfo = stakingEntryInfo,
|
||||
stakingAvailability = it,
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
)
|
||||
}
|
||||
}
|
||||
.flowOn(dispatchers.main)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue