Updated on 2026-08-14
This commit is contained in:
commit
5a59a3adee
3 changed files with 45 additions and 2 deletions
|
|
@ -805,6 +805,13 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
if (fromToken is CryptoCurrency.Token) {
|
||||
return IncludeFeeInAmount.Excluded
|
||||
}
|
||||
|
||||
val tokenForFeeBalance =
|
||||
userWalletManager.getNativeTokenBalance(networkId, derivationPath) ?: ProxyAmount.empty()
|
||||
|
||||
if (amount.value > tokenForFeeBalance.value) {
|
||||
return IncludeFeeInAmount.BalanceNotEnough
|
||||
}
|
||||
val feeValue = when (txFee) {
|
||||
TxFeeState.Empty -> BigDecimal.ZERO
|
||||
is TxFeeState.MultipleFeeState -> if (selectedFee == FeeType.NORMAL) {
|
||||
|
|
@ -815,8 +822,6 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
is TxFeeState.SingleFeeState -> txFee.fee.feeValue
|
||||
}
|
||||
|
||||
val tokenForFeeBalance =
|
||||
userWalletManager.getNativeTokenBalance(networkId, derivationPath) ?: ProxyAmount.empty()
|
||||
val amountWithFee = amount.value + feeValue
|
||||
return if (amountWithFee < tokenForFeeBalance.value) {
|
||||
IncludeFeeInAmount.Excluded
|
||||
|
|
|
|||
|
|
@ -784,6 +784,36 @@ internal class StateBuilder(
|
|||
)
|
||||
}
|
||||
|
||||
fun updateProvidersBottomSheetContent(
|
||||
uiState: SwapStateHolder,
|
||||
tokenSwapInfoForProviders: Map<String, TokenSwapInfo>,
|
||||
): SwapStateHolder {
|
||||
val config = uiState.bottomSheetConfig?.content as? ChooseProviderBottomSheetConfig
|
||||
return if (config != null) {
|
||||
val providers = config.providers
|
||||
uiState.copy(
|
||||
bottomSheetConfig = uiState.bottomSheetConfig.copy(
|
||||
content = config.copy(
|
||||
providers = providers.map {
|
||||
val tokenInfo = tokenSwapInfoForProviders[it.id]
|
||||
if (it is ProviderState.Content && tokenInfo != null) {
|
||||
val rateString = tokenInfo.tokenAmount
|
||||
.getFormattedCryptoAmount(tokenInfo.cryptoCurrencyStatus.currency)
|
||||
it.copy(
|
||||
subtitle = stringReference(rateString),
|
||||
)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}.toImmutableList(),
|
||||
),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
uiState
|
||||
}
|
||||
}
|
||||
|
||||
fun updateSelectedProvider(uiState: SwapStateHolder, selectedProviderId: String): SwapStateHolder {
|
||||
val config = uiState.bottomSheetConfig?.content as? ChooseProviderBottomSheetConfig
|
||||
return if (config != null) {
|
||||
|
|
|
|||
|
|
@ -271,6 +271,13 @@ internal class SwapViewModel @Inject constructor(
|
|||
if (providersState.isNotEmpty()) {
|
||||
val (provider, state) = updateLoadedQuotes(providersState)
|
||||
setupLoadedState(provider, state, fromToken)
|
||||
uiState = stateBuilder.updateProvidersBottomSheetContent(
|
||||
uiState = uiState,
|
||||
tokenSwapInfoForProviders = providersState
|
||||
.getLastLoadedSuccessStates()
|
||||
.entries
|
||||
.associate { it.key.providerId to it.value.toTokenInfo },
|
||||
)
|
||||
} else {
|
||||
Timber.e("Accidentally empty quotes list")
|
||||
}
|
||||
|
|
@ -483,6 +490,7 @@ internal class SwapViewModel @Inject constructor(
|
|||
when (it) {
|
||||
is TxState.TxSent -> {
|
||||
uiState = stateBuilder.loadingPermissionState(uiState)
|
||||
uiState = stateBuilder.dismissBottomSheet(uiState)
|
||||
}
|
||||
is TxState.UserCancelled -> Unit
|
||||
else -> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue