Updated on 2026-08-14

This commit is contained in:
Tangem 2023-10-25 10:07:27 +08:00
parent e3a286af0e
commit 8e1c45dfcb
4 changed files with 33 additions and 35 deletions

View file

@ -46,6 +46,7 @@ import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import timber.log.Timber
import java.math.BigDecimal
import javax.inject.Inject
import kotlin.properties.Delegates
@ -264,7 +265,7 @@ internal class TokenDetailsViewModel @Inject constructor(
val cryptoCurrencyStatus = cryptoCurrencyStatus ?: return
viewModelScope.launch(dispatchers.io) {
when (cryptoCurrencyStatus.currency) {
when (val currency = cryptoCurrencyStatus.currency) {
is CryptoCurrency.Coin -> {
reduxStateHolder.dispatch(
action = TradeCryptoAction.New.SendCoin(
@ -273,26 +274,29 @@ internal class TokenDetailsViewModel @Inject constructor(
),
)
}
is CryptoCurrency.Token -> sendToken(status = cryptoCurrencyStatus)
is CryptoCurrency.Token -> {
sendToken(tokenCurrency = currency, tokenFiatRate = cryptoCurrencyStatus.value.fiatRate)
}
}
}
}
private fun sendToken(status: CryptoCurrencyStatus) {
private fun sendToken(tokenCurrency: CryptoCurrency.Token, tokenFiatRate: BigDecimal?) {
viewModelScope.launch(dispatchers.io) {
val wallet = getUserWalletUseCase(userWalletId).getOrElse { return@launch }
val maybeCoinStatus = getNetworkCoinStatusUseCase(
userWalletId = userWalletId,
networkId = status.currency.network.id,
derivationPath = status.currency.network.derivationPath,
networkId = tokenCurrency.network.id,
derivationPath = tokenCurrency.network.derivationPath,
isSingleWalletWithTokens = wallet.scanResponse.cardTypesResolver.isSingleWalletWithToken(),
).firstOrNull()
maybeCoinStatus?.onRight { coinStatus ->
reduxStateHolder.dispatch(
action = TradeCryptoAction.New.SendToken(
userWallet = getUserWalletUseCase(userWalletId).getOrElse { return@launch },
tokenStatus = status,
userWallet = wallet,
tokenCurrency = tokenCurrency,
tokenFiatRate = tokenFiatRate,
coinFiatRate = coinStatus.value.fiatRate,
),
)

View file

@ -638,36 +638,30 @@ internal class WalletViewModel @Inject constructor(
}
override fun onMultiCurrencySendClick(cryptoCurrencyStatus: CryptoCurrencyStatus) {
if (cryptoCurrencyStatus.currency is CryptoCurrency.Coin) {
onSingleCurrencySendClick(cryptoCurrencyStatus = cryptoCurrencyStatus)
return
}
val state = uiState as? WalletState.ContentState ?: return
analyticsEventsHandler.send(
event = TokenScreenAnalyticsEvent.ButtonSend(cryptoCurrencyStatus.currency.symbol),
)
val currency = cryptoCurrencyStatus.currency as? CryptoCurrency.Token ?: return
viewModelScope.launch(dispatchers.io) {
val userWallet = getWallet(index = state.walletsListConfig.selectedWalletIndex)
val isSingleWalletWithTokens = !userWallet.isMultiCurrency &&
userWallet.scanResponse.walletData?.token != null
getNetworkCoinStatusUseCase(
userWalletId = userWallet.walletId,
networkId = cryptoCurrencyStatus.currency.network.id,
derivationPath = cryptoCurrencyStatus.currency.network.derivationPath,
isSingleWalletWithTokens = isSingleWalletWithTokens,
isSingleWalletWithTokens = userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken(),
)
.take(count = 1)
.collectLatest {
it.onRight { coinStatus ->
reduxStateHolder.dispatch(
action = TradeCryptoAction.New.SendToken(
userWallet = getWallet(index = state.walletsListConfig.selectedWalletIndex),
tokenStatus = cryptoCurrencyStatus,
userWallet = userWallet,
tokenCurrency = currency,
tokenFiatRate = cryptoCurrencyStatus.value.fiatRate,
coinFiatRate = coinStatus.value.fiatRate,
),
)