diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/AllowPermissionsHandlerImpl.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/AllowPermissionsHandlerImpl.kt index 8f73c36ee7..344a698f34 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/AllowPermissionsHandlerImpl.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/AllowPermissionsHandlerImpl.kt @@ -1,9 +1,11 @@ package com.tangem.feature.swap.domain +import java.util.Collections.synchronizedSet + class AllowPermissionsHandlerImpl : AllowPermissionsHandler { // todo maybe need to save in store - private val allowPermissionsInProgress = mutableSetOf() + private val allowPermissionsInProgress = synchronizedSet(mutableSetOf()) override fun addAddressToInProgress(tokenAddress: String) { allowPermissionsInProgress.add(tokenAddress) diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/di/SwapDomainModule.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/di/SwapDomainModule.kt index ab15afbae5..26b53125e0 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/di/SwapDomainModule.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/di/SwapDomainModule.kt @@ -12,6 +12,7 @@ import javax.inject.Singleton internal class SwapDomainModule { @Provides + @Singleton fun provideAllowPermissionsHandler(): AllowPermissionsHandler { return AllowPermissionsHandlerImpl() } 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 94bcb7958f..9acbb9438a 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 @@ -74,6 +74,7 @@ import com.tangem.feature.swap.analytics.SwapEvents import com.tangem.feature.swap.choosetoken.api.ChooseTokenBridge import com.tangem.feature.swap.component.SwapFeeSelectorBlockComponent import com.tangem.feature.swap.converters.SwapTransactionErrorStateConverter +import com.tangem.feature.swap.domain.AllowPermissionsHandler import com.tangem.feature.swap.domain.SwapInteractor import com.tangem.feature.swap.domain.TransactionFeeResult import com.tangem.feature.swap.domain.TxFeeSealedState @@ -88,6 +89,7 @@ import com.tangem.feature.swap.router.SwapNavScreen import com.tangem.feature.swap.router.SwapRouter import com.tangem.feature.swap.ui.StateBuilder import com.tangem.feature.swap.utils.formatToUIRepresentation +import com.tangem.feature.swap.utils.getContractAddress import com.tangem.features.approval.api.GiveApprovalComponent import com.tangem.features.approval.api.GiveApprovalFeatureToggles import com.tangem.features.send.v2.api.entity.FeeSelectorUM @@ -144,6 +146,7 @@ internal class SwapModel @Inject constructor( private val appsFlyerStore: AppsFlyerStore, private val holdToConfirmButtonFeatureToggles: HoldToConfirmButtonFeatureToggles, private val messageSender: UiMessageSender, + private val allowPermissionsHandler: AllowPermissionsHandler, chooseTokenBridgeFactory: ChooseTokenBridge.Factory, giveApprovalFeatureToggles: GiveApprovalFeatureToggles, ) : Model() { @@ -256,6 +259,10 @@ internal class SwapModel @Inject constructor( } override fun onApproveDone() { + val fromContractAddress = dataState.fromCryptoCurrency?.currency?.getContractAddress() + if (fromContractAddress != null) { + allowPermissionsHandler.addAddressToInProgress(fromContractAddress) + } approvalSlotNavigation.dismiss() updateWalletBalance() uiState = stateBuilder.loadingPermissionState(uiState) diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/utils/SwapUtils.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/utils/SwapUtils.kt index a0ef72bd20..3093dcb07b 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/utils/SwapUtils.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/utils/SwapUtils.kt @@ -5,6 +5,7 @@ import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.wrappedList import com.tangem.core.ui.format.bigdecimal.format import com.tangem.core.ui.format.bigdecimal.simple +import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.feature.swap.domain.models.ExpressDataError import com.tangem.feature.swap.domain.models.SwapAmount import com.tangem.feature.swap.presentation.R @@ -52,4 +53,11 @@ internal fun getExpressErrorTitle(expressDataError: ExpressDataError): TextRefer internal fun SwapAmount.formatToUIRepresentation(): String { return value.format { simple(decimals = decimals) } +} + +internal fun CryptoCurrency.getContractAddress(): String { + return when (this) { + is CryptoCurrency.Token -> this.contractAddress + is CryptoCurrency.Coin -> "0" + } } \ No newline at end of file