From 54d38c6bf01fe55bde64f7046de0fcf1041584c8 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 24 Apr 2024 14:45:13 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../impl/presentation/state/SendStateFactory.kt | 13 ++++++++++--- .../send/impl/presentation/state/SendUiState.kt | 2 +- .../state/confirm/SendConfirmStateConverter.kt | 2 +- .../presentation/state/fee/FeeStateFactory.kt | 9 +++++++++ .../presentation/viewmodel/SendViewModel.kt | 17 ++++++++--------- gradle/dependencies.toml | 2 +- 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendStateFactory.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendStateFactory.kt index b31e9559be..c8d7369fbd 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendStateFactory.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendStateFactory.kt @@ -15,6 +15,7 @@ import com.tangem.features.send.impl.R import com.tangem.features.send.impl.presentation.domain.AvailableWallet import com.tangem.features.send.impl.presentation.state.amount.SendAmountStateConverter import com.tangem.features.send.impl.presentation.state.confirm.SendConfirmStateConverter +import com.tangem.features.send.impl.presentation.state.fee.FeeSelectorState import com.tangem.features.send.impl.presentation.state.fee.SendFeeStateConverter import com.tangem.features.send.impl.presentation.state.fields.SendAmountFieldConverter import com.tangem.features.send.impl.presentation.state.recipient.SendRecipientHistoryListConverter @@ -263,7 +264,7 @@ internal class SendStateFactory( return state.copy( sendState = state.sendState?.copy( isSending = isSending, - isPrimaryButtonEnabled = !isSending, + isPrimaryButtonEnabled = isPrimaryButtonEnabled(state, state.sendState.notifications), ), ) } @@ -285,10 +286,9 @@ internal class SendStateFactory( fun getSendNotificationState(notifications: ImmutableList): SendUiState { val state = currentStateProvider() val sendState = state.sendState ?: return state - val hasErrorNotifications = notifications.any { it is SendNotification.Error } return state.copy( sendState = sendState.copy( - isPrimaryButtonEnabled = !hasErrorNotifications, + isPrimaryButtonEnabled = isPrimaryButtonEnabled(state, notifications), notifications = notifications, showTapHelp = sendState.showTapHelp && notifications.isEmpty(), ), @@ -302,5 +302,12 @@ internal class SendStateFactory( sendState = sendState.copy(showTapHelp = false), ) } + + private fun isPrimaryButtonEnabled(state: SendUiState, notifications: ImmutableList): Boolean { + val sendState = state.sendState ?: return false + val feeState = state.feeState ?: return false + val hasErrorNotifications = notifications.any { it is SendNotification.Error } + return !hasErrorNotifications && !sendState.isSending && feeState.feeSelectorState is FeeSelectorState.Content + } //endregion } \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendUiState.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendUiState.kt index 2b14283039..043f45837f 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendUiState.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendUiState.kt @@ -84,7 +84,7 @@ internal sealed class SendStates { @Stable data class SendState( override val type: SendUiStateType = SendUiStateType.Send, - override val isPrimaryButtonEnabled: Boolean = true, + override val isPrimaryButtonEnabled: Boolean = false, val isSending: Boolean, val isSuccess: Boolean, val transactionDate: Long, diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendConfirmStateConverter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendConfirmStateConverter.kt index e202bf5e25..7935da04c8 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendConfirmStateConverter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendConfirmStateConverter.kt @@ -10,7 +10,7 @@ internal class SendConfirmStateConverter( ) : Converter { override fun convert(value: Unit): SendStates.SendState { return SendStates.SendState( - isPrimaryButtonEnabled = true, + isPrimaryButtonEnabled = false, isSending = false, isSuccess = false, transactionDate = 0L, diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeStateFactory.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeStateFactory.kt index a74613acd3..b88d51c2a9 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeStateFactory.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/FeeStateFactory.kt @@ -45,6 +45,9 @@ internal class FeeStateFactory( val state = currentStateProvider() val feeState = state.feeState ?: return state return state.copy( + sendState = state.sendState?.copy( + isPrimaryButtonEnabled = false, + ), feeState = feeState.copy( feeSelectorState = if (feeState.feeSelectorState is FeeSelectorState.Content) { feeState.feeSelectorState @@ -77,6 +80,9 @@ internal class FeeStateFactory( val fee = feeConverter.convert(updatedFeeSelectorState) return state.copy( + sendState = state.sendState?.copy( + isPrimaryButtonEnabled = true, + ), feeState = feeState.copy( feeSelectorState = updatedFeeSelectorState, fee = fee, @@ -91,6 +97,9 @@ internal class FeeStateFactory( feeState = state.feeState?.copy( feeSelectorState = FeeSelectorState.Error, ), + sendState = state.sendState?.copy( + isPrimaryButtonEnabled = false, + ), ) } diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt index 1eba5568fa..94620f127c 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt @@ -692,9 +692,6 @@ internal class SendViewModel @Inject constructor( updateNotifications() updateFeeNotifications() }.saveIn(feeJobHolder) - .invokeOnCompletion { - // todo - } } private fun onFeeLoadFailed(isShowStatus: Boolean) { @@ -713,12 +710,14 @@ internal class SendViewModel @Inject constructor( val recipientState = uiState.recipientState ?: return null val amount = amountState.amountTextField.cryptoAmount.value ?: return null - return getFeeUseCase.invoke( - amount = amount, - destination = recipientState.addressTextField.value, - userWallet = userWallet, - cryptoCurrency = cryptoCurrency, - ) + return feeCryptoCurrencyStatus?.let { feeCurrencyStatus -> + getFeeUseCase.invoke( + amount = amount, + destination = recipientState.addressTextField.value, + userWallet = userWallet, + cryptoCurrency = feeCurrencyStatus.currency, + ) + } } // endregion diff --git a/gradle/dependencies.toml b/gradle/dependencies.toml index eec9a20c7b..603776f9f0 100644 --- a/gradle/dependencies.toml +++ b/gradle/dependencies.toml @@ -85,7 +85,7 @@ leakcanary = "2.13" # endregion Other libraries # region Tangem -tangemBlockchainSdk = "release-app_5.9-605" +tangemBlockchainSdk = "release-app_5.9-608" #tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds tangemCardSdk = "release-app_5.9-343" #tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^