Updated on 2026-08-14

This commit is contained in:
Tangem 2024-11-01 17:47:18 +02:00
parent 8202b6bf2a
commit ab85772d10
47 changed files with 356 additions and 116 deletions

View file

@ -2,10 +2,13 @@ package com.tangem.features.send.impl.presentation.state
import com.tangem.blockchain.common.TransactionData
import com.tangem.common.ui.amountScreen.converters.AmountStateConverter
import com.tangem.common.ui.amountScreen.converters.MaxEnterAmountConverter
import com.tangem.common.ui.amountScreen.models.AmountParameters
import com.tangem.common.ui.amountScreen.models.AmountState
import com.tangem.common.ui.notifications.NotificationUM
import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter
import com.tangem.core.ui.event.consumedEvent
import com.tangem.core.ui.extensions.stringReference
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.wallets.models.UserWallet
@ -33,14 +36,15 @@ internal class SendStateFactory(
private val isTapHelpPreviewEnabledProvider: Provider<Boolean>,
) {
private val iconStateConverter by lazy(::CryptoCurrencyToIconStateConverter)
private val maxEnterAmountConverter = MaxEnterAmountConverter()
private val amountStateConverter by lazy(LazyThreadSafetyMode.NONE) {
AmountStateConverter(
clickIntents = clickIntents,
appCurrencyProvider = appCurrencyProvider,
iconStateConverter = iconStateConverter,
userWalletProvider = userWalletProvider,
cryptoCurrencyStatusProvider = cryptoCurrencyStatusProvider,
maxEnterAmountProvider = Provider { maxEnterAmountConverter.convert(cryptoCurrencyStatusProvider()) },
)
}
private val recipientStateConverter by lazy(LazyThreadSafetyMode.NONE) {
@ -79,7 +83,12 @@ internal class SendStateFactory(
fun getReadyState(): SendUiState {
val state = currentStateProvider()
val amountState = if (state.amountState is AmountState.Empty) {
amountStateConverter.convert("")
amountStateConverter.convert(
AmountParameters(
title = stringReference(userWalletProvider().name),
value = "",
),
)
} else {
state.amountState
}
@ -96,7 +105,12 @@ internal class SendStateFactory(
fun getReadyState(amount: String, destinationAddress: String, memo: String?): SendUiState {
val state = currentStateProvider()
val amountState = if (state.amountState is AmountState.Empty) {
amountStateConverter.convert(amount)
amountStateConverter.convert(
AmountParameters(
title = stringReference(userWalletProvider().name),
value = amount,
),
)
} else {
state.amountState
}

View file

@ -1,5 +1,6 @@
package com.tangem.features.send.impl.presentation.state.fields
import com.tangem.common.ui.amountScreen.converters.MaxEnterAmountConverter
import com.tangem.common.ui.amountScreen.converters.field.AmountFieldChangeTransformer
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.features.send.impl.presentation.state.SendUiState
@ -13,15 +14,19 @@ internal class SendAmountFieldChangeConverter(
private val cryptoCurrencyStatusProvider: Provider<CryptoCurrencyStatus>,
) : Converter<String, SendUiState> {
private val maxEnterAmountConverter = MaxEnterAmountConverter()
override fun convert(value: String): SendUiState {
val state = currentStateProvider()
val isEditState = stateRouterProvider().isEditState
val amountState = state.getAmountState(isEditState) ?: return state
val amountState = state.getAmountState(isEditState)
val maxEnterAmount = maxEnterAmountConverter.convert(cryptoCurrencyStatusProvider())
return state.copyWrapped(
isEditState = isEditState,
sendState = state.sendState?.copy(reduceAmountBy = null),
amountState = AmountFieldChangeTransformer(cryptoCurrencyStatusProvider(), value).transform(amountState),
amountState = AmountFieldChangeTransformer(maxEnterAmount, value).transform(amountState),
)
}
}

View file

@ -1,6 +1,7 @@
package com.tangem.features.send.impl.presentation.state.fields
import com.tangem.common.ui.amountScreen.converters.field.AmountFieldMaxAmountTransformer
import com.tangem.common.ui.amountScreen.converters.MaxEnterAmountConverter
import com.tangem.common.ui.amountScreen.converters.field.AmountFieldSetMaxAmountTransformer
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.features.send.impl.presentation.state.SendUiState
import com.tangem.features.send.impl.presentation.state.StateRouter
@ -14,6 +15,8 @@ internal class SendAmountFieldMaxAmountConverter(
private val cryptoCurrencyStatusProvider: Provider<CryptoCurrencyStatus>,
) : Converter<Unit, SendUiState> {
private val maxEnterAmountConverter = MaxEnterAmountConverter()
override fun convert(value: Unit): SendUiState {
val state = currentStateProvider()
val cryptoCurrencyStatus = cryptoCurrencyStatusProvider()
@ -23,10 +26,12 @@ internal class SendAmountFieldMaxAmountConverter(
val decimalCryptoValue = cryptoCurrencyStatus.value.amount
if (decimalCryptoValue.isNullOrZero()) return state
val maxEnterAmount = maxEnterAmountConverter.convert(cryptoCurrencyStatus)
return state.copyWrapped(
isEditState = isEditState,
sendState = state.sendState?.copy(reduceAmountBy = null),
amountState = AmountFieldMaxAmountTransformer(cryptoCurrencyStatusProvider()).transform(amountState),
amountState = AmountFieldSetMaxAmountTransformer(maxEnterAmount).transform(amountState),
)
}
}

View file

@ -88,7 +88,7 @@ private fun SendAppBar(uiState: SendUiState, currentState: SendUiCurrentScreen)
-> resourceReference(R.string.common_fee_selector_title) to null
SendUiStateType.Send -> if (uiState.sendState?.isSuccess == false) {
resourceReference(R.string.send_summary_title, wrappedList(uiState.cryptoCurrencyName)) to
(uiState.amountState as? AmountState.Data)?.walletName
(uiState.amountState as? AmountState.Data)?.title
} else {
null to null
}
@ -108,7 +108,7 @@ private fun SendAppBar(uiState: SendUiState, currentState: SendUiCurrentScreen)
}
AppBarWithBackButtonAndIcon(
text = titleRes?.resolveReference(),
subtitle = subtitleRes,
subtitle = subtitleRes?.resolveReference(),
onBackClick = uiState.clickIntents::onCloseClick,
onIconClick = uiState.clickIntents::onQrCodeScanClick,
backIconRes = backIcon,