Updated on 2026-08-14
This commit is contained in:
parent
613bb9226f
commit
3f1102f232
20 changed files with 247 additions and 172 deletions
|
|
@ -15,7 +15,6 @@ import com.tangem.feature.swap.models.states.ProviderState
|
|||
data class SwapStateHolder(
|
||||
val sendCardData: SwapCardState,
|
||||
val receiveCardData: SwapCardState,
|
||||
val networkCurrency: String,
|
||||
val blockchainId: String, // not the same as networkId, its local id in app
|
||||
val warnings: List<SwapWarning> = emptyList(),
|
||||
val alert: SwapWarning.GenericWarning? = null,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.feature.swap.models
|
||||
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.feature.swap.domain.models.ui.TxFee
|
||||
|
||||
data class UiActions(
|
||||
|
|
@ -20,7 +21,7 @@ data class UiActions(
|
|||
val onSelectFeeType: (TxFee) -> Unit,
|
||||
val onProviderClick: (String) -> Unit,
|
||||
val onProviderSelect: (String) -> Unit,
|
||||
val onBuyClick: () -> Unit,
|
||||
val onBuyClick: (CryptoCurrency) -> Unit,
|
||||
val onPolicyClick: (String) -> Unit,
|
||||
val onTosClick: (String) -> Unit,
|
||||
val onReceiveCardWarningClick: () -> Unit,
|
||||
|
|
|
|||
|
|
@ -79,7 +79,6 @@ internal class StateBuilder(
|
|||
isBalanceHidden = true,
|
||||
),
|
||||
fee = FeeItemState.Empty,
|
||||
networkCurrency = networkInfo.blockchainCurrency,
|
||||
swapButton = SwapButton(enabled = false, onClick = {}),
|
||||
onRefresh = {},
|
||||
onBackClicked = actions.onBackClicked,
|
||||
|
|
@ -250,7 +249,6 @@ internal class StateBuilder(
|
|||
balance = toCurrencyStatus.getFormattedAmount(isNeedSymbol = false),
|
||||
isBalanceHidden = isBalanceHiddenProvider(),
|
||||
),
|
||||
networkCurrency = quoteModel.networkCurrency,
|
||||
warnings = warnings,
|
||||
permissionState = convertPermissionState(
|
||||
lastPermissionState = uiStateHolder.permissionState,
|
||||
|
|
@ -317,7 +315,7 @@ internal class StateBuilder(
|
|||
val warnings = mutableListOf<SwapWarning>()
|
||||
addDomainWarnings(quoteModel, warnings)
|
||||
if (!quoteModel.preparedSwapConfigState.isAllowedToSpend &&
|
||||
quoteModel.preparedSwapConfigState.isFeeEnough &&
|
||||
quoteModel.preparedSwapConfigState.feeState is SwapFeeState.Enough &&
|
||||
quoteModel.permissionState is PermissionDataState.PermissionReadyForRequest
|
||||
) {
|
||||
warnings.add(
|
||||
|
|
@ -412,7 +410,8 @@ internal class StateBuilder(
|
|||
fromToken: CryptoCurrency,
|
||||
warnings: MutableList<SwapWarning>,
|
||||
) {
|
||||
if (!quoteModel.preparedSwapConfigState.isFeeEnough &&
|
||||
val feeEnoughState = quoteModel.preparedSwapConfigState.feeState
|
||||
if (feeEnoughState is SwapFeeState.NotEnough &&
|
||||
quoteModel.preparedSwapConfigState.isBalanceEnough &&
|
||||
quoteModel.permissionState !is PermissionDataState.PermissionLoading
|
||||
) {
|
||||
|
|
@ -420,7 +419,9 @@ internal class StateBuilder(
|
|||
SwapWarning.UnableToCoverFeeWarning(
|
||||
createUnableToCoverFeeNotificationConfig(
|
||||
fromToken = fromToken,
|
||||
onBuyClick = actions.onBuyClick,
|
||||
feeCurrency = feeEnoughState.feeCurrency,
|
||||
currencyName = feeEnoughState.currencyName ?: fromToken.network.name,
|
||||
currencySymbol = feeEnoughState.currencySymbol ?: fromToken.network.currencySymbol,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
@ -438,7 +439,7 @@ internal class StateBuilder(
|
|||
IncludeFeeInAmount.Excluded ->
|
||||
preparedSwapConfigState.isAllowedToSpend &&
|
||||
preparedSwapConfigState.isBalanceEnough &&
|
||||
preparedSwapConfigState.isFeeEnough
|
||||
preparedSwapConfigState.feeState is SwapFeeState.Enough
|
||||
is IncludeFeeInAmount.Included -> true
|
||||
}
|
||||
}
|
||||
|
|
@ -1219,8 +1220,16 @@ internal class StateBuilder(
|
|||
|
||||
private fun createUnableToCoverFeeNotificationConfig(
|
||||
fromToken: CryptoCurrency,
|
||||
onBuyClick: () -> Unit,
|
||||
feeCurrency: CryptoCurrency?,
|
||||
currencyName: String,
|
||||
currencySymbol: String,
|
||||
): NotificationConfig {
|
||||
val buttonState = feeCurrency?.let {
|
||||
NotificationConfig.ButtonsState.SecondaryButtonConfig(
|
||||
text = resourceReference(R.string.common_buy_currency, wrappedList(currencySymbol)),
|
||||
onClick = { actions.onBuyClick(it) },
|
||||
)
|
||||
}
|
||||
return NotificationConfig(
|
||||
title = resourceReference(
|
||||
R.string.warning_express_not_enough_fee_for_token_tx_title,
|
||||
|
|
@ -1228,13 +1237,10 @@ internal class StateBuilder(
|
|||
),
|
||||
subtitle = resourceReference(
|
||||
R.string.warning_express_not_enough_fee_for_token_tx_description,
|
||||
wrappedList(fromToken.network.name, fromToken.network.currencySymbol),
|
||||
wrappedList(currencyName, currencySymbol),
|
||||
),
|
||||
iconResId = fromToken.networkIconResId,
|
||||
buttonsState = NotificationConfig.ButtonsState.SecondaryButtonConfig(
|
||||
text = resourceReference(R.string.common_buy_currency, wrappedList(fromToken.network.currencySymbol)),
|
||||
onClick = onBuyClick,
|
||||
),
|
||||
buttonsState = buttonState,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -490,7 +490,6 @@ private val state = SwapStateHolder(
|
|||
),
|
||||
),
|
||||
),
|
||||
networkCurrency = "MATIC",
|
||||
swapButton = SwapButton(enabled = true, onClick = {}),
|
||||
onRefresh = {},
|
||||
onBackClicked = {},
|
||||
|
|
|
|||
|
|
@ -932,12 +932,11 @@ internal class SwapViewModel @Inject constructor(
|
|||
)
|
||||
}
|
||||
},
|
||||
onBuyClick = {
|
||||
swapInteractor.getSelectedWallet()?.let {
|
||||
val fromToken = dataState.fromCryptoCurrency ?: return@let
|
||||
onBuyClick = { currency ->
|
||||
swapInteractor.getSelectedWallet()?.let { userWallet ->
|
||||
swapRouter.openTokenDetails(
|
||||
it.walletId,
|
||||
swapInteractor.getNativeToken(fromToken.currency.network.backendId),
|
||||
userWalletId = userWallet.walletId,
|
||||
currency = currency,
|
||||
)
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue