diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/TangemBottomSheetConfig.kt b/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/TangemBottomSheetConfig.kt index 002cecf115..d99aefacb5 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/TangemBottomSheetConfig.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/TangemBottomSheetConfig.kt @@ -10,10 +10,15 @@ package com.tangem.core.ui.components.bottomsheets data class TangemBottomSheetConfig( val isShown: Boolean, val onDismissRequest: () -> Unit, + val dismissOnClickOutside: () -> Boolean = { true }, val content: TangemBottomSheetConfigContent, ) { companion object { - val Empty = TangemBottomSheetConfig(false, {}, TangemBottomSheetConfigContent.Empty) + val Empty = TangemBottomSheetConfig( + isShown = false, + onDismissRequest = {}, + content = TangemBottomSheetConfigContent.Empty, + ) } } \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/modal/TangemModalBottomSheetWithFooter.kt b/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/modal/TangemModalBottomSheetWithFooter.kt index 6506a16d14..8b2c012fc1 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/modal/TangemModalBottomSheetWithFooter.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/modal/TangemModalBottomSheetWithFooter.kt @@ -88,7 +88,17 @@ inline fun DefaultModalBottomSheetW noinline footer: @Composable (BoxScope.(T) -> Unit)?, ) { var isVisible by remember { mutableStateOf(value = config.isShown) } - val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = skipPartiallyExpanded) + val sheetState = rememberModalBottomSheetState( + skipPartiallyExpanded = skipPartiallyExpanded, + confirmValueChange = { sheetValue -> + if (config.dismissOnClickOutside().not()) { + // Ignore transitions to hidden (prevents dismiss on outside click/back press) + sheetValue != SheetValue.Hidden + } else { + true + } + }, + ) if (isVisible && config.content is T) { BasicModalBottomSheetWithFooter( diff --git a/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/FeeExtensions.kt b/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/FeeExtensions.kt index 799506d8f2..6df54ae127 100644 --- a/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/FeeExtensions.kt +++ b/domain/yield-supply/src/main/java/com/tangem/domain/yield/supply/FeeExtensions.kt @@ -6,7 +6,7 @@ import java.math.BigInteger import java.math.RoundingMode private val HUNDRED_PERCENT = 100.toBigInteger() // base 100% -val INCREASE_GAS_LIMIT_FOR_SUPPLY = 112.toBigInteger() // 12% increase +val INCREASE_GAS_LIMIT_FOR_SUPPLY = 120.toBigInteger() // 20% increase fun Fee.fixFee(cryptoCurrency: CryptoCurrency, gasLimit: BigInteger): Fee = when (this) { is Fee.Ethereum.Legacy -> copy( diff --git a/domain/yield-supply/src/test/java/com/tangem/domain/yield/supply/YieldSupplyEstimateEnterFeeUseCaseTest.kt b/domain/yield-supply/src/test/java/com/tangem/domain/yield/supply/YieldSupplyEstimateEnterFeeUseCaseTest.kt index 20c7619b9e..38e789a341 100644 --- a/domain/yield-supply/src/test/java/com/tangem/domain/yield/supply/YieldSupplyEstimateEnterFeeUseCaseTest.kt +++ b/domain/yield-supply/src/test/java/com/tangem/domain/yield/supply/YieldSupplyEstimateEnterFeeUseCaseTest.kt @@ -314,9 +314,9 @@ class YieldSupplyEstimateEnterFeeUseCaseTest { val deployFee = txs.first().fee as Fee.Ethereum.EIP1559 val approveFee = txs[1].fee as Fee.Ethereum.EIP1559 val enterFee = txs.last().fee as Fee.Ethereum.EIP1559 - Truth.assertThat(deployFee.gasLimit).isEqualTo(BigInteger.valueOf(1_120)) - Truth.assertThat(approveFee.gasLimit).isEqualTo(BigInteger.valueOf(2_240)) - Truth.assertThat(enterFee.gasLimit).isEqualTo(BigInteger.valueOf(3_360)) + Truth.assertThat(deployFee.gasLimit).isEqualTo(BigInteger.valueOf(1_200)) + Truth.assertThat(approveFee.gasLimit).isEqualTo(BigInteger.valueOf(2_400)) + Truth.assertThat(enterFee.gasLimit).isEqualTo(BigInteger.valueOf(3_600)) } @Test @@ -353,9 +353,9 @@ class YieldSupplyEstimateEnterFeeUseCaseTest { val deployFee = txs.first().fee as Fee.Ethereum.Legacy val approveFee = txs[1].fee as Fee.Ethereum.Legacy val enterFee = txs.last().fee as Fee.Ethereum.Legacy - Truth.assertThat(deployFee.gasLimit).isEqualTo(BigInteger.valueOf(1_120)) - Truth.assertThat(approveFee.gasLimit).isEqualTo(BigInteger.valueOf(2_240)) - Truth.assertThat(enterFee.gasLimit).isEqualTo(BigInteger.valueOf(3_360)) + Truth.assertThat(deployFee.gasLimit).isEqualTo(BigInteger.valueOf(1_200)) + Truth.assertThat(approveFee.gasLimit).isEqualTo(BigInteger.valueOf(2_400)) + Truth.assertThat(enterFee.gasLimit).isEqualTo(BigInteger.valueOf(3_600)) } private fun getDeployTx() = uncompiled( diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/active/YieldSupplyActiveEntryComponent.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/active/YieldSupplyActiveEntryComponent.kt index 59616762c7..89dcded7bf 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/active/YieldSupplyActiveEntryComponent.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/active/YieldSupplyActiveEntryComponent.kt @@ -2,6 +2,7 @@ package com.tangem.features.yield.supply.impl.subcomponents.active import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.arkivanov.decompose.extensions.compose.subscribeAsState import com.arkivanov.decompose.router.stack.StackNavigation import com.arkivanov.decompose.router.stack.childStack @@ -59,9 +60,10 @@ internal class YieldSupplyActiveEntryComponent( @Composable override fun BottomSheet() { val stackState by innerStack.subscribeAsState() - + val isTransactionInProgress by model.isTransactionInProgressFlow.collectAsStateWithLifecycle() YieldSupplyActiveEntryBottomSheet( stackState = stackState, + dismissOnClickOutside = { !isTransactionInProgress }, onDismiss = ::dismiss, ) } diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/active/model/YieldSupplyActiveEntryModel.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/active/model/YieldSupplyActiveEntryModel.kt index 02fc956678..9f7ca52491 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/active/model/YieldSupplyActiveEntryModel.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/active/model/YieldSupplyActiveEntryModel.kt @@ -11,6 +11,9 @@ import com.tangem.features.yield.supply.impl.subcomponents.approve.YieldSupplyAp import com.tangem.features.yield.supply.impl.subcomponents.stopearning.YieldSupplyStopEarningComponent import com.tangem.utils.TangemBlogUrlBuilder import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.update import javax.inject.Inject @ModelScoped @@ -25,15 +28,25 @@ internal class YieldSupplyActiveEntryModel @Inject constructor( private val params = paramsContainer.require() + val isTransactionInProgressFlow: StateFlow + field = MutableStateFlow(false) + override fun onStopEarning() { router.push(YieldSupplyActiveRoute.Exit) } override fun onBackClick() { - router.pop() + if (!isTransactionInProgressFlow.value) { + router.pop() + } + } + + override fun onTransactionProgress(inProgress: Boolean) { + isTransactionInProgressFlow.update { inProgress } } override fun onTransactionSent() { + isTransactionInProgressFlow.update { false } params.onDismiss() } diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/active/ui/YieldSupplyActiveEntryBottomSheet.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/active/ui/YieldSupplyActiveEntryBottomSheet.kt index 124b736fa4..e4f47efa5e 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/active/ui/YieldSupplyActiveEntryBottomSheet.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/active/ui/YieldSupplyActiveEntryBottomSheet.kt @@ -14,12 +14,14 @@ import com.tangem.features.yield.supply.impl.subcomponents.active.model.YieldSup @Composable internal fun YieldSupplyActiveEntryBottomSheet( stackState: ChildStack, + dismissOnClickOutside: () -> Boolean, onDismiss: () -> Unit, ) { TangemModalBottomSheetWithFooter( config = TangemBottomSheetConfig( isShown = true, onDismissRequest = onDismiss, + dismissOnClickOutside = dismissOnClickOutside, content = TangemBottomSheetConfigContent.Empty, ), containerColor = TangemTheme.colors.background.tertiary, diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/approve/YieldSupplyApproveComponent.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/approve/YieldSupplyApproveComponent.kt index 3c1de839bb..c712301a01 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/approve/YieldSupplyApproveComponent.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/approve/YieldSupplyApproveComponent.kt @@ -106,6 +106,7 @@ internal class YieldSupplyApproveComponent( interface ModelCallback { fun onBackClick() + fun onTransactionProgress(inProgress: Boolean) fun onTransactionSent() } } \ No newline at end of file diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/approve/model/YieldSupplyApproveModel.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/approve/model/YieldSupplyApproveModel.kt index bb92b7315b..e2c89da4c0 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/approve/model/YieldSupplyApproveModel.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/approve/model/YieldSupplyApproveModel.kt @@ -117,6 +117,8 @@ internal class YieldSupplyApproveModel @Inject constructor( } fun onClick() { + params.callback.onTransactionProgress(true) + val yieldSupplyFeeUM = uiState.value.yieldSupplyFeeUM as? YieldSupplyFeeUM.Content ?: return uiState.update(YieldSupplyTransactionInProgressTransformer) @@ -153,6 +155,7 @@ internal class YieldSupplyApproveModel @Inject constructor( } }, ) + params.callback.onTransactionProgress(false) }, ifRight = { val event = AnalyticsParam.TxSentFrom.Earning( diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/YieldSupplyStartEarningEntryComponent.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/YieldSupplyStartEarningEntryComponent.kt index 77763ea8fc..850ee680cd 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/YieldSupplyStartEarningEntryComponent.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/YieldSupplyStartEarningEntryComponent.kt @@ -2,6 +2,7 @@ package com.tangem.features.yield.supply.impl.subcomponents.startearning import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.arkivanov.decompose.extensions.compose.subscribeAsState import com.arkivanov.decompose.router.stack.StackNavigation import com.arkivanov.decompose.router.stack.childStack @@ -56,9 +57,11 @@ internal class YieldSupplyStartEarningEntryComponent( @Composable override fun BottomSheet() { val stackState by innerStack.subscribeAsState() + val uiState by model.uiState.collectAsStateWithLifecycle() YieldSupplyStartEarningBottomSheet( stackState = stackState, + dismissOnClickOutside = { !uiState.isTransactionSending }, onDismiss = ::dismiss, ) } diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/model/YieldSupplyStartEarningEntryModel.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/model/YieldSupplyStartEarningEntryModel.kt index 2037750020..696f86af29 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/model/YieldSupplyStartEarningEntryModel.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/model/YieldSupplyStartEarningEntryModel.kt @@ -8,8 +8,8 @@ import com.tangem.core.decompose.navigation.Router import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.wrappedList -import com.tangem.features.yield.supply.impl.R import com.tangem.features.yield.supply.api.analytics.YieldSupplyAnalytics +import com.tangem.features.yield.supply.impl.R import com.tangem.features.yield.supply.impl.common.entity.YieldSupplyActionUM import com.tangem.features.yield.supply.impl.common.entity.YieldSupplyFeeUM import com.tangem.features.yield.supply.impl.subcomponents.feepolicy.YieldSupplyFeePolicyComponent @@ -54,7 +54,9 @@ internal class YieldSupplyStartEarningEntryModel @Inject constructor( } override fun onBackClick() { - router.pop() + if (!uiState.value.isTransactionSending) { + router.pop() + } } override fun onFeePolicyClick() { diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/ui/YieldSupplyStartEarningBottomSheet.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/ui/YieldSupplyStartEarningBottomSheet.kt index aba821a580..6a7550515c 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/ui/YieldSupplyStartEarningBottomSheet.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/startearning/ui/YieldSupplyStartEarningBottomSheet.kt @@ -14,12 +14,14 @@ import com.tangem.features.yield.supply.impl.subcomponents.startearning.YieldSup @Composable internal fun YieldSupplyStartEarningBottomSheet( stackState: ChildStack, + dismissOnClickOutside: () -> Boolean, onDismiss: () -> Unit, ) { TangemModalBottomSheetWithFooter( config = TangemBottomSheetConfig( isShown = true, onDismissRequest = onDismiss, + dismissOnClickOutside = dismissOnClickOutside, content = TangemBottomSheetConfigContent.Empty, ), containerColor = TangemTheme.colors.background.tertiary, diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/YieldSupplyStopEarningComponent.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/YieldSupplyStopEarningComponent.kt index 2379649d45..e74a248197 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/YieldSupplyStopEarningComponent.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/YieldSupplyStopEarningComponent.kt @@ -107,6 +107,7 @@ internal class YieldSupplyStopEarningComponent( interface ModelCallback { fun onBackClick() + fun onTransactionProgress(inProgress: Boolean) fun onTransactionSent() } } \ No newline at end of file diff --git a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/model/YieldSupplyStopEarningModel.kt b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/model/YieldSupplyStopEarningModel.kt index c9dc0ec5fd..13daef75cc 100644 --- a/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/model/YieldSupplyStopEarningModel.kt +++ b/features/yield-supply/impl/src/main/java/com/tangem/features/yield/supply/impl/subcomponents/stopearning/model/YieldSupplyStopEarningModel.kt @@ -126,6 +126,8 @@ internal class YieldSupplyStopEarningModel @Inject constructor( } fun onClick() { + params.callback.onTransactionProgress(true) + val yieldSupplyFeeUM = uiState.value.yieldSupplyFeeUM as? YieldSupplyFeeUM.Content ?: return analytics.send( YieldSupplyAnalytics.ButtonStopEarning( @@ -163,6 +165,7 @@ internal class YieldSupplyStopEarningModel @Inject constructor( } }, ) + params.callback.onTransactionProgress(false) }, ifRight = { onStopEarningTransactionSuccess()