Updated on 2026-08-14

This commit is contained in:
Tangem 2020-09-08 17:35:39 +03:00
parent ed77fecdee
commit 51ca58d89b
5 changed files with 40 additions and 13 deletions

View file

@ -176,8 +176,8 @@ private fun handleFeeActionUi(action: FeeActionUi, sendState: SendState, state:
is ToggleFeeLayoutVisibility -> {
state.copy(visibility = if (state.visibility == View.VISIBLE) View.GONE else View.VISIBLE)
}
is ChangeSelectedFee -> state.copy(selectedFeeId = action.id)
is ChangeIncludeFee -> state.copy(includeFeeIsChecked = action.isChecked)
is ChangeSelectedFee -> state.copy(feeType = action.feeType)
is ChangeIncludeFee -> state.copy(feeIsIncluded = action.isIncluded)
}
return updateLastState(sendState.copy(feeLayoutState = result), result)
}

View file

@ -50,6 +50,6 @@ sealed class AmountActionUi : SendScreenActionUi {
// Fee
sealed class FeeActionUi : SendScreenActionUi {
object ToggleFeeLayoutVisibility : FeeActionUi()
data class ChangeSelectedFee(val id: Int) : FeeActionUi()
class ChangeIncludeFee(val isChecked: Boolean) : FeeActionUi()
data class ChangeSelectedFee(val feeType: FeeType) : FeeActionUi()
class ChangeIncludeFee(val isIncluded: Boolean) : FeeActionUi()
}

View file

@ -1,8 +1,8 @@
package com.tangem.tap.features.send.redux
import android.view.View
import com.tangem.blockchain.common.AmountType
import com.tangem.tap.common.entities.TapCurrency
import com.tangem.wallet.R
import org.rekotlin.StateType
import java.math.BigDecimal
@ -86,6 +86,7 @@ data class Value<T>(
data class AmountState(
val etAmountFieldValue: String = BigDecimal.ZERO.toPlainString(),
val typeOfAmount: AmountType = AmountType.Coin,
val cursorAtTheSamePosition: Boolean = true,
val amountToSendCrypto: BigDecimal = BigDecimal.ZERO,
val balance: BigDecimal = BigDecimal.ZERO,
@ -93,8 +94,12 @@ data class AmountState(
val amountIsOverBalance: Boolean = false
) : StateType
enum class FeeType {
LOW, NORMAL, PRIORITY
}
data class FeeLayoutState(
val visibility: Int = View.GONE,
val selectedFeeId: Int = R.id.chipNormal,
val includeFeeIsChecked: Boolean = false
val feeType: FeeType = FeeType.NORMAL,
val feeIsIncluded: Boolean = false
) : StateType

View file

@ -17,6 +17,7 @@ import com.tangem.tap.features.send.BaseStoreFragment
import com.tangem.tap.features.send.redux.AddressPayIdActionUi.*
import com.tangem.tap.features.send.redux.AmountActionUi.*
import com.tangem.tap.features.send.redux.FeeActionUi.*
import com.tangem.tap.features.send.redux.FeeType
import com.tangem.tap.features.send.redux.MainCurrencyType
import com.tangem.tap.features.send.redux.ReleaseSendState
import com.tangem.tap.features.send.ui.stateSubscribers.SendStateSubscriber
@ -132,7 +133,7 @@ class SendFragment : BaseStoreFragment(R.layout.fragment_send) {
store.dispatch(ToggleFeeLayoutVisibility)
}
chipGroup.setOnCheckedChangeListener { group, checkedId ->
store.dispatch(ChangeSelectedFee(checkedId))
store.dispatch(ChangeSelectedFee(FeeUiHelper.idToFee(checkedId)))
}
swIncludeFee.setOnCheckedChangeListener { btn, isChecked ->
store.dispatch(ChangeIncludeFee(isChecked))
@ -172,5 +173,26 @@ fun EditText.inputedTextAsFlow(): Flow<String> = callbackFlow {
awaitClose { removeTextChangedListener(watcher) }
}
class FeeUiHelper {
companion object {
fun feeToId(fee: FeeType): Int {
return when (fee) {
FeeType.LOW -> R.id.chipLow
FeeType.NORMAL -> R.id.chipNormal
FeeType.PRIORITY -> R.id.chipPriority
}
}
fun idToFee(id: Int): FeeType {
return when (id) {
R.id.chipLow -> FeeType.LOW
R.id.chipNormal -> FeeType.NORMAL
R.id.chipPriority -> FeeType.PRIORITY
else -> FeeType.NORMAL
}
}
}
}

View file

@ -12,6 +12,7 @@ import com.tangem.tap.features.send.redux.AddressPayIdVerifyAction.FailReason
import com.tangem.tap.features.send.redux.AmountState
import com.tangem.tap.features.send.redux.FeeLayoutState
import com.tangem.tap.features.send.redux.SendState
import com.tangem.tap.features.send.ui.FeeUiHelper
import com.tangem.tap.features.send.ui.SendFragment
import com.tangem.wallet.R
import kotlinx.android.synthetic.main.btn_expand_collapse.*
@ -74,13 +75,12 @@ class SendStateSubscriber(fragment: Fragment) : FragmentStateSubscriber<SendStat
fg.llFeeContainer.visibility = layoutState.visibility
}
if (fg.swIncludeFee.isChecked != layoutState.includeFeeIsChecked) {
fg.swIncludeFee.isChecked = layoutState.includeFeeIsChecked
if (fg.swIncludeFee.isChecked != layoutState.feeIsIncluded) {
fg.swIncludeFee.isChecked = layoutState.feeIsIncluded
}
if (fg.chipGroup.checkedChipId != layoutState.selectedFeeId) {
fg.chipGroup.check(layoutState.selectedFeeId)
}
val chipId = FeeUiHelper.feeToId(layoutState.feeType)
if (fg.chipGroup.checkedChipId != chipId) fg.chipGroup.check(chipId)
}
private fun handleAmountState(fg: Fragment, state: AmountState) {