Updated on 2026-08-14

This commit is contained in:
Tangem 2023-04-05 17:28:26 +03:00
parent 27c3c5a47b
commit 3bcc451a43
3 changed files with 30 additions and 6 deletions

View file

@ -244,7 +244,7 @@ internal class SwapInteractorImpl @Inject constructor(
return repository.getTangemFee()
}
fun getTokenDecimals(token: Currency): Int {
private fun getTokenDecimals(token: Currency): Int {
return if (token is Currency.NonNativeToken) {
token.decimalCount
} else {
@ -355,15 +355,15 @@ internal class SwapInteractorImpl @Inject constructor(
swapStateData = null,
formattedFee = null,
)
return updatePermissionState(
val quotesState = updatePermissionState(
networkId = networkId,
fromToken = fromToken,
quotesLoadedState = swapState,
).copy(
preparedSwapConfigState = PreparedSwapConfigState(
)
return quotesState.copy(
preparedSwapConfigState = quotesState.preparedSwapConfigState.copy(
isAllowedToSpend = isAllowedToSpend,
isBalanceEnough = isBalanceWithoutFeeEnough,
isFeeEnough = true,
),
)
} else {
@ -540,7 +540,14 @@ internal class SwapInteractorImpl @Inject constructor(
decimals = transactionManager.getNativeTokenDecimals(networkId),
currency = userWalletManager.getNetworkCurrency(networkId),
) + feeFiat
val isFeeEnough = checkFeeIsEnough(
fee = feeData.fee.value,
spendAmount = SwapAmount.zeroSwapAmount(),
networkId = networkId,
fromToken = fromToken,
)
return quotesLoadedState.copy(
fee = formattedFee,
permissionState = PermissionDataState.PermissionReadyForRequest(
currency = fromToken.symbol,
amount = INFINITY_SYMBOL,
@ -553,6 +560,9 @@ internal class SwapInteractorImpl @Inject constructor(
approveModel = transactionData,
),
),
preparedSwapConfigState = quotesLoadedState.preparedSwapConfigState.copy(
isFeeEnough = isFeeEnough,
),
)
}

View file

@ -6,7 +6,14 @@ import java.math.BigDecimal
data class SwapAmount(
val value: BigDecimal,
val decimals: Int,
)
) {
companion object {
fun zeroSwapAmount(): SwapAmount {
return SwapAmount(BigDecimal.ZERO, 0)
}
}
}
fun SwapAmount.formatToUIRepresentation(): String {
return value.toFormattedString(decimals = decimals)

View file

@ -1,5 +1,12 @@
package com.tangem.feature.swap.domain.models.domain
/**
* Prepared swap config state that contains flags to determine
*
* @property isAllowedToSpend shows is token allowed to spend
* @property isBalanceEnough shows is balance of token enough
* @property isFeeEnough shows is amount of main coin enough for fee
*/
data class PreparedSwapConfigState(
val isAllowedToSpend: Boolean,
val isBalanceEnough: Boolean,