Updated on 2026-08-14

This commit is contained in:
Tangem 2021-09-09 21:37:07 +03:00
parent 7e39873b23
commit 35ac528768
6 changed files with 30 additions and 24 deletions

View file

@ -1,3 +1,17 @@
package com.tangem.tap.common.entities
open class Button(val enabled: Boolean)
import com.tangem.tap.common.toggleWidget.ProgressState
import com.tangem.tap.features.send.redux.states.ButtonState
open class Button(val enabled: Boolean)
open class IndeterminateProgressButton(
val state: ButtonState
) : Button(state != ButtonState.DISABLED) {
val progressState: ProgressState
get() = when (state) {
ButtonState.PROGRESS -> ProgressState.Progress()
else -> ProgressState.None
}
}

View file

@ -11,7 +11,7 @@ import com.tangem.tap.domain.TapError
import com.tangem.tap.domain.configurable.warningMessage.WarningMessage
import com.tangem.tap.features.send.redux.states.FeeType
import com.tangem.tap.features.send.redux.states.MainCurrencyType
import com.tangem.tap.features.send.redux.states.SendButtonState
import com.tangem.tap.features.send.redux.states.ButtonState
import com.tangem.wallet.R
import org.rekotlin.Action
import java.math.BigDecimal
@ -137,7 +137,7 @@ sealed class SendActionUi : SendScreenActionUi {
sealed class SendAction : SendScreenAction {
data class ChangeSendButtonState(val state: SendButtonState) : SendAction()
data class ChangeSendButtonState(val state: ButtonState) : SendAction()
object SendSuccess : SendAction(), ToastNotificationAction {
override val messageResource: Int = R.string.send_transaction_success
}

View file

@ -23,7 +23,7 @@ import com.tangem.tap.features.send.redux.*
import com.tangem.tap.features.send.redux.FeeAction.RequestFee
import com.tangem.tap.features.send.redux.states.ExternalTransactionData
import com.tangem.tap.features.send.redux.states.MainCurrencyType
import com.tangem.tap.features.send.redux.states.SendButtonState
import com.tangem.tap.features.send.redux.states.ButtonState
import com.tangem.tap.features.send.redux.states.TransactionExtrasState
import com.tangem.tap.features.wallet.redux.WalletAction
import com.tangem.tap.scope
@ -121,7 +121,7 @@ private fun sendTransaction(
externalTransactionData: ExternalTransactionData?,
dispatch: (Action) -> Unit,
) {
dispatch(SendAction.ChangeSendButtonState(SendButtonState.PROGRESS))
dispatch(SendAction.ChangeSendButtonState(ButtonState.PROGRESS))
var txData = walletManager.createTransaction(amountToSend, feeAmount, destinationAddress)
transactionExtras.xlmMemo?.memo?.let { txData = txData.copy(extras = StellarTransactionExtras(it)) }
@ -236,7 +236,7 @@ private fun sendTransaction(
}
}
}
dispatch(SendAction.ChangeSendButtonState(SendButtonState.ENABLED))
dispatch(SendAction.ChangeSendButtonState(ButtonState.ENABLED))
}
}
}

View file

@ -2,6 +2,7 @@ package com.tangem.tap.features.send.redux.reducers
import com.tangem.blockchain.common.AmountType
import com.tangem.tap.common.CurrencyConverter
import com.tangem.tap.common.entities.IndeterminateProgressButton
import com.tangem.tap.features.send.redux.*
import com.tangem.tap.features.send.redux.states.ExternalTransactionData
import com.tangem.tap.features.send.redux.states.IdStateHolder
@ -41,7 +42,9 @@ class SendScreenReducer {
private class SendReducer : SendInternalReducer {
override fun handle(action: SendScreenAction, sendState: SendState): SendState {
val result = when (action) {
is SendAction.ChangeSendButtonState -> sendState.copy(sendButtonState = action.state)
is SendAction.ChangeSendButtonState -> {
sendState.copy(sendButtonState = IndeterminateProgressButton(action.state))
}
is SendAction.Dialog.TezosWarningDialog -> sendState.copy(dialog = action)
is SendAction.Dialog.SendTransactionFails -> sendState.copy(dialog = action)
is SendAction.Dialog.Hide -> sendState.copy(dialog = null)

View file

@ -5,6 +5,7 @@ import com.tangem.blockchain.common.AmountType
import com.tangem.blockchain.common.WalletManager
import com.tangem.common.extensions.isZero
import com.tangem.tap.common.CurrencyConverter
import com.tangem.tap.common.entities.IndeterminateProgressButton
import com.tangem.tap.common.entities.TapCurrency
import com.tangem.tap.common.redux.global.StateDialog
import com.tangem.tap.common.text.DecimalDigitsInputFilter
@ -39,7 +40,7 @@ data class SendState(
val feeState: FeeState = FeeState(),
val receiptState: ReceiptState = ReceiptState(),
val sendWarningsList: List<WarningMessage> = listOf(),
val sendButtonState: SendButtonState = SendButtonState.DISABLED,
val sendButtonState: IndeterminateProgressButton = IndeterminateProgressButton(ButtonState.DISABLED),
val dialog: StateDialog? = null,
val externalTransactionData: ExternalTransactionData? = null
) : SendScreenState {
@ -87,7 +88,7 @@ data class SendState(
}
}
fun getButtonState(): SendButtonState = if (isReadyToSend()) SendButtonState.ENABLED else SendButtonState.DISABLED
fun getButtonState(): ButtonState = if (isReadyToSend()) ButtonState.ENABLED else ButtonState.DISABLED
fun getTotalAmountToSend(value: BigDecimal = amountState.amountToSendCrypto): BigDecimal {
val needToExtractFee = amountState.isCoinAmount() && feeState.feeIsIncluded
@ -117,7 +118,7 @@ data class SendState(
}
}
enum class SendButtonState {
enum class ButtonState {
ENABLED, DISABLED, PROGRESS
}

View file

@ -116,20 +116,8 @@ class SendStateSubscriber(fragment: BaseStoreFragment) : FragmentStateSubscriber
}
}
when (state.sendButtonState) {
SendButtonState.ENABLED -> {
fg.btnSend.isEnabled = true
sendFragment.sendBtn.changeState(ProgressState.None)
}
SendButtonState.DISABLED -> {
fg.btnSend.isEnabled = false
sendFragment.sendBtn.changeState(ProgressState.None)
}
SendButtonState.PROGRESS -> {
fg.btnSend.isEnabled = true
sendFragment.sendBtn.changeState(ProgressState.Progress())
}
}
sendFragment.sendBtn.changeState(state.sendButtonState.progressState)
sendFragment.sendBtn.mainView.isEnabled = state.sendButtonState.enabled
val rv = fg.rv_warning_messages
val adapter = rv.adapter as? WarningMessagesAdapter ?: return