Updated on 2026-08-14
This commit is contained in:
parent
76e17fc21f
commit
f9cc3decfb
12 changed files with 353 additions and 144 deletions
|
|
@ -45,10 +45,7 @@ import com.tangem.domain.staking.GetYieldUseCase
|
|||
import com.tangem.domain.staking.model.StakingAvailability
|
||||
import com.tangem.domain.tokens.*
|
||||
import com.tangem.domain.tokens.legacy.TradeCryptoAction
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.domain.tokens.model.NetworkAddress
|
||||
import com.tangem.domain.tokens.model.ScenarioUnavailabilityReason
|
||||
import com.tangem.domain.tokens.model.*
|
||||
import com.tangem.domain.tokens.model.analytics.TokenReceiveAnalyticsEvent
|
||||
import com.tangem.domain.tokens.model.analytics.TokenScreenAnalyticsEvent
|
||||
import com.tangem.domain.tokens.model.analytics.TokenScreenAnalyticsEvent.Companion.toReasonAnalyticsText
|
||||
|
|
@ -281,6 +278,7 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
.conflate()
|
||||
.distinctUntilChanged()
|
||||
.onEach {
|
||||
sendButtonsEvents(it.states)
|
||||
internalUiState.value = stateFactory.getManageButtonsState(actions = it.states)
|
||||
}
|
||||
.flowOn(dispatchers.main)
|
||||
|
|
@ -288,6 +286,21 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
.saveIn(buttonsJobHolder)
|
||||
}
|
||||
|
||||
private fun sendButtonsEvents(states: List<TokenActionsState.ActionState>) {
|
||||
// for now send only for swap
|
||||
val swapState = states.firstOrNull { it is TokenActionsState.ActionState.Swap } ?: return
|
||||
if (swapState.unavailabilityReason != ScenarioUnavailabilityReason.None) {
|
||||
analyticsEventsHandler.send(
|
||||
TokenScreenAnalyticsEvent.ActionButtonDisabled(
|
||||
token = cryptoCurrency.symbol,
|
||||
status = swapState.unavailabilityReason.toReasonAnalyticsText(),
|
||||
blockchain = cryptoCurrency.network.name,
|
||||
action = "Swap",
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateWarnings(cryptoCurrencyStatus: CryptoCurrencyStatus) {
|
||||
viewModelScope.launch(dispatchers.main) {
|
||||
getCurrencyWarningsUseCase.invoke(
|
||||
|
|
@ -472,14 +485,15 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onBuyClick(unavailabilityReason: ScenarioUnavailabilityReason) {
|
||||
analyticsEventsHandler.send(TokenScreenAnalyticsEvent.ButtonBuy(cryptoCurrency.symbol))
|
||||
analyticsEventsHandler.send(
|
||||
TokenScreenAnalyticsEvent.ButtonWithParams.ButtonBuy(
|
||||
token = cryptoCurrency.symbol,
|
||||
blockchain = cryptoCurrency.network.name,
|
||||
status = unavailabilityReason.toReasonAnalyticsText(),
|
||||
),
|
||||
)
|
||||
|
||||
if (handleUnavailabilityReason(
|
||||
unavailabilityReason = unavailabilityReason,
|
||||
tokenSymbol = cryptoCurrency.symbol,
|
||||
tokenAction = TokenScreenAnalyticsEvent.NoticeActionInactive.TokenAction.BuyAction,
|
||||
)
|
||||
) {
|
||||
if (handleUnavailabilityReason(unavailabilityReason = unavailabilityReason)) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -512,7 +526,13 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onBuyCoinClick(cryptoCurrency: CryptoCurrency) {
|
||||
analyticsEventsHandler.send(TokenScreenAnalyticsEvent.ButtonBuy(cryptoCurrency.symbol))
|
||||
analyticsEventsHandler.send(
|
||||
TokenScreenAnalyticsEvent.ButtonWithParams.ButtonBuy(
|
||||
token = cryptoCurrency.symbol,
|
||||
blockchain = cryptoCurrency.network.name,
|
||||
status = null,
|
||||
),
|
||||
)
|
||||
router.openTokenDetails(userWalletId = userWalletId, currency = cryptoCurrency)
|
||||
}
|
||||
|
||||
|
|
@ -528,14 +548,15 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onSendClick(unavailabilityReason: ScenarioUnavailabilityReason) {
|
||||
analyticsEventsHandler.send(TokenScreenAnalyticsEvent.ButtonSend(cryptoCurrency.symbol))
|
||||
analyticsEventsHandler.send(
|
||||
TokenScreenAnalyticsEvent.ButtonWithParams.ButtonSend(
|
||||
token = cryptoCurrency.symbol,
|
||||
blockchain = cryptoCurrency.network.name,
|
||||
status = unavailabilityReason.toReasonAnalyticsText(),
|
||||
),
|
||||
)
|
||||
|
||||
if (handleUnavailabilityReason(
|
||||
unavailabilityReason = unavailabilityReason,
|
||||
tokenSymbol = cryptoCurrency.symbol,
|
||||
tokenAction = TokenScreenAnalyticsEvent.NoticeActionInactive.TokenAction.SendAction,
|
||||
)
|
||||
) {
|
||||
if (handleUnavailabilityReason(unavailabilityReason = unavailabilityReason)) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -554,17 +575,18 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
override fun onReceiveClick(unavailabilityReason: ScenarioUnavailabilityReason) {
|
||||
val networkAddress = cryptoCurrencyStatus?.value?.networkAddress ?: return
|
||||
|
||||
if (handleUnavailabilityReason(
|
||||
unavailabilityReason = unavailabilityReason,
|
||||
tokenSymbol = cryptoCurrency.symbol,
|
||||
tokenAction = TokenScreenAnalyticsEvent.NoticeActionInactive.TokenAction.ReceiveAction,
|
||||
)
|
||||
) {
|
||||
if (handleUnavailabilityReason(unavailabilityReason = unavailabilityReason)) {
|
||||
return
|
||||
}
|
||||
|
||||
viewModelScope.launch(dispatchers.main) {
|
||||
analyticsEventsHandler.send(TokenScreenAnalyticsEvent.ButtonReceive(cryptoCurrency.symbol))
|
||||
analyticsEventsHandler.send(
|
||||
TokenScreenAnalyticsEvent.ButtonWithParams.ButtonReceive(
|
||||
token = cryptoCurrency.symbol,
|
||||
blockchain = cryptoCurrency.network.name,
|
||||
status = unavailabilityReason.toReasonAnalyticsText(),
|
||||
),
|
||||
)
|
||||
analyticsEventsHandler.send(TokenReceiveAnalyticsEvent.ReceiveScreenOpened(cryptoCurrency.symbol))
|
||||
|
||||
internalUiState.value = stateFactory.getStateWithReceiveBottomSheet(
|
||||
|
|
@ -583,12 +605,7 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onStakeClick(unavailabilityReason: ScenarioUnavailabilityReason) {
|
||||
if (handleUnavailabilityReason(
|
||||
unavailabilityReason = unavailabilityReason,
|
||||
tokenSymbol = cryptoCurrency.symbol,
|
||||
tokenAction = null,
|
||||
)
|
||||
) {
|
||||
if (handleUnavailabilityReason(unavailabilityReason = unavailabilityReason)) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -619,14 +636,15 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onSellClick(unavailabilityReason: ScenarioUnavailabilityReason) {
|
||||
analyticsEventsHandler.send(TokenScreenAnalyticsEvent.ButtonSell(cryptoCurrency.symbol))
|
||||
analyticsEventsHandler.send(
|
||||
TokenScreenAnalyticsEvent.ButtonWithParams.ButtonSell(
|
||||
token = cryptoCurrency.symbol,
|
||||
blockchain = cryptoCurrency.network.name,
|
||||
status = unavailabilityReason.toReasonAnalyticsText(),
|
||||
),
|
||||
)
|
||||
|
||||
if (handleUnavailabilityReason(
|
||||
unavailabilityReason = unavailabilityReason,
|
||||
tokenSymbol = cryptoCurrency.symbol,
|
||||
tokenAction = TokenScreenAnalyticsEvent.NoticeActionInactive.TokenAction.SellAction,
|
||||
)
|
||||
) {
|
||||
if (handleUnavailabilityReason(unavailabilityReason = unavailabilityReason)) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -643,14 +661,15 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onSwapClick(unavailabilityReason: ScenarioUnavailabilityReason) {
|
||||
analyticsEventsHandler.send(TokenScreenAnalyticsEvent.ButtonExchange(cryptoCurrency.symbol))
|
||||
analyticsEventsHandler.send(
|
||||
TokenScreenAnalyticsEvent.ButtonWithParams.ButtonExchange(
|
||||
token = cryptoCurrency.symbol,
|
||||
blockchain = cryptoCurrency.network.name,
|
||||
status = unavailabilityReason.toReasonAnalyticsText(),
|
||||
),
|
||||
)
|
||||
|
||||
if (handleUnavailabilityReason(
|
||||
unavailabilityReason = unavailabilityReason,
|
||||
tokenSymbol = cryptoCurrency.symbol,
|
||||
tokenAction = TokenScreenAnalyticsEvent.NoticeActionInactive.TokenAction.SwapAction,
|
||||
)
|
||||
) {
|
||||
if (handleUnavailabilityReason(unavailabilityReason = unavailabilityReason)) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -972,21 +991,8 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
internalUiState.value = stateFactory.getStateWithClosedBottomSheet()
|
||||
}
|
||||
|
||||
private fun handleUnavailabilityReason(
|
||||
unavailabilityReason: ScenarioUnavailabilityReason,
|
||||
tokenSymbol: String,
|
||||
tokenAction: TokenScreenAnalyticsEvent.NoticeActionInactive.TokenAction?,
|
||||
): Boolean {
|
||||
private fun handleUnavailabilityReason(unavailabilityReason: ScenarioUnavailabilityReason): Boolean {
|
||||
if (unavailabilityReason == ScenarioUnavailabilityReason.None) return false
|
||||
if (tokenAction != null) {
|
||||
analyticsEventsHandler.send(
|
||||
TokenScreenAnalyticsEvent.NoticeActionInactive(
|
||||
token = tokenSymbol,
|
||||
tokenAction = tokenAction,
|
||||
reason = unavailabilityReason.toReasonAnalyticsText(),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
internalUiState.value = stateFactory.getStateWithActionButtonErrorDialog(unavailabilityReason)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue