Updated on 2026-08-14
This commit is contained in:
parent
0c5ff2eb37
commit
821c6b5697
2 changed files with 46 additions and 6 deletions
|
|
@ -551,9 +551,6 @@ internal class SwapAmountModel @Inject constructor(
|
||||||
initPairs(data.swapCurrencies, data.cryptoCurrency)
|
initPairs(data.swapCurrencies, data.cryptoCurrency)
|
||||||
amountUM.copy(
|
amountUM.copy(
|
||||||
isPrimaryButtonEnabled = false,
|
isPrimaryButtonEnabled = false,
|
||||||
secondaryAmount = SwapAmountFieldUM.Loading(
|
|
||||||
amountType = SwapAmountType.To,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
amountUM
|
amountUM
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ package com.tangem.features.swap.v2.impl.amount.model.transformers
|
||||||
|
|
||||||
import com.tangem.common.ui.amountScreen.converters.field.AmountFieldChangeTransformer
|
import com.tangem.common.ui.amountScreen.converters.field.AmountFieldChangeTransformer
|
||||||
import com.tangem.common.ui.amountScreen.models.EnterAmountBoundary
|
import com.tangem.common.ui.amountScreen.models.EnterAmountBoundary
|
||||||
|
import com.tangem.domain.swap.models.SwapAmountType
|
||||||
|
import com.tangem.domain.swap.models.SwapDirection
|
||||||
|
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountFieldUM
|
||||||
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM
|
import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM
|
||||||
import com.tangem.features.swap.v2.impl.amount.model.SwapAmountQuoteUtils.updateAmount
|
import com.tangem.features.swap.v2.impl.amount.model.SwapAmountQuoteUtils.updateAmount
|
||||||
import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM
|
import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM
|
||||||
|
|
@ -44,13 +47,53 @@ internal class SwapAmountValueChangeTransformer(
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
return (updatedState as? SwapAmountUM.Content)?.copy(
|
val contentState = updatedState as? SwapAmountUM.Content ?: return updatedState
|
||||||
|
|
||||||
|
val newState = if (value.isEmpty()) {
|
||||||
|
contentState.clearOppositeField(prevState)
|
||||||
|
} else {
|
||||||
|
contentState
|
||||||
|
}
|
||||||
|
|
||||||
|
return newState.copy(
|
||||||
isPrimaryButtonEnabled = false,
|
isPrimaryButtonEnabled = false,
|
||||||
selectedQuote = if (updatedState.isPrimaryButtonEnabled) {
|
selectedQuote = if (value.isEmpty()) {
|
||||||
SwapQuoteUM.Empty
|
SwapQuoteUM.Empty
|
||||||
} else {
|
} else {
|
||||||
SwapQuoteUM.Loading
|
SwapQuoteUM.Loading
|
||||||
},
|
},
|
||||||
) ?: updatedState
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun SwapAmountUM.Content.clearOppositeField(prevState: SwapAmountUM.Content): SwapAmountUM.Content {
|
||||||
|
val isPrimaryFieldEdited =
|
||||||
|
selectedAmountType == SwapAmountType.From && swapDirection == SwapDirection.Direct
|
||||||
|
|
||||||
|
return if (isPrimaryFieldEdited) {
|
||||||
|
val secondaryStatus = secondaryCryptoCurrencyStatus ?: return this
|
||||||
|
val secondaryContent = secondaryAmount as? SwapAmountFieldUM.Content ?: return this
|
||||||
|
copy(
|
||||||
|
secondaryAmount = secondaryContent.copy(
|
||||||
|
amountField = AmountFieldChangeTransformer(
|
||||||
|
cryptoCurrencyStatus = secondaryStatus,
|
||||||
|
maxEnterAmount = secondaryMaximumAmountBoundary ?: return this,
|
||||||
|
minimumTransactionAmount = secondaryMinimumAmountBoundary,
|
||||||
|
value = "",
|
||||||
|
).transform(prevState.secondaryAmount.amountField),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
val primaryContent = primaryAmount as? SwapAmountFieldUM.Content ?: return this
|
||||||
|
copy(
|
||||||
|
primaryAmount = primaryContent.copy(
|
||||||
|
amountField = AmountFieldChangeTransformer(
|
||||||
|
cryptoCurrencyStatus = primaryCryptoCurrencyStatus,
|
||||||
|
maxEnterAmount = primaryMaximumAmountBoundary,
|
||||||
|
minimumTransactionAmount = primaryMinimumAmountBoundary,
|
||||||
|
value = "",
|
||||||
|
).transform(prevState.primaryAmount.amountField),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue