Updated on 2026-08-14

This commit is contained in:
Tangem 2020-09-14 23:36:05 +03:00
parent deee4fe183
commit 957bc23951
7 changed files with 43 additions and 28 deletions

View file

@ -3,10 +3,10 @@ package com.tangem.tap.features.send.redux.reducers
import com.tangem.blockchain.common.WalletManager
import com.tangem.tap.common.CurrencyConverter
import com.tangem.tap.features.send.redux.*
import com.tangem.tap.features.send.redux.states.IdStateHolder
import com.tangem.tap.features.send.redux.states.SendState
import com.tangem.tap.store
import org.rekotlin.Action
import org.rekotlin.StateType
import timber.log.Timber
import java.math.BigDecimal
@ -34,7 +34,7 @@ class SendReducer {
val newState = reducer.handle(action, sendState).copy(sendButtonIsEnabled = sendState.isReadyToSend())
Timber.i("${newState.lastChangedStateType}.")
Timber.i("${newState.lastChangedStates}.")
return newState
}
@ -63,5 +63,7 @@ private class PrepareSendScreenStatesReducer : SendInternalReducer {
}
}
internal fun updateLastState(sendState: SendState, lastChangedState: StateType): SendState =
sendState.copy(lastChangedStateType = lastChangedState)
internal fun updateLastState(sendState: SendState, lastChangedState: IdStateHolder): SendState {
sendState.lastChangedStates.add(lastChangedState.stateId)
return sendState
}

View file

@ -1,7 +1,6 @@
package com.tangem.tap.features.send.redux.states
import com.tangem.tap.features.send.redux.AddressPayIdVerifyAction
import org.rekotlin.StateType
data class AddressPayIdState(
val etFieldValue: String? = null,
@ -10,8 +9,9 @@ data class AddressPayIdState(
val recipientWalletAddress: String? = null,
val error: AddressPayIdVerifyAction.Error? = null,
val truncateHandler: ((String) -> String)? = null,
val pasteIsEnabled: Boolean = false
) : StateType {
val pasteIsEnabled: Boolean = false,
override val stateId: StateId = StateId.ADDRESS_PAY_ID
) : SendScreenState {
fun isReady(): Boolean = error == null && recipientWalletAddress?.isNotEmpty() ?: false

View file

@ -2,7 +2,6 @@ package com.tangem.tap.features.send.redux.states
import com.tangem.blockchain.common.Amount
import com.tangem.tap.features.send.redux.FeeAction
import org.rekotlin.StateType
import java.math.BigDecimal
/**
@ -20,8 +19,9 @@ data class FeeState(
val mainLayoutIsVisible: Boolean = false,
val controlsLayoutIsVisible: Boolean = true,
val feeChipGroupIsVisible: Boolean = true,
val error: FeeAction.Error? = null
) : StateType {
val error: FeeAction.Error? = null,
override val stateId: StateId = StateId.FEE
) : SendScreenState {
fun isReady(): Boolean = error == null && currentFee != null
fun getCurrentFee(): BigDecimal = currentFee?.value?.value ?: BigDecimal.ZERO

View file

@ -1,7 +1,5 @@
package com.tangem.tap.features.send.redux.states
import org.rekotlin.StateType
// Shows only one type of the layout
enum class ReceiptLayoutType {
UNKNOWN, FIAT, CRYPTO, TOKEN_FIAT, TOKEN_CRYPTO
@ -14,7 +12,8 @@ data class ReceiptState(
val tokenFiat: ReceiptTokenFiat? = null,
val tokenCrypto: ReceiptTokenCrypto? = null,
val mainCurrencyType: Value<MainCurrencyType>? = null,
) : StateType
override val stateId: StateId = StateId.RECEIPT
) : SendScreenState
data class ReceiptSymbols(
val fiat: String,

View file

@ -14,17 +14,29 @@ import java.math.BigDecimal
/**
[REDACTED_AUTHOR]
*/
interface IdStateHolder {
val stateId: StateId
}
enum class StateId {
SEND_SCREEN, ADDRESS_PAY_ID, AMOUNT, FEE, RECEIPT
}
interface SendScreenState : StateType, IdStateHolder
data class SendState(
val amount: Amount? = null,
val walletManager: WalletManager? = null,
val currencyConverter: CurrencyConverter = CurrencyConverter(BigDecimal.ONE),
val lastChangedStateType: StateType = NoneState(),
val lastChangedStates: LinkedHashSet<StateId> = linkedSetOf(),
val addressPayIdState: AddressPayIdState = AddressPayIdState(),
val amountState: AmountState = AmountState(),
val feeState: FeeState = FeeState(),
val receiptState: ReceiptState = ReceiptState(),
val sendButtonIsEnabled: Boolean = false,
) : StateType {
override val stateId: StateId = StateId.SEND_SCREEN
) : SendScreenState {
fun isReadyToSend(): Boolean {
val sendState = store.state.sendState
@ -39,8 +51,6 @@ data class SendState(
}
}
class NoneState : StateType
data class AmountState(
val viewAmountValue: String = BigDecimal.ZERO.toPlainString(),
val viewBalanceValue: String = BigDecimal.ZERO.toPlainString(),
@ -50,8 +60,9 @@ data class AmountState(
val balanceCrypto: BigDecimal = BigDecimal.ZERO,
val cursorAtTheSamePosition: Boolean = true,
val maxLengthOfAmount: Int = 2,
val error: AmountAction.Error? = null
) : StateType {
val error: AmountAction.Error? = null,
override val stateId: StateId = StateId.AMOUNT
) : SendScreenState {
fun isReady(): Boolean = error == null && !amountToSendCrypto.isZero()
}

View file

@ -92,12 +92,12 @@ class SendFragment : BaseStoreFragment(R.layout.fragment_send) {
store.dispatch(ChangeAddressOrPayId(scannedCode))
store.dispatch(TruncateOrRestore(!etAddressOrPayId.isFocused))
mainView.postDelayed(200) { store.dispatch(FeeAction.RequestFee) }
store.dispatch(FeeAction.RequestFee)
}
private fun setupAmountLayout() {
store.dispatch(SetMainCurrency(restoreMainCurrency()))
mainView.postDelayed(200) { store.dispatch(ReceiptAction.RefreshReceipt) }
store.dispatch(ReceiptAction.RefreshReceipt)
tvAmountCurrency.setOnClickListener {
store.dispatch(ToggleMainCurrency)

View file

@ -34,15 +34,17 @@ import kotlinx.android.synthetic.main.layout_send_receipt.*
class SendStateSubscriber(fragment: BaseStoreFragment) : FragmentStateSubscriber<SendState>(fragment) {
override fun updateWithNewState(fg: BaseStoreFragment, state: SendState) {
when (state.lastChangedStateType) {
is FeeState -> handleFeeState(fg, state.feeState)
is AddressPayIdState -> handleAddressPayIdState(fg, state.addressPayIdState)
is AmountState -> handleAmountState(fg, state.amountState)
is ReceiptState -> handleReceiptState(fg, state.receiptState)
val lastChangedStates = state.lastChangedStates.toList()
state.lastChangedStates.clear()
lastChangedStates.forEach {
when (it) {
StateId.ADDRESS_PAY_ID -> handleAddressPayIdState(fg, state.addressPayIdState)
StateId.AMOUNT -> handleAmountState(fg, state.amountState)
StateId.FEE -> handleFeeState(fg, state.feeState)
StateId.RECEIPT -> handleReceiptState(fg, state.receiptState)
}
}
fg.btnSend.isEnabled = state.sendButtonIsEnabled
fg.imvPaste.isEnabled = state.addressPayIdState.pasteIsEnabled
}
private fun handleAddressPayIdState(fg: BaseStoreFragment, state: AddressPayIdState) {
@ -59,6 +61,7 @@ class SendStateSubscriber(fragment: BaseStoreFragment) : FragmentStateSubscriber
return if (resId == null) null
else context.getString(resId)
}
fg.imvPaste.isEnabled = state.pasteIsEnabled
val et = fg.etAddressOrPayId
val til = fg.tilAddressOrPayId