From 8b69fb70dc0c1be2ed53f2440e72fb8d2c989e2a Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 29 May 2026 21:24:41 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../configs/feature_toggles_config.json | 2 +- .../FeatureTogglesNamingConventionTest.kt | 1 - .../domain/transfer/SwapTransferInteractor.kt | 4 +- .../transfer/SwapTransferInteractorImpl.kt | 10 ++--- .../SwapTransferInteractorImplTest.kt | 38 ++++++++++++++++--- .../feature/swap/DefaultSwapFeatureToggles.kt | 2 +- .../tangem/feature/swap/model/SwapModel.kt | 14 +++---- gradle/tangem_dependencies.toml | 2 +- .../WalletManagerFactoryCreator.kt | 3 ++ .../di/BlockchainSDKFactoryModule.kt | 5 ++- 10 files changed, 56 insertions(+), 25 deletions(-) diff --git a/core/config-toggles/src/main/assets/configs/feature_toggles_config.json b/core/config-toggles/src/main/assets/configs/feature_toggles_config.json index 8eed9a1b0a..cf25f880f4 100644 --- a/core/config-toggles/src/main/assets/configs/feature_toggles_config.json +++ b/core/config-toggles/src/main/assets/configs/feature_toggles_config.json @@ -68,7 +68,7 @@ "version": "undefined" }, { - "name": "SWAP_INTEGRATED_APPROVE", + "name": "AND_15120_SWAP_INTEGRATED_APPROVE", "version": "undefined" }, { diff --git a/core/config-toggles/src/test/kotlin/com/tangem/core/configtoggle/feature/FeatureTogglesNamingConventionTest.kt b/core/config-toggles/src/test/kotlin/com/tangem/core/configtoggle/feature/FeatureTogglesNamingConventionTest.kt index fa6ba51dee..b4d72d4288 100644 --- a/core/config-toggles/src/test/kotlin/com/tangem/core/configtoggle/feature/FeatureTogglesNamingConventionTest.kt +++ b/core/config-toggles/src/test/kotlin/com/tangem/core/configtoggle/feature/FeatureTogglesNamingConventionTest.kt @@ -50,7 +50,6 @@ internal class FeatureTogglesNamingConventionTest { "SOLANA_TX_HISTORY_ENABLED", "STAKING_ETH_ENABLED", "SWAP_AB_ENABLED", - "SWAP_INTEGRATED_APPROVE", "USEDESK_ENABLED", "VIRTUAL_ACCOUNTS_ENABLED", "VISA_ONBOARDING_ENABLED", diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/transfer/SwapTransferInteractor.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/transfer/SwapTransferInteractor.kt index 6731dc4b61..976de31b40 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/transfer/SwapTransferInteractor.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/transfer/SwapTransferInteractor.kt @@ -30,13 +30,13 @@ interface SwapTransferInteractor { suspend fun loadFee( fromSwapCurrencyStatus: SwapCurrencyStatus, toSwapCurrencyStatus: SwapCurrencyStatus, - fromTokenAmount: String, + fromTokenAmount: BigDecimal, ): Either suspend fun loadFeeExtended( fromSwapCurrencyStatus: SwapCurrencyStatus, toSwapCurrencyStatus: SwapCurrencyStatus, - fromTokenAmount: String, + fromTokenAmount: BigDecimal, ): Either suspend fun sendTransfer( diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/transfer/SwapTransferInteractorImpl.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/transfer/SwapTransferInteractorImpl.kt index 2263812fe8..ef795d8ae8 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/transfer/SwapTransferInteractorImpl.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/transfer/SwapTransferInteractorImpl.kt @@ -205,15 +205,14 @@ class SwapTransferInteractorImpl @Inject constructor( override suspend fun loadFee( fromSwapCurrencyStatus: SwapCurrencyStatus, toSwapCurrencyStatus: SwapCurrencyStatus, - fromTokenAmount: String, + fromTokenAmount: BigDecimal, ): Either { - val amount = fromTokenAmount.parseBigDecimalOrNull() ?: BigDecimal.ZERO val destination = toSwapCurrencyStatus.destinationAddress() ?: return feeDataError( message = "Destination address is null", ) return getFeeUseCase( - amount = amount, + amount = fromTokenAmount, destination = destination, userWallet = fromSwapCurrencyStatus.userWallet, cryptoCurrency = fromSwapCurrencyStatus.currency, @@ -223,9 +222,8 @@ class SwapTransferInteractorImpl @Inject constructor( override suspend fun loadFeeExtended( fromSwapCurrencyStatus: SwapCurrencyStatus, toSwapCurrencyStatus: SwapCurrencyStatus, - fromTokenAmount: String, + fromTokenAmount: BigDecimal, ): Either { - val amount = fromTokenAmount.parseBigDecimalOrNull() ?: BigDecimal.ZERO val destination = toSwapCurrencyStatus.destinationAddress() ?: return feeDataError( message = "Destination address is null", ) @@ -233,7 +231,7 @@ class SwapTransferInteractorImpl @Inject constructor( val currency = fromSwapCurrencyStatus.currency val transactionData = createTransferTransactionUseCase( - amount = amount.convertToSdkAmount( + amount = fromTokenAmount.convertToSdkAmount( cryptoCurrencyStatus = fromSwapCurrencyStatus.status, ), memo = null, diff --git a/features/swap/domain/src/test/kotlin/com/tangem/feature/swap/domain/transfer/SwapTransferInteractorImplTest.kt b/features/swap/domain/src/test/kotlin/com/tangem/feature/swap/domain/transfer/SwapTransferInteractorImplTest.kt index 864296e66f..3116e627ff 100644 --- a/features/swap/domain/src/test/kotlin/com/tangem/feature/swap/domain/transfer/SwapTransferInteractorImplTest.kt +++ b/features/swap/domain/src/test/kotlin/com/tangem/feature/swap/domain/transfer/SwapTransferInteractorImplTest.kt @@ -133,7 +133,17 @@ internal class SwapTransferInteractorImplTest { every { getBalanceHidingSettingsUseCase.isBalanceHidden() } returns flowOf(true) coEvery { isAccountsModeEnabledUseCase.invokeSync() } returns true val currencyCheck = buildCurrencyCheck() - coEvery { getCurrencyCheckUseCase(any(), any(), any(), any(), any(), any(), any()) } returns currencyCheck + coEvery { + getCurrencyCheckUseCase( + userWalletId = any(), + currencyStatus = any(), + feeCurrencyStatus = any(), + amount = any(), + fee = any(), + feeCurrencyBalanceAfterTransaction = any(), + recipientAddress = any(), + ) + } returns currencyCheck coEvery { isAmountSubtractAvailableUseCase(any(), any(), any()) } returns false.right() @@ -193,7 +203,17 @@ internal class SwapTransferInteractorImplTest { every { getBalanceHidingSettingsUseCase.isBalanceHidden() } returns flowOf(true) coEvery { isAccountsModeEnabledUseCase.invokeSync() } returns true val currencyCheck = buildCurrencyCheck() - coEvery { getCurrencyCheckUseCase(any(), any(), any(), any(), any(), any(), any()) } returns currencyCheck + coEvery { + getCurrencyCheckUseCase( + userWalletId = any(), + currencyStatus = any(), + feeCurrencyStatus = any(), + amount = any(), + fee = any(), + feeCurrencyBalanceAfterTransaction = any(), + recipientAddress = any(), + ) + } returns currencyCheck coEvery { isAmountSubtractAvailableUseCase(any(), any(), any()) } returns false.right() @@ -259,7 +279,15 @@ internal class SwapTransferInteractorImplTest { every { getBalanceHidingSettingsUseCase.isBalanceHidden() } returns flowOf(false) coEvery { isAccountsModeEnabledUseCase.invokeSync() } returns false coEvery { - getCurrencyCheckUseCase(any(), any(), any(), any(), any(), any(), any()) + getCurrencyCheckUseCase( + userWalletId = any(), + currencyStatus = any(), + feeCurrencyStatus = any(), + amount = any(), + fee = any(), + feeCurrencyBalanceAfterTransaction = any(), + recipientAddress = any(), + ) } returns buildCurrencyCheck() coEvery { isAmountSubtractAvailableUseCase(any(), any(), any()) @@ -309,7 +337,7 @@ internal class SwapTransferInteractorImplTest { val result = sut.loadFee( fromSwapCurrencyStatus = fromCurrencyStatus, toSwapCurrencyStatus = toCurrencyStatus, - fromTokenAmount = "1.5", + fromTokenAmount = BigDecimal("1.5"), ) assertThat(result).isEqualTo(transactionFee.right()) @@ -365,7 +393,7 @@ internal class SwapTransferInteractorImplTest { val result = sut.loadFeeExtended( fromSwapCurrencyStatus = fromCurrencyStatus, toSwapCurrencyStatus = toCurrencyStatus, - fromTokenAmount = "2.0", + fromTokenAmount = BigDecimal("2.0"), ) assertThat(result).isEqualTo(feeExtended.right()) diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/DefaultSwapFeatureToggles.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/DefaultSwapFeatureToggles.kt index a98c00d50b..fc49fe82dc 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/DefaultSwapFeatureToggles.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/DefaultSwapFeatureToggles.kt @@ -18,7 +18,7 @@ internal class DefaultSwapFeatureToggles @Inject constructor( ) override val isSwapIntegratedApproveEnabled: Boolean = featureTogglesManager.isFeatureEnabled( - toggle = FeatureToggles.SWAP_INTEGRATED_APPROVE, + toggle = FeatureToggles.AND_15120_SWAP_INTEGRATED_APPROVE, ) override val isSwapAbEnabled: Boolean = featureTogglesManager.isFeatureEnabled( diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt index 7ca2eef0a1..59973dc978 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt @@ -2180,6 +2180,7 @@ internal class SwapModel @Inject constructor( dataState.fromSwapCurrencyStatus ?: return Either.Left(GetFeeError.UnknownError) val toSwapCurrencyStatus = dataState.toSwapCurrencyStatus ?: return Either.Left(GetFeeError.UnknownError) + val amount = lastAmount.value.parseBigDecimalOrNull() ?: return Either.Left(GetFeeError.UnknownError) val shouldTransferInsteadOfSwap = swapTransferInteractor.shouldTransferInsteadOfSwap( fromSwapCurrencyStatus.currency, toSwapCurrencyStatus.currency, @@ -2188,7 +2189,7 @@ internal class SwapModel @Inject constructor( return swapTransferInteractor.loadFee( fromSwapCurrencyStatus = fromSwapCurrencyStatus, toSwapCurrencyStatus = toSwapCurrencyStatus, - fromTokenAmount = lastAmount.value, + fromTokenAmount = amount, ).onLeft { TangemLogger.e("loadFee[transfer]: Failed to load fee with error $it") }.onRight { @@ -2202,9 +2203,7 @@ internal class SwapModel @Inject constructor( return Either.Left(GetFeeError.UnknownError) } - val amountDecimal = lastAmount.value.replace(",", ".").toBigDecimalOrNull() - ?: return Either.Left(GetFeeError.UnknownError) - val swapAmount = SwapAmount(amountDecimal, fromSwapCurrencyStatus.currency.decimals) + val swapAmount = SwapAmount(amount, fromSwapCurrencyStatus.currency.decimals) val swapDataForCall = when (quoteState.swapProvider.type) { ExchangeProviderType.DEX, ExchangeProviderType.DEX_BRIDGE -> { quoteState.swapDataModel ?: return Either.Left(GetFeeError.UnknownError) @@ -2235,6 +2234,8 @@ internal class SwapModel @Inject constructor( dataState.fromSwapCurrencyStatus ?: return Either.Left(GetFeeError.UnknownError) val toSwapCurrencyStatus = dataState.toSwapCurrencyStatus ?: return Either.Left(GetFeeError.UnknownError) + val amount = lastAmount.value.parseBigDecimalOrNull() ?: return Either.Left(GetFeeError.UnknownError) + val shouldTransferInsteadOfSwap = swapTransferInteractor.shouldTransferInsteadOfSwap( fromSwapCurrencyStatus.currency, toSwapCurrencyStatus.currency, @@ -2243,7 +2244,7 @@ internal class SwapModel @Inject constructor( return swapTransferInteractor.loadFeeExtended( fromSwapCurrencyStatus = fromSwapCurrencyStatus, toSwapCurrencyStatus = toSwapCurrencyStatus, - fromTokenAmount = lastAmount.value, + fromTokenAmount = amount, ) } val quoteState = dataState.getCurrentLoadedSwapState() ?: return Either.Left(GetFeeError.UnknownError) @@ -2252,8 +2253,7 @@ internal class SwapModel @Inject constructor( return Either.Left(GetFeeError.UnknownError) } - val amountDecimal = lastAmount.value.parseBigDecimalOrNull() ?: return Either.Left(GetFeeError.UnknownError) - val swapAmount = SwapAmount(amountDecimal, fromSwapCurrencyStatus.currency.decimals) + val swapAmount = SwapAmount(amount, fromSwapCurrencyStatus.currency.decimals) // DEX path requires a SwapDataModel. val swapDataForCall = when (quoteState.swapProvider.type) { diff --git a/gradle/tangem_dependencies.toml b/gradle/tangem_dependencies.toml index ad6ebb8cb7..9323268e46 100644 --- a/gradle/tangem_dependencies.toml +++ b/gradle/tangem_dependencies.toml @@ -5,7 +5,7 @@ # https://github.com/tangem/tangem-sdk-android/ # https://github.com/tangem/vico -tangemBlockchainSdk = "develop-1532" +tangemBlockchainSdk = "develop-1535" #tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds tangemCardSdk = "develop-620" #tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^ diff --git a/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/WalletManagerFactoryCreator.kt b/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/WalletManagerFactoryCreator.kt index 58af77dd60..1e2e3552c5 100644 --- a/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/WalletManagerFactoryCreator.kt +++ b/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/WalletManagerFactoryCreator.kt @@ -20,6 +20,7 @@ import javax.inject.Inject * [REDACTED_AUTHOR] */ +@Suppress("LongParameterList") internal class WalletManagerFactoryCreator @Inject constructor( private val accountCreator: AccountCreator, private val blockchainDataStorage: BlockchainDataStorage, @@ -41,6 +42,7 @@ internal class WalletManagerFactoryCreator @Inject constructor( isSolanaTxHistoryEnabled = featureToggleValues.isSolanaTxHistoryEnabled, isSolanaScaledUiAmountEnabled = featureToggleValues.isSolanaScaledUiAmountEnabled, isHederaErc20Enabled = featureToggleValues.isHederaErc20Enabled, + isStateOverrideGasEstimateEnabled = featureToggleValues.isStateOverrideGasEstimateEnabled, ), blockchainDataStorage = blockchainDataStorage, loggers = listOf(blockchainSDKLogger), @@ -52,5 +54,6 @@ internal class WalletManagerFactoryCreator @Inject constructor( val isSolanaScaledUiAmountEnabled: Boolean, val isYieldModeSwapEnabled: Boolean, val isHederaErc20Enabled: Boolean, + val isStateOverrideGasEstimateEnabled: Boolean, ) } \ No newline at end of file diff --git a/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/di/BlockchainSDKFactoryModule.kt b/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/di/BlockchainSDKFactoryModule.kt index 3ff97082fb..ef8a7025e7 100644 --- a/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/di/BlockchainSDKFactoryModule.kt +++ b/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/di/BlockchainSDKFactoryModule.kt @@ -23,8 +23,8 @@ import com.tangem.datasource.api.tangemTech.TangemTechApi import com.tangem.datasource.di.NetworkMoshi import com.tangem.datasource.local.config.environment.EnvironmentConfig import com.tangem.datasource.local.preferences.AppPreferencesStore -import com.tangem.utils.coroutines.AppCoroutineScope import com.tangem.libs.blockchain_sdk.BuildConfig +import com.tangem.utils.coroutines.AppCoroutineScope import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.Module import dagger.Provides @@ -110,6 +110,9 @@ internal object BlockchainSDKFactoryModule { isHederaErc20Enabled = featureTogglesManager.isFeatureEnabled( FeatureToggles.HEDERA_ERC20_ENABLED, ), + isStateOverrideGasEstimateEnabled = featureTogglesManager.isFeatureEnabled( + FeatureToggles.AND_15120_SWAP_INTEGRATED_APPROVE, + ), ), ) }