Updated on 2026-08-14
This commit is contained in:
parent
e3a286af0e
commit
8e1c45dfcb
4 changed files with 33 additions and 35 deletions
|
|
@ -332,8 +332,7 @@ class TradeCryptoMiddleware {
|
|||
}
|
||||
|
||||
private fun handleNewSendToken(action: TradeCryptoAction.New.SendToken) {
|
||||
val cryptoStatus = action.tokenStatus
|
||||
val currency = cryptoStatus.currency
|
||||
val currency = action.tokenCurrency
|
||||
val blockchain = Blockchain.fromId(currency.network.id.value)
|
||||
|
||||
scope.launch {
|
||||
|
|
@ -352,21 +351,21 @@ class TradeCryptoMiddleware {
|
|||
return@launch
|
||||
}
|
||||
|
||||
val sendableAmounts = walletManager.wallet.amounts.values.filter { it.type is AmountType.Token }
|
||||
when (currency) {
|
||||
is CryptoCurrency.Coin -> error("Action.tokenStatus.currency is Coin")
|
||||
is CryptoCurrency.Token -> {
|
||||
store.dispatchOnMain(
|
||||
action = PrepareSendScreen(
|
||||
walletManager = walletManager,
|
||||
coinAmount = walletManager.wallet.amounts[AmountType.Coin],
|
||||
coinRate = action.coinFiatRate,
|
||||
tokenAmount = sendableAmounts.first(),
|
||||
tokenRate = cryptoStatus.value.fiatRate,
|
||||
),
|
||||
)
|
||||
}
|
||||
val sendableAmount = walletManager.wallet.amounts.values.firstOrNull {
|
||||
val amountType = it.type
|
||||
amountType is AmountType.Token && amountType.token.contractAddress == currency.contractAddress
|
||||
}
|
||||
|
||||
store.dispatchOnMain(
|
||||
action = PrepareSendScreen(
|
||||
walletManager = walletManager,
|
||||
coinAmount = walletManager.wallet.amounts[AmountType.Coin],
|
||||
coinRate = action.coinFiatRate,
|
||||
tokenAmount = sendableAmount,
|
||||
tokenRate = action.tokenFiatRate,
|
||||
),
|
||||
)
|
||||
|
||||
val bundle = bundleOf(SendRouter.CRYPTO_CURRENCY_KEY to currency)
|
||||
store.dispatchOnMain(NavigationAction.NavigateTo(screen = AppScreen.Send, bundle = bundle))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ sealed class TradeCryptoAction : Action {
|
|||
|
||||
data class SendToken(
|
||||
val userWallet: UserWallet,
|
||||
val tokenStatus: CryptoCurrencyStatus,
|
||||
val tokenCurrency: CryptoCurrency.Token,
|
||||
val tokenFiatRate: BigDecimal?,
|
||||
val coinFiatRate: BigDecimal?,
|
||||
) : New()
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue