Updated on 2026-08-14

This commit is contained in:
Tangem 2024-03-13 17:42:41 +08:00
parent e5d135edb4
commit a0834799ea
15 changed files with 141 additions and 64 deletions

View file

@ -87,16 +87,18 @@ internal class SendStateFactory(
val state = currentStateProvider()
return state.copy(
amountState = state.amountState ?: amountStateConverter.convert(""),
recipientState = state.recipientState ?: recipientStateConverter.convert(""),
recipientState = state.recipientState
?: recipientStateConverter.convert(SendRecipientStateConverter.Data("", null)),
feeState = state.feeState ?: feeStateConverter.convert(Unit),
)
}
fun getReadyState(amount: String, destinationAddress: String): SendUiState {
fun getReadyState(amount: String, destinationAddress: String, memo: String?): SendUiState {
val state = currentStateProvider()
return state.copy(
amountState = state.amountState ?: amountStateConverter.convert(amount),
recipientState = state.recipientState ?: recipientStateConverter.convert(destinationAddress),
recipientState = state.recipientState
?: recipientStateConverter.convert(SendRecipientStateConverter.Data(destinationAddress, memo)),
feeState = state.feeState ?: feeStateConverter.convert(Unit),
isEditingDisabled = true,
)

View file

@ -1,5 +1,6 @@
package com.tangem.features.send.impl.presentation.state.recipient
import androidx.annotation.StringRes
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
@ -15,13 +16,18 @@ import com.tangem.utils.converter.Converter
internal class SendRecipientMemoFieldConverter(
private val clickIntents: SendClickIntents,
private val cryptoCurrencyStatus: Provider<CryptoCurrencyStatus>,
) : Converter<Int, SendTextField.RecipientMemo> {
) : Converter<SendRecipientMemoFieldConverter.Data, SendTextField.RecipientMemo> {
fun convertOrNull(): SendTextField.RecipientMemo? {
fun convertOrNull(memoValue: String?): SendTextField.RecipientMemo? {
val cryptoCurrency = cryptoCurrencyStatus().currency
val memo = memoValue ?: ""
return when (cryptoCurrency.network.id.value) {
Blockchain.XRP.id -> convert(R.string.send_destination_tag_field)
Blockchain.XRP.id -> {
convert(
value = Data(memo = memo, label = R.string.send_destination_tag_field),
)
}
Blockchain.Binance.id,
Blockchain.TON.id,
Blockchain.Cosmos.id,
@ -30,24 +36,30 @@ internal class SendRecipientMemoFieldConverter(
Blockchain.Stellar.id,
Blockchain.Hedera.id,
Blockchain.Algorand.id,
-> convert(R.string.send_extras_hint_memo)
-> {
convert(
value = Data(memo = memo, label = R.string.send_extras_hint_memo),
)
}
else -> null
}
}
override fun convert(value: Int): SendTextField.RecipientMemo {
override fun convert(value: Data): SendTextField.RecipientMemo {
return SendTextField.RecipientMemo(
value = "",
value = value.memo,
onValueChange = clickIntents::onRecipientMemoValueChange,
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Done,
keyboardType = KeyboardType.Text,
),
placeholder = resourceReference(R.string.send_optional_field),
label = resourceReference(value),
label = resourceReference(value.label),
error = resourceReference(R.string.send_memo_destination_tag_error),
disabledText = resourceReference(R.string.send_additional_field_already_included),
isEnabled = true,
)
}
data class Data(val memo: String, @StringRes val label: Int)
}

View file

@ -10,7 +10,7 @@ import kotlinx.collections.immutable.persistentListOf
internal class SendRecipientStateConverter(
private val clickIntents: SendClickIntents,
private val cryptoCurrencyStatusProvider: Provider<CryptoCurrencyStatus>,
) : Converter<String, SendStates.RecipientState> {
) : Converter<SendRecipientStateConverter.Data, SendStates.RecipientState> {
private val addressFieldConverter by lazy { SendRecipientAddressFieldConverter(clickIntents) }
private val memoFieldConverter by lazy {
@ -20,14 +20,16 @@ internal class SendRecipientStateConverter(
)
}
override fun convert(value: String): SendStates.RecipientState {
override fun convert(value: Data): SendStates.RecipientState {
return SendStates.RecipientState(
addressTextField = addressFieldConverter.convert(value),
memoTextField = memoFieldConverter.convertOrNull(),
addressTextField = addressFieldConverter.convert(value.address),
memoTextField = memoFieldConverter.convertOrNull(value.memo),
network = cryptoCurrencyStatusProvider().currency.network.name,
isPrimaryButtonEnabled = false,
wallets = persistentListOf(),
recent = persistentListOf(),
)
}
data class Data(val address: String, val memo: String? = null)
}

View file

@ -99,6 +99,7 @@ internal class SendViewModel @Inject constructor(
private val transactionId: String? = savedStateHandle[SendRouter.TRANSACTION_ID_KEY]
private val amount: String? = savedStateHandle[SendRouter.AMOUNT_KEY]
private val destinationAddress: String? = savedStateHandle[SendRouter.DESTINATION_ADDRESS_KEY]
private val memo: String? = savedStateHandle[SendRouter.TAG_KEY]
private val selectedAppCurrencyFlow: StateFlow<AppCurrency> = createSelectedAppCurrencyFlow()
@ -342,7 +343,7 @@ internal class SendViewModel @Inject constructor(
stateRouter.showSend()
}
transactionId != null && amount != null && destinationAddress != null -> {
uiState = stateFactory.getReadyState(amount, destinationAddress)
uiState = stateFactory.getReadyState(amount, destinationAddress, memo)
stateRouter.showFee()
updateNotifications()
}