Updated on 2026-08-14
This commit is contained in:
parent
54094ffa2f
commit
5e17abbf91
4 changed files with 36 additions and 32 deletions
|
|
@ -536,18 +536,17 @@ internal class SwapAmountModel @Inject constructor(
|
|||
} as? AmountState.Data
|
||||
|
||||
val fromAmountValue = fromAmount?.amountTextField?.cryptoAmount?.value.orZero()
|
||||
|
||||
if (fromAmount?.amountTextField?.isError == true || fromAmountValue.isNullOrZero()) {
|
||||
val isAmountScreen = params is SwapAmountComponentParams.AmountParams
|
||||
val isAmountError = fromAmount?.amountTextField?.isError == true || fromAmountValue.isNullOrZero()
|
||||
if (isAmountScreen && isAmountError) {
|
||||
uiState.transformerUpdate(SwapQuoteEmptyStateTransformer)
|
||||
return
|
||||
}
|
||||
|
||||
val swapGroups = state.swapCurrencies.getGroupWithDirection(state.swapDirection)
|
||||
|
||||
uiState.transformerUpdate(SwapQuoteLoadingStateTransformer)
|
||||
if (!isSilentReload) { uiState.transformerUpdate(SwapQuoteLoadingStateTransformer) }
|
||||
|
||||
modelScope.launch {
|
||||
val quotes = swapGroups.available.filter {
|
||||
val quotes = state.swapCurrencies.getGroupWithDirection(state.swapDirection).available.filter {
|
||||
it.currencyStatus.currency.id == toCryptoCurrency.id
|
||||
}.flatMap {
|
||||
it.providers
|
||||
|
|
@ -594,7 +593,6 @@ internal class SwapAmountModel @Inject constructor(
|
|||
needApplyFcaRestrictions = userCountry.needApplyFCARestrictions(),
|
||||
),
|
||||
)
|
||||
|
||||
feeSelectorReloadTrigger.triggerUpdate()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,8 +34,10 @@ internal class SwapAmountSetQuotesTransformer(
|
|||
|
||||
val sortedQuotes = quotes.sortedWith(SwapQuotesComparator)
|
||||
val bestQuote = findBestQuote(quotes) ?: SwapQuoteUM.Empty
|
||||
val quotesWithDiff = getQuotesWithDiff(sortedQuotes, bestQuote, isSingleProvider)
|
||||
val selectedQuote = if (isSilentReload && prevState.selectedQuote !is SwapQuoteUM.Loading) {
|
||||
prevState.selectedQuote
|
||||
quotesWithDiff.firstOrNull { it.provider?.providerId == prevState.selectedQuote.provider?.providerId }
|
||||
?: prevState.selectedQuote
|
||||
} else {
|
||||
(bestQuote as? SwapQuoteUM.Content)?.copy(
|
||||
diffPercent = DifferencePercent.Best,
|
||||
|
|
@ -55,7 +57,7 @@ internal class SwapAmountSetQuotesTransformer(
|
|||
if (updatedState !is SwapAmountUM.Content) return prevState
|
||||
|
||||
return updatedState.copy(
|
||||
isPrimaryButtonEnabled = updatedState.isPrimaryButtonEnabled && quotes.isNotEmpty(),
|
||||
isPrimaryButtonEnabled = updatedState.isPrimaryButtonEnabled && quotesWithDiff.isNotEmpty(),
|
||||
swapQuotes = getQuotesWithDiff(sortedQuotes, bestQuote, isSingleProvider),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ internal class SwapAmountValueChangeTransformer(
|
|||
)
|
||||
|
||||
return (updatedState as? SwapAmountUM.Content)?.copy(
|
||||
isPrimaryButtonEnabled = false,
|
||||
selectedQuote = if (updatedState.isPrimaryButtonEnabled) {
|
||||
SwapQuoteUM.Empty
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -16,31 +16,34 @@ internal class SwapAmountValueMaxTransformer(
|
|||
override fun transform(prevState: SwapAmountUM): SwapAmountUM {
|
||||
if (prevState !is SwapAmountUM.Content) return prevState
|
||||
|
||||
return prevState
|
||||
.copy(selectedQuote = SwapQuoteUM.Loading)
|
||||
.updateAmount(
|
||||
onPrimaryAmount = { primaryStatus ->
|
||||
val updatedState = prevState.updateAmount(
|
||||
onPrimaryAmount = { primaryStatus ->
|
||||
copy(
|
||||
amountField = AmountFieldSetMaxAmountTransformer(
|
||||
cryptoCurrencyStatus = primaryStatus,
|
||||
maxAmount = primaryMaximumAmountBoundary,
|
||||
minAmount = primaryMinimumAmountBoundary,
|
||||
).transform(prevState.primaryAmount.amountField),
|
||||
)
|
||||
},
|
||||
onSecondaryAmount = { secondaryStatus ->
|
||||
if (secondaryMaximumAmountBoundary != null) {
|
||||
copy(
|
||||
amountField = AmountFieldSetMaxAmountTransformer(
|
||||
cryptoCurrencyStatus = primaryStatus,
|
||||
maxAmount = primaryMaximumAmountBoundary,
|
||||
minAmount = primaryMinimumAmountBoundary,
|
||||
).transform(prevState.primaryAmount.amountField),
|
||||
cryptoCurrencyStatus = secondaryStatus,
|
||||
maxAmount = secondaryMaximumAmountBoundary,
|
||||
minAmount = secondaryMinimumAmountBoundary,
|
||||
).transform(prevState.secondaryAmount.amountField),
|
||||
)
|
||||
},
|
||||
onSecondaryAmount = { secondaryStatus ->
|
||||
if (secondaryMaximumAmountBoundary != null) {
|
||||
copy(
|
||||
amountField = AmountFieldSetMaxAmountTransformer(
|
||||
cryptoCurrencyStatus = secondaryStatus,
|
||||
maxAmount = secondaryMaximumAmountBoundary,
|
||||
minAmount = secondaryMinimumAmountBoundary,
|
||||
).transform(prevState.secondaryAmount.amountField),
|
||||
)
|
||||
} else {
|
||||
this
|
||||
}
|
||||
},
|
||||
)
|
||||
} else {
|
||||
this
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
return (updatedState as? SwapAmountUM.Content)?.copy(
|
||||
isPrimaryButtonEnabled = false,
|
||||
selectedQuote = SwapQuoteUM.Loading,
|
||||
) ?: updatedState
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue