Updated on 2026-08-14
This commit is contained in:
parent
74ce535550
commit
9de0480b5a
4 changed files with 28 additions and 3 deletions
|
|
@ -55,6 +55,7 @@ interface SwapInteractor {
|
|||
* @param fromToken [Currency] from which want to swap
|
||||
* @param toToken [Currency] that receive after swap
|
||||
* @param amountToSwap amount you want to swap
|
||||
* @param selectedFee selected fee to swap
|
||||
* @return
|
||||
*/
|
||||
@Throws(IllegalStateException::class)
|
||||
|
|
@ -63,6 +64,7 @@ interface SwapInteractor {
|
|||
fromToken: Currency,
|
||||
toToken: Currency,
|
||||
amountToSwap: String,
|
||||
selectedFee: FeeType = FeeType.NORMAL,
|
||||
): SwapState
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -167,6 +167,7 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
fromToken: Currency,
|
||||
toToken: Currency,
|
||||
amountToSwap: String,
|
||||
selectedFee: FeeType,
|
||||
): SwapState {
|
||||
syncWalletBalanceForTokens(networkId, listOf(fromToken, toToken))
|
||||
val amountDecimal = toBigDecimalOrNull(amountToSwap)
|
||||
|
|
@ -190,6 +191,7 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
fromToken = fromToken,
|
||||
toToken = toToken,
|
||||
amount = amount,
|
||||
selectedFee = selectedFee,
|
||||
)
|
||||
} else {
|
||||
loadQuoteData(
|
||||
|
|
@ -454,6 +456,7 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
fromToken: Currency,
|
||||
toToken: Currency,
|
||||
amount: SwapAmount,
|
||||
selectedFee: FeeType,
|
||||
): SwapState {
|
||||
repository.prepareSwapTransaction(
|
||||
networkId = networkId,
|
||||
|
|
@ -475,10 +478,14 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
derivationPath = derivationPath,
|
||||
)
|
||||
val txFeeState = proxyFeesToFeeState(networkId, feeData)
|
||||
val feeByPriority = when (selectedFee) {
|
||||
FeeType.NORMAL -> txFeeState.normalFee.feeValue
|
||||
FeeType.PRIORITY -> txFeeState.priorityFee.feeValue
|
||||
}
|
||||
val isBalanceIncludeFeeEnough =
|
||||
isBalanceEnough(networkId, fromToken, amount, txFeeState.priorityFee.feeValue)
|
||||
isBalanceEnough(networkId, fromToken, amount, feeByPriority)
|
||||
val isFeeEnough = checkFeeIsEnough(
|
||||
fee = txFeeState.normalFee.feeValue,
|
||||
fee = feeByPriority,
|
||||
spendAmount = amount,
|
||||
networkId = networkId,
|
||||
fromToken = fromToken,
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@ internal class StateBuilder(val actions: UiActions, val isBalanceHiddenProvider:
|
|||
} else {
|
||||
permissionState
|
||||
}
|
||||
return when (val fee = uiState.fee) {
|
||||
val updateState = when (val fee = uiState.fee) {
|
||||
is FeeState.Loaded -> {
|
||||
getUpdatedFeeStateForEnoughFee(uiState, fee, item, newSelectedItem, newPermissionState, isFeeEnough)
|
||||
}
|
||||
|
|
@ -321,6 +321,15 @@ internal class StateBuilder(val actions: UiActions, val isBalanceHiddenProvider:
|
|||
}
|
||||
else -> uiState
|
||||
}
|
||||
return if (isFeeEnough) {
|
||||
updateState.copy(
|
||||
warnings = uiState.warnings.filterNot { it is SwapWarning.InsufficientFunds },
|
||||
)
|
||||
} else {
|
||||
updateState.copy(
|
||||
warnings = uiState.warnings.plus(SwapWarning.InsufficientFunds),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
|
|
@ -348,6 +357,9 @@ internal class StateBuilder(val actions: UiActions, val isBalanceHiddenProvider:
|
|||
return uiState.copy(
|
||||
fee = newFeeState,
|
||||
permissionState = newPermissionState,
|
||||
swapButton = uiState.swapButton.copy(
|
||||
enabled = isFeeEnough,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -376,6 +388,9 @@ internal class StateBuilder(val actions: UiActions, val isBalanceHiddenProvider:
|
|||
return uiState.copy(
|
||||
fee = newFeeState,
|
||||
permissionState = newPermissionState,
|
||||
swapButton = uiState.swapButton.copy(
|
||||
enabled = isFeeEnough,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -205,6 +205,7 @@ internal class SwapViewModel @Inject constructor(
|
|||
fromToken = fromToken,
|
||||
toToken = toToken,
|
||||
amountToSwap = amount,
|
||||
selectedFee = dataState.selectedFee?.feeType ?: FeeType.NORMAL,
|
||||
)
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue