Updated on 2026-08-14

This commit is contained in:
Tangem 2024-05-23 17:38:35 +05:00
commit e1540e2c5b
11 changed files with 30 additions and 18 deletions

View file

@ -23,8 +23,8 @@ import com.tangem.core.ui.components.inputrow.inner.DividerContainer
import com.tangem.core.ui.components.inputrow.inner.PasteButton
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.resolveReference
import com.tangem.core.ui.res.TangemThemePreview
import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.res.TangemThemePreview
import kotlinx.coroutines.delay
/**
@ -56,6 +56,7 @@ fun InputRowRecipient(
isError: Boolean = false,
showDivider: Boolean = false,
isLoading: Boolean = false,
isValuePasted: Boolean = false,
) {
val (titleText, color) = if (isError && error != null) {
error to TangemTheme.colors.text.warning
@ -92,6 +93,7 @@ fun InputRowRecipient(
placeholder = placeholder,
onValueChange = onValueChange,
singleLine = singleLine,
isValuePasted = isValuePasted,
modifier = Modifier
.padding(start = TangemTheme.dimens.spacing12)
.weight(1f)

View file

@ -151,14 +151,14 @@ internal class SendStateFactory(
)
}
fun onRecipientAddressValueChange(value: String, isXAddress: Boolean = false): SendUiState {
fun onRecipientAddressValueChange(value: String, isXAddress: Boolean = false, isValuePasted: Boolean): SendUiState {
val state = currentStateProvider()
val isEditState = stateRouterProvider().isEditState
val recipientState = state.getRecipientState(isEditState) ?: return state
return state.copyWrapped(
isEditState = isEditState,
recipientState = recipientState.copy(
addressTextField = recipientState.addressTextField.copy(value = value),
addressTextField = recipientState.addressTextField.copy(value = value, isValuePasted = isValuePasted),
memoTextField = recipientState.memoTextField?.copy(isEnabled = !isXAddress),
),
)
@ -207,14 +207,17 @@ internal class SendStateFactory(
)
}
fun getOnRecipientMemoValueChange(value: String): SendUiState {
fun getOnRecipientMemoValueChange(value: String, isValuePasted: Boolean): SendUiState {
val state = currentStateProvider()
val isEditState = stateRouterProvider().isEditState
val recipientState = state.getRecipientState(isEditState) ?: return state
return state.copyWrapped(
isEditState = isEditState,
recipientState = recipientState.copy(
memoTextField = recipientState.memoTextField?.copy(value = value),
memoTextField = recipientState.memoTextField?.copy(
value = value,
isValuePasted = isValuePasted,
),
),
)
}

View file

@ -42,6 +42,7 @@ internal sealed class SendTextField {
val label: TextReference,
val isError: Boolean = false,
val error: TextReference? = null,
val isValuePasted: Boolean,
) : SendTextField()
data class RecipientMemo(
@ -54,6 +55,7 @@ internal sealed class SendTextField {
val error: TextReference? = null,
val disabledText: TextReference,
val isEnabled: Boolean,
val isValuePasted: Boolean,
) : SendTextField()
data class CustomFee(

View file

@ -30,6 +30,7 @@ internal object RecipientStatePreviewData {
label = stringReference("Recipient"),
isError = false,
error = null,
isValuePasted = false,
),
memoTextField = null,
recent = persistentListOf(

View file

@ -36,7 +36,7 @@ internal object SendClickIntentsStub : SendClickIntents {
override fun onRecipientAddressValueChange(value: String, type: EnterAddressSource?) {}
override fun onRecipientMemoValueChange(value: String) {}
override fun onRecipientMemoValueChange(value: String, isValuePasted: Boolean) {}
override fun feeReload() {}
@ -64,7 +64,8 @@ internal object SendClickIntentsStub : SendClickIntents {
reduceAmountBy: BigDecimal?,
reduceAmountTo: BigDecimal?,
clazz: Class<out SendNotification>,
) {}
) {
}
override fun onNotificationCancel(clazz: Class<out SendNotification>) {}
}

View file

@ -24,6 +24,7 @@ internal class SendRecipientAddressFieldConverter(
error = resourceReference(R.string.send_recipient_address_error),
placeholder = resourceReference(R.string.send_enter_address_field),
label = resourceReference(R.string.send_recipient),
isValuePasted = false,
)
}
}

View file

@ -58,6 +58,7 @@ internal class SendRecipientMemoFieldConverter(
error = resourceReference(R.string.send_memo_destination_tag_error),
disabledText = resourceReference(R.string.send_additional_field_already_included),
isEnabled = true,
isValuePasted = false,
)
}

View file

@ -69,7 +69,7 @@ internal fun SendRecipientContent(
)
memoField(
memoField = memoField,
onMemoChange = clickIntents::onRecipientMemoValueChange,
onMemoChange = { clickIntents.onRecipientMemoValueChange(it, true) },
)
listHeaderItem(
titleRes = R.string.send_recipient_wallets_title,
@ -116,6 +116,7 @@ private fun LazyListScope.addressItem(
isError = isError,
isLoading = isValidating,
error = address.error,
isValuePasted = address.isValuePasted,
modifier = Modifier
.background(
color = TangemTheme.colors.background.action,
@ -141,6 +142,7 @@ private fun LazyListScope.memoField(memoField: SendTextField.RecipientMemo?, onM
isError = memoField.isError,
error = memoField.error,
isReadOnly = !memoField.isEnabled,
isValuePasted = memoField.isValuePasted,
)
}
}

View file

@ -30,6 +30,7 @@ internal fun TextFieldWithPaste(
error: TextReference? = null,
isError: Boolean = false,
isReadOnly: Boolean = false,
isValuePasted: Boolean = false,
) {
val (title, color) = when {
isError && error != null -> error to TangemTheme.colors.text.warning
@ -63,6 +64,7 @@ internal fun TextFieldWithPaste(
placeholderColor = placeholderColor,
onValueChange = onValueChange,
readOnly = isReadOnly,
isValuePasted = isValuePasted,
modifier = Modifier
.fillMaxWidth()
.padding(top = TangemTheme.dimens.spacing6),

View file

@ -39,7 +39,7 @@ internal interface SendClickIntents {
// region Recipient
fun onRecipientAddressValueChange(value: String, type: EnterAddressSource? = null)
fun onRecipientMemoValueChange(value: String)
fun onRecipientMemoValueChange(value: String, isValuePasted: Boolean = false)
// endregion
// region Fee

View file

@ -52,10 +52,7 @@ import com.tangem.features.send.impl.presentation.state.confirm.SendNotification
import com.tangem.features.send.impl.presentation.state.fee.*
import com.tangem.lib.crypto.BlockchainUtils
import com.tangem.utils.Provider
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import com.tangem.utils.coroutines.DelayedWork
import com.tangem.utils.coroutines.JobHolder
import com.tangem.utils.coroutines.saveIn
import com.tangem.utils.coroutines.*
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.*
@ -586,7 +583,7 @@ internal class SendViewModel @Inject constructor(
)
}
// endregion
// endregion
// region amount state clicks
override fun onCurrencyChangeClick(isFiat: Boolean) {
@ -612,7 +609,7 @@ internal class SendViewModel @Inject constructor(
override fun onRecipientAddressValueChange(value: String, type: EnterAddressSource?) {
viewModelScope.launch {
if (!checkIfXrpAddressValue(value)) {
uiState = stateFactory.onRecipientAddressValueChange(value)
uiState = stateFactory.onRecipientAddressValueChange(value, isValuePasted = type != null)
uiState = stateFactory.getOnRecipientAddressValidationStarted()
val isValidAddress = validateAddress(value)
uiState = stateFactory.getOnRecipientAddressValidState(value, isValidAddress)
@ -622,10 +619,10 @@ internal class SendViewModel @Inject constructor(
}.saveIn(addressValidationJobHolder)
}
override fun onRecipientMemoValueChange(value: String) {
override fun onRecipientMemoValueChange(value: String, isValuePasted: Boolean) {
viewModelScope.launch {
if (!checkIfXrpAddressValue(value)) {
uiState = stateFactory.getOnRecipientMemoValueChange(value)
uiState = stateFactory.getOnRecipientMemoValueChange(value, isValuePasted)
uiState = stateFactory.getOnRecipientAddressValidationStarted()
val isValidAddress = validateAddress(uiState.recipientState?.addressTextField?.value.orEmpty())
uiState = stateFactory.getOnRecipientMemoValidState(value, isValidAddress)
@ -647,7 +644,7 @@ internal class SendViewModel @Inject constructor(
private suspend fun checkIfXrpAddressValue(value: String): Boolean {
return BlockchainUtils.decodeRippleXAddress(value, cryptoCurrency.network.id.value)?.let { decodedAddress ->
uiState = stateFactory.onRecipientAddressValueChange(value, isXAddress = true)
uiState = stateFactory.onRecipientAddressValueChange(value, isXAddress = true, isValuePasted = true)
uiState = stateFactory.getOnXAddressMemoState()
val isValidAddress = validateAddress(decodedAddress.address)
uiState = stateFactory.getOnRecipientAddressValidState(decodedAddress.address, isValidAddress)