Updated on 2026-08-14

This commit is contained in:
Tangem 2025-12-10 16:31:57 +03:00
commit 4df207e832
59 changed files with 492 additions and 234 deletions

View file

@ -87,7 +87,7 @@ internal class ItemsBuilder @Inject constructor(private val router: Router) {
DetailsItemUM.Basic.Item(
id = "support_email",
block = BlockUM(
text = resourceReference(R.string.details_row_title_contact_to_support),
text = resourceReference(R.string.common_contact_support),
iconRes = R.drawable.ic_comment_24,
onClick = onSupportEmailClick,
),

View file

@ -20,28 +20,26 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.Dp
import com.tangem.common.ui.charts.state.MarketChartDataProducer
import com.tangem.core.ui.components.*
import com.tangem.core.ui.components.appbar.TangemTopAppBar
import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent
import com.tangem.core.ui.components.buttons.segmentedbutton.SegmentedButtons
import com.tangem.core.ui.components.currency.icon.CoinIcon
import com.tangem.core.ui.components.marketprice.PriceChangeInPercent
import com.tangem.core.ui.components.marketprice.PriceChangeType
import com.tangem.core.ui.event.EventEffect
import com.tangem.core.ui.event.StateEvent
import com.tangem.core.ui.event.consumedEvent
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.resolveReference
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.extensions.stringReference
import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.res.TangemThemePreview
import com.tangem.domain.markets.PriceChangeInterval
import com.tangem.features.markets.details.impl.ui.components.*
import com.tangem.features.markets.details.impl.ui.preview.MarketsTokenDetailsPreview
import com.tangem.features.markets.details.impl.ui.state.ExchangesBottomSheetContent
import com.tangem.features.markets.details.impl.ui.state.InfoBottomSheetContent
import com.tangem.features.markets.details.impl.ui.state.MarketsTokenDetailsUM
@ -317,36 +315,16 @@ fun PriceChangeInterval.getText(): TextReference {
}
}
@Preview
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
// region Preview
@Composable
private fun Preview() {
@Preview(showBackground = true, widthDp = 360)
@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES)
private fun MarketsTokenDetailsContent_Preview(
@PreviewParameter(MarketsTokenDetailsContentPreviewProvider::class) params: MarketsTokenDetailsUM,
) {
TangemThemePreview {
MarketsTokenDetailsContent(
state = MarketsTokenDetailsUM(
tokenName = "Token Name",
priceText = "$0.00000000324",
dateTimeText = stringReference("Today"),
priceChangePercentText = "52.00%",
iconUrl = "",
priceChangeType = PriceChangeType.UP,
chartState = MarketsTokenDetailsUM.ChartState(
dataProducer = MarketChartDataProducer.build { },
onLoadRetryClick = {},
status = MarketsTokenDetailsUM.ChartState.Status.LOADING,
onMarkerPointSelected = { _, _ -> },
),
selectedInterval = PriceChangeInterval.H24,
onSelectedIntervalChange = { },
body = MarketsTokenDetailsUM.Body.Loading,
bottomSheetConfig = TangemBottomSheetConfig(
isShown = false,
onDismissRequest = {},
content = TangemBottomSheetConfigContent.Empty,
),
markerSet = false,
triggerPriceChange = consumedEvent(),
),
state = params,
onHeaderSizeChange = {},
onBackClick = {},
backgroundColor = TangemTheme.colors.background.tertiary,
@ -356,4 +334,13 @@ private fun Preview() {
addTopBarStatusBarPadding = false,
)
}
}
}
private class MarketsTokenDetailsContentPreviewProvider : PreviewParameterProvider<MarketsTokenDetailsUM> {
override val values: Sequence<MarketsTokenDetailsUM>
get() = sequenceOf(
MarketsTokenDetailsPreview.loadingState,
MarketsTokenDetailsPreview.contentState,
)
}
// endregion

View file

@ -8,6 +8,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.tangem.core.ui.components.RectangleShimmer
import com.tangem.core.ui.components.block.information.GridItems
import com.tangem.core.ui.components.block.information.InformationBlock
@ -51,12 +52,16 @@ internal fun InsightsBlock(state: InsightsUM, modifier: Modifier = Modifier) {
currentInterval = it
state.onIntervalChanged(it)
},
modifier = Modifier.width(IntrinsicSize.Min),
) {
Box(
Modifier
.fillMaxSize()
.align(Alignment.Center)
.padding(vertical = TangemTheme.dimens.spacing4),
.padding(
horizontal = 14.dp,
vertical = 4.dp,
),
) {
Text(
modifier = Modifier.align(Alignment.Center),

View file

@ -57,12 +57,16 @@ internal fun PricePerformanceBlock(state: PricePerformanceUM, modifier: Modifier
currentInterval = it
state.onIntervalChanged(it)
},
modifier = Modifier.width(IntrinsicSize.Min),
) {
Box(
Modifier
.fillMaxSize()
.align(Alignment.Center)
.padding(vertical = TangemTheme.dimens.spacing4),
.padding(
horizontal = 14.dp,
vertical = TangemTheme.dimens.spacing4,
),
) {
Text(
modifier = Modifier.align(Alignment.Center),

View file

@ -0,0 +1,129 @@
package com.tangem.features.markets.details.impl.ui.preview
import com.tangem.common.ui.charts.state.MarketChartDataProducer
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent
import com.tangem.core.ui.components.marketprice.PriceChangeType
import com.tangem.core.ui.event.consumedEvent
import com.tangem.core.ui.extensions.stringReference
import com.tangem.domain.markets.PriceChangeInterval
import com.tangem.features.markets.details.impl.ui.state.*
import kotlinx.collections.immutable.persistentListOf
internal object MarketsTokenDetailsPreview {
private val infoPoint = InfoPointUM(
title = stringReference("1"),
value = "2",
change = InfoPointUM.ChangeType.DOWN,
onInfoClick = {},
)
val loadingState = MarketsTokenDetailsUM(
tokenName = "Token Name",
priceText = "$0.00000000324",
dateTimeText = stringReference("Today"),
priceChangePercentText = "52.00%",
iconUrl = "",
priceChangeType = PriceChangeType.UP,
chartState = MarketsTokenDetailsUM.ChartState(
dataProducer = MarketChartDataProducer.build { },
onLoadRetryClick = {},
status = MarketsTokenDetailsUM.ChartState.Status.LOADING,
onMarkerPointSelected = { _, _ -> },
),
selectedInterval = PriceChangeInterval.H24,
onSelectedIntervalChange = { },
body = MarketsTokenDetailsUM.Body.Loading,
bottomSheetConfig = TangemBottomSheetConfig(
isShown = false,
onDismissRequest = {},
content = TangemBottomSheetConfigContent.Empty,
),
markerSet = false,
triggerPriceChange = consumedEvent(),
)
val contentState = MarketsTokenDetailsUM(
tokenName = "Token Name",
priceText = "$0.00000000324",
dateTimeText = stringReference("Today"),
priceChangePercentText = "52.00%",
iconUrl = "",
priceChangeType = PriceChangeType.UP,
chartState = MarketsTokenDetailsUM.ChartState(
dataProducer = MarketChartDataProducer.build { },
onLoadRetryClick = {},
status = MarketsTokenDetailsUM.ChartState.Status.LOADING,
onMarkerPointSelected = { _, _ -> },
),
selectedInterval = PriceChangeInterval.H24,
onSelectedIntervalChange = { },
body = MarketsTokenDetailsUM.Body.Content(
description = MarketsTokenDetailsUM.Description(
shortDescription = stringReference("markets_token_details_description_short"),
fullDescription = stringReference("markets_token_details_description_full"),
onReadMoreClick = {},
),
infoBlocks = MarketsTokenDetailsUM.InformationBlocks(
insights = InsightsUM(
h24Info = persistentListOf(
infoPoint,
infoPoint,
infoPoint,
),
weekInfo = persistentListOf(
infoPoint,
infoPoint,
infoPoint,
),
monthInfo = persistentListOf(
infoPoint,
infoPoint,
infoPoint,
),
onInfoClick = {},
onIntervalChanged = {},
),
securityScore = SecurityScoreUM(
score = 2.3f,
description = stringReference("markets_token_details_security_score_description"),
onInfoClick = {},
),
metrics = MetricsUM(
metrics = persistentListOf(
infoPoint,
infoPoint,
infoPoint,
),
),
pricePerformance = PricePerformanceUM(
h24 = PricePerformanceUM.Value(
low = "1",
high = "2",
indicatorFraction = 0.3f,
),
month = PricePerformanceUM.Value(
low = "1",
high = "2",
indicatorFraction = 0.3f,
),
all = PricePerformanceUM.Value(
low = "1",
high = "2",
indicatorFraction = 0.3f,
),
onIntervalChanged = {},
),
listedOn = ListedOnUM.Empty,
links = null,
),
),
bottomSheetConfig = TangemBottomSheetConfig(
isShown = false,
onDismissRequest = {},
content = TangemBottomSheetConfigContent.Empty,
),
markerSet = true,
triggerPriceChange = consumedEvent(),
)
}

View file

@ -17,14 +17,15 @@ internal class OnrampOffersStateFactory(
fun getOffersState(offers: List<OnrampOffersBlock>): OnrampV2MainComponentUM {
val currentState = currentStateProvider.invoke()
return when (currentState) {
is OnrampV2MainComponentUM.InitialLoading -> currentState
is OnrampV2MainComponentUM.Content -> {
if (currentState.offersBlockState is OnrampOffersBlockUM.Loading && offers.isEmpty()) {
return currentState
}
currentState.copy(
offersBlockState = mapOnrampOffersBlockToUM(offersBlocks = offers),
)
}
is OnrampV2MainComponentUM.InitialLoading -> {
currentState
}
}
}

View file

@ -64,6 +64,7 @@ internal class OnrampV2AmountStateFactory(
currencySymbol = currency.unit,
onAmountValueChanged = onrampIntents::onAmountValueChanged,
),
offersBlockState = OnrampOffersBlockUM.Loading,
)
}

View file

@ -523,6 +523,7 @@ internal class SendConfirmModel @Inject constructor(
params.callback.onResult(
state.copy(
navigationUM = NavigationUM.Content(
source = CommonSendRoute.Confirm.javaClass.simpleName,
title = resourceReference(id = R.string.common_send),
subtitle = null,
backIconRes = when (confirmUM) {

View file

@ -52,6 +52,7 @@ internal class SendConfirmSuccessModel @Inject constructor(
params.callback.onResult(
state.copy(
navigationUM = NavigationUM.Content(
source = CommonSendRoute.ConfirmSuccess.javaClass.simpleName,
title = stringReference(""),
subtitle = null,
backIconRes = R.drawable.ic_close_24,

View file

@ -371,11 +371,12 @@ internal class NFTSendConfirmModel @Inject constructor(
flow = uiState,
flow2 = params.currentRoute,
transform = { state, route -> state to route },
).onEach { (state, _) ->
).onEach { (state, route) ->
val confirmUM = state.confirmUM
params.callback.onResult(
state.copy(
navigationUM = NavigationUM.Content(
source = CommonSendRoute.Confirm.javaClass.simpleName,
title = resourceReference(R.string.nft_send),
subtitle = null,
backIconRes = when (confirmUM) {

View file

@ -50,6 +50,7 @@ internal class NFTSendSuccessModel @Inject constructor(
params.callback.onResult(
state.copy(
navigationUM = NavigationUM.Content(
source = CommonSendRoute.ConfirmSuccess.javaClass.simpleName,
title = stringReference(""),
subtitle = null,
backIconRes = R.drawable.ic_close_24,

View file

@ -378,6 +378,7 @@ internal class SendAmountModel @Inject constructor(
setSendWithSwapAvailability()
params.callback.onNavigationResult(
NavigationUM.Content(
source = CommonSendRoute.Amount::class.java.simpleName,
title = resourceReference(R.string.send_amount_label),
subtitle = null,
backIconRes = if (route.isEditMode) {

View file

@ -35,6 +35,7 @@ import com.tangem.features.send.v2.api.entity.PredefinedValues
import com.tangem.features.send.v2.api.subcomponents.destination.SendDestinationComponentParams
import com.tangem.features.send.v2.api.subcomponents.destination.SendDestinationComponentParams.DestinationBlockParams
import com.tangem.features.send.v2.api.subcomponents.destination.entity.DestinationUM
import com.tangem.features.send.v2.common.CommonSendRoute
import com.tangem.features.send.v2.impl.R
import com.tangem.features.send.v2.subcomponents.destination.analytics.EnterAddressSource
import com.tangem.features.send.v2.subcomponents.destination.analytics.SendDestinationAnalyticEvents
@ -359,6 +360,7 @@ internal class SendDestinationModel @Inject constructor(
).onEach { (state, route) ->
params.callback.onNavigationResult(
NavigationUM.Content(
source = CommonSendRoute.Destination::class.java.simpleName,
title = params.title,
subtitle = null,
backIconRes = if (route.isEditMode) {

View file

@ -136,6 +136,7 @@ internal class NotificationsModel @Inject constructor(
val currencyCheck = getCurrencyCheckUseCase(
userWalletId = userWalletId,
currencyStatus = cryptoCurrencyStatus,
feeCurrencyStatus = feeCryptoCurrencyStatus,
amount = sendingAmount,
fee = feeValue,
recipientAddress = destinationAddress,

View file

@ -772,6 +772,7 @@ internal class StakingModel @Inject constructor(
val currencyStatus = getCurrencyCheckUseCase(
userWalletId = userWalletId,
currencyStatus = cryptoCurrencyStatus,
feeCurrencyStatus = feeCryptoCurrencyStatus,
amount = amount,
fee = fee,
feeCurrencyBalanceAfterTransaction = balanceAfterTransaction,

View file

@ -720,6 +720,7 @@ internal class SwapAmountModel @Inject constructor(
).filter { (_, route) -> route is SendWithSwapRoute.Amount }.onEach { (state, route) ->
params.callback.onNavigationResult(
NavigationUM.Content(
source = SendWithSwapRoute.Amount::class.java.simpleName,
title = resourceReference(R.string.common_amount),
subtitle = null,
backIconRes = if (route.isEditMode) {

View file

@ -428,6 +428,7 @@ internal class SendWithSwapConfirmModel @Inject constructor(
route = SendWithSwapRoute.Confirm,
sendWithSwapUM = state.copy(
navigationUM = NavigationUM.Content(
source = SendWithSwapRoute.Confirm.javaClass.simpleName,
title = resourceReference(id = R.string.send_with_swap_confirm_title),
subtitle = null,
backIconRes = R.drawable.ic_back_24,

View file

@ -12,6 +12,7 @@ import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.features.swap.v2.impl.R
import com.tangem.features.swap.v2.impl.common.entity.ConfirmUM
import com.tangem.features.swap.v2.impl.sendviaswap.SendWithSwapRoute
import com.tangem.features.swap.v2.impl.sendviaswap.entity.SendWithSwapUM
import com.tangem.features.swap.v2.impl.sendviaswap.success.SendWithSwapSuccessComponent
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
@ -40,6 +41,7 @@ internal class SendWithSwapSuccessModel @Inject constructor(
private fun configConfirmSuccessNavigation() {
params.callback.onNavigationResult(
NavigationUM.Content(
source = SendWithSwapRoute.Success.javaClass.simpleName,
title = TextReference.EMPTY,
subtitle = null,
backIconRes = R.drawable.ic_close_24,

View file

@ -55,6 +55,7 @@ import com.tangem.features.swap.v2.impl.amount.entity.SwapAmountUM
import com.tangem.features.swap.v2.impl.amount.ui.preview.SwapAmountContentPreview
import com.tangem.features.swap.v2.impl.common.entity.ConfirmUM
import com.tangem.features.swap.v2.impl.common.entity.SwapQuoteUM
import com.tangem.features.swap.v2.impl.sendviaswap.SendWithSwapRoute
import com.tangem.features.swap.v2.impl.sendviaswap.entity.SendWithSwapUM
import kotlinx.collections.immutable.persistentListOf
import java.math.BigDecimal
@ -368,6 +369,7 @@ private fun SendWithSwapSuccessContent_Preview() {
),
),
navigationUM = NavigationUM.Content(
source = SendWithSwapRoute.Success.javaClass.simpleName,
title = TextReference.EMPTY,
subtitle = null,
backIconRes = R.drawable.ic_close_24,

View file

@ -92,6 +92,7 @@ internal class SwapInteractorImpl @AssistedInject constructor(
private val amountFormatter: AmountFormatter,
private val rampStateManager: RampStateManager,
private val singleAccountStatusListSupplier: SingleAccountStatusListSupplier,
private val getFeePaidCryptoCurrencyStatusSyncUseCase: GetFeePaidCryptoCurrencyStatusSyncUseCase,
private val accountsFeatureToggles: AccountsFeatureToggles,
@Assisted private val userWalletId: UserWalletId,
) : SwapInteractor {
@ -631,9 +632,14 @@ internal class SwapInteractorImpl @AssistedInject constructor(
} else {
amount
}
val feePaidCurrencyStatus = getFeePaidCryptoCurrencyStatusSyncUseCase(
userWalletId = userWalletId,
cryptoCurrencyStatus = fromTokenStatus,
).getOrNull()
val currencyCheck = getCurrencyCheckUseCase(
userWalletId = userWalletId,
currencyStatus = fromTokenStatus,
feeCurrencyStatus = feePaidCurrencyStatus,
amount = amountToRequest.value,
fee = fee,
feeCurrencyBalanceAfterTransaction = balanceAfterTransaction,

View file

@ -5,7 +5,7 @@ import com.tangem.core.decompose.context.AppComponentContext
import com.tangem.core.decompose.model.getOrCreateModel
import com.tangem.core.ui.decompose.ComposableBottomSheetComponent
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.pay.TangemPayTopUpData
import com.tangem.domain.pay.model.TangemPayTopUpData
import com.tangem.features.tangempay.model.TangemPayAddFundsModel
import com.tangem.features.tangempay.ui.TangemPayAddFundsContent
import java.math.BigDecimal

View file

@ -1,8 +1,10 @@
package com.tangem.features.tangempay.entity
import androidx.compose.ui.unit.dp
import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig
import com.tangem.core.ui.components.containers.pullToRefresh.PullToRefreshConfig
import com.tangem.core.ui.components.dropdownmenu.TangemDropdownMenuItem
import com.tangem.core.ui.components.notifications.NotificationConfig
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.extensions.themedColor
import com.tangem.core.ui.res.TangemTheme
@ -21,6 +23,7 @@ internal class TangemPayDetailsStateFactory(
private val converter: TangemPayCardFrozenStateConverter,
) {
@Suppress("LongMethod")
fun getInitialState(): TangemPayDetailsUM {
val cardFrozenStateItem = when (cardFrozenState) {
is TangemPayCardFrozenState.Pending -> null
@ -88,6 +91,16 @@ internal class TangemPayDetailsStateFactory(
isBalanceHidden = false,
addFundsEnabled = true,
cardFrozenState = converter.convert(cardFrozenState),
betaNotificationConfig = NotificationConfig(
title = resourceReference(R.string.tangem_pay_beta_notification_title),
subtitle = resourceReference(R.string.tangem_pay_beta_notification_subtitle),
iconResId = R.drawable.img_visa_notification,
buttonsState = NotificationConfig.ButtonsState.SecondaryButtonConfig(
text = resourceReference(R.string.common_contact_support),
onClick = intents::onContactSupportClicked,
),
iconSize = 36.dp,
),
)
}
}

View file

@ -2,6 +2,7 @@ package com.tangem.features.tangempay.entity
import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig
import com.tangem.core.ui.components.containers.pullToRefresh.PullToRefreshConfig
import com.tangem.core.ui.components.notifications.NotificationConfig
import com.tangem.core.ui.extensions.TextReference
import com.tangem.domain.visa.model.TangemPayCardFrozenState
import kotlinx.collections.immutable.ImmutableList
@ -14,6 +15,7 @@ internal data class TangemPayDetailsUM(
val isBalanceHidden: Boolean,
val addFundsEnabled: Boolean,
val cardFrozenState: CardFrozenState,
val betaNotificationConfig: NotificationConfig,
)
internal data class TangemPayCardDetailsUM(

View file

@ -4,7 +4,10 @@ import androidx.compose.runtime.Stable
import com.tangem.core.decompose.di.ModelScoped
import com.tangem.core.decompose.model.Model
import com.tangem.core.decompose.model.ParamsContainer
import com.tangem.domain.pay.TangemPaySwapDataFactory
import com.tangem.domain.models.ReceiveAddressModel
import com.tangem.domain.models.ReceiveAddressModel.NameService
import com.tangem.domain.pay.TangemPayCryptoCurrencyFactory
import com.tangem.domain.pay.model.TangemPayTopUpData
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
import com.tangem.features.tangempay.components.TangemPayAddFundsComponent
import com.tangem.features.tangempay.entity.TangemPayAddFundsUM
@ -17,7 +20,7 @@ import javax.inject.Inject
internal class TangemPayAddFundsModel @Inject constructor(
paramsContainer: ParamsContainer,
override val dispatchers: CoroutineDispatcherProvider,
private val tangemPaySwapDataFactory: TangemPaySwapDataFactory,
private val tangemPayCryptoCurrencyFactory: TangemPayCryptoCurrencyFactory,
private val getUserWalletUseCase: GetUserWalletUseCase,
) : Model() {
@ -26,17 +29,25 @@ internal class TangemPayAddFundsModel @Inject constructor(
val uiState: TangemPayAddFundsUM = getInitialState()
private fun getInitialState(): TangemPayAddFundsUM {
val userWallet = requireNotNull(
getUserWalletUseCase(params.walletId).getOrNull(),
) { "User wallet not found for id: ${params.walletId}" }
val data = tangemPaySwapDataFactory.create(
userWallet = userWallet,
depositAddress = params.depositAddress,
chainId = params.chainId,
cryptoBalance = params.cryptoBalance,
fiatBalance = params.fiatBalance,
).getOrNull()
val userWallet = getUserWalletUseCase(params.walletId).getOrNull()
val currency = userWallet?.let {
tangemPayCryptoCurrencyFactory.create(userWallet = userWallet, chainId = params.chainId).getOrNull()
}
val data = currency?.let {
TangemPayTopUpData(
currency = currency,
walletId = params.walletId,
cryptoBalance = params.cryptoBalance,
fiatBalance = params.fiatBalance,
depositAddress = params.depositAddress,
receiveAddress = listOf(
ReceiveAddressModel(
nameService = NameService.Default,
value = params.depositAddress,
),
),
)
}
return TangemPayAddFundsUMConverter(listener = params.listener).convert(data)
}

View file

@ -17,10 +17,13 @@ import com.tangem.core.ui.components.containers.pullToRefresh.PullToRefreshConfi
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.message.SnackbarMessage
import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase
import com.tangem.domain.feedback.SendFeedbackEmailUseCase
import com.tangem.domain.feedback.models.FeedbackEmailType
import com.tangem.domain.feedback.models.WalletMetaInfo
import com.tangem.domain.models.TokenReceiveConfig
import com.tangem.domain.pay.TangemPaySwapDataFactory
import com.tangem.domain.pay.TangemPayTopUpData
import com.tangem.domain.pay.TangemPayCryptoCurrencyFactory
import com.tangem.domain.pay.model.TangemPayCardBalance
import com.tangem.domain.pay.model.TangemPayTopUpData
import com.tangem.domain.pay.repository.CustomerOrderRepository
import com.tangem.domain.pay.repository.TangemPayCardDetailsRepository
import com.tangem.domain.tangempay.TangemPayAnalyticsEvents
@ -70,9 +73,10 @@ internal class TangemPayDetailsModel @Inject constructor(
private val uiMessageSender: UiMessageSender,
private val cardDetailsEventListener: CardDetailsEventListener,
private val txHistoryUpdateListener: TangemPayTxHistoryUpdateListener,
private val tangemPaySwapDataFactory: TangemPaySwapDataFactory,
private val tangemPayCryptoCurrencyFactory: TangemPayCryptoCurrencyFactory,
private val orderRepository: CustomerOrderRepository,
private val getUserWalletUseCase: GetUserWalletUseCase,
private val sendFeedbackEmailUseCase: SendFeedbackEmailUseCase,
) : Model(), TangemPayTxHistoryUiActions, TangemPayDetailIntents, AddFundsListener {
private val params: TangemPayDetailsContainerComponent.Params = paramsContainer.require()
@ -236,27 +240,22 @@ internal class TangemPayDetailsModel @Inject constructor(
if (hasActiveWithdrawal) {
showBottomSheetError(TangemPayDetailsErrorType.WithdrawInProgress)
} else {
val userWallet = requireNotNull(
getUserWalletUseCase(params.userWalletId).getOrNull(),
) { "User wallet not found: ${params.userWalletId}" }
val data = tangemPaySwapDataFactory.create(
userWallet = userWallet,
depositAddress = depositAddress,
chainId = params.config.chainId,
cryptoBalance = currentBalance.cryptoBalance,
fiatBalance = currentBalance.fiatBalance,
).getOrNull()
if (data != null) {
val userWallet = getUserWalletUseCase(params.userWalletId).getOrNull()
val currency = userWallet?.let {
tangemPayCryptoCurrencyFactory.create(userWallet = userWallet, chainId = params.config.chainId)
.getOrNull()
}
if (currency != null) {
router.push(
AppRoute.Swap(
currencyFrom = data.currency,
userWalletId = data.walletId,
currencyFrom = currency,
userWalletId = params.userWalletId,
isInitialReverseOrder = false,
screenSource = AnalyticsParam.ScreensSources.TangemPay.value,
tangemPayInput = AppRoute.Swap.TangemPayInput(
cryptoAmount = data.cryptoBalance,
fiatAmount = data.fiatBalance,
depositAddress = data.depositAddress,
cryptoAmount = currentBalance.availableForWithdrawal,
fiatAmount = currentBalance.availableForWithdrawal,
depositAddress = depositAddress,
isWithdrawal = true,
),
),
@ -277,7 +276,13 @@ internal class TangemPayDetailsModel @Inject constructor(
Timber.e(e)
return@launch
}
uiState.update(DetailsBalanceTransformer(balance = result))
uiState.update(
transformer = DetailsBalanceTransformer(
balance = result,
userWallet = getUserWalletUseCase(params.userWalletId).getOrNull(),
cryptoCurrencyFactory = tangemPayCryptoCurrencyFactory,
),
)
}.saveIn(fetchBalanceJobHolder)
}
@ -305,6 +310,16 @@ internal class TangemPayDetailsModel @Inject constructor(
}.saveIn(addToWalletBannerJobHolder)
}
override fun onContactSupportClicked() {
modelScope.launch {
sendFeedbackEmailUseCase.invoke(
type = FeedbackEmailType.Visa.FeatureIsBeta(
walletMetaInfo = WalletMetaInfo(userWalletId = params.userWalletId),
),
)
}
}
override fun onRefreshSwipe(refreshState: ShowRefreshState) {
modelScope.launch {
uiState.update(TangemPayDetailsRefreshTransformer(isRefreshing = refreshState.value))

View file

@ -2,17 +2,24 @@ package com.tangem.features.tangempay.model.transformers
import arrow.core.Either
import com.tangem.core.error.UniversalError
import com.tangem.core.ui.format.bigdecimal.crypto
import com.tangem.core.ui.format.bigdecimal.fiat
import com.tangem.core.ui.format.bigdecimal.format
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.pay.TangemPayCryptoCurrencyFactory
import com.tangem.domain.pay.model.TangemPayCardBalance
import com.tangem.features.tangempay.entity.TangemPayDetailsBalanceBlockState
import com.tangem.features.tangempay.entity.TangemPayDetailsUM
import com.tangem.utils.transformer.Transformer
import kotlinx.collections.immutable.persistentListOf
import java.math.BigDecimal
import java.util.Currency
internal class DetailsBalanceTransformer(
private val balance: Either<UniversalError, TangemPayCardBalance>,
private val cryptoCurrencyFactory: TangemPayCryptoCurrencyFactory,
private val userWallet: UserWallet?,
) : Transformer<TangemPayDetailsUM> {
override fun transform(prevState: TangemPayDetailsUM): TangemPayDetailsUM {
@ -21,22 +28,32 @@ internal class DetailsBalanceTransformer(
TangemPayDetailsBalanceBlockState.Error(actionButtons = persistentListOf())
}
is Either.Right<TangemPayCardBalance> -> {
TangemPayDetailsBalanceBlockState.Content(
isBalanceFlickering = false,
fiatBalance = getBalanceText(balance.value),
// TODO [REDACTED_TASK_KEY]: Add crypto balance when the BFF is ready
cryptoBalance = "",
actionButtons = prevState.balanceBlockState.actionButtons,
)
val cryptoCurrency = userWallet?.let {
cryptoCurrencyFactory.create(userWallet, balance.value.chainId).getOrNull()
}
if (cryptoCurrency == null) {
TangemPayDetailsBalanceBlockState.Error(actionButtons = persistentListOf())
} else {
TangemPayDetailsBalanceBlockState.Content(
isBalanceFlickering = false,
fiatBalance = getFiatBalanceText(balance.value),
cryptoBalance = getCryptoBalanceText(balance.value.cryptoBalance, cryptoCurrency),
actionButtons = prevState.balanceBlockState.actionButtons,
)
}
}
}
return prevState.copy(balanceBlockState = balance)
}
private fun getBalanceText(balance: TangemPayCardBalance): String {
private fun getFiatBalanceText(balance: TangemPayCardBalance): String {
val currency = Currency.getInstance(balance.currencyCode)
return balance.fiatBalance.format {
fiat(fiatCurrencyCode = currency.currencyCode, fiatCurrencySymbol = currency.symbol)
}
}
private fun getCryptoBalanceText(cryptoBalance: BigDecimal, cryptoCurrency: CryptoCurrency): String {
return cryptoBalance.format { crypto(cryptoCurrency = cryptoCurrency) }
}
}

View file

@ -1,7 +1,7 @@
package com.tangem.features.tangempay.model.transformers
import com.tangem.core.ui.extensions.TextReference
import com.tangem.domain.pay.TangemPayTopUpData
import com.tangem.domain.pay.model.TangemPayTopUpData
import com.tangem.features.tangempay.components.AddFundsListener
import com.tangem.features.tangempay.details.impl.R
import com.tangem.features.tangempay.entity.TangemPayAddFundsItemUM

View file

@ -31,11 +31,10 @@ import com.tangem.core.ui.components.containers.pullToRefresh.PullToRefreshConfi
import com.tangem.core.ui.components.containers.pullToRefresh.TangemPullToRefreshContainer
import com.tangem.core.ui.components.dropdownmenu.TangemDropdownItem
import com.tangem.core.ui.components.dropdownmenu.TangemDropdownMenu
import com.tangem.core.ui.components.notifications.Notification
import com.tangem.core.ui.components.notifications.NotificationConfig
import com.tangem.core.ui.components.text.applyBladeBrush
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.orMaskWithStars
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.extensions.stringResourceSafe
import com.tangem.core.ui.extensions.*
import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.res.TangemThemePreview
import com.tangem.core.ui.test.TokenDetailsTopBarTestTags
@ -81,7 +80,9 @@ internal fun TangemPayDetailsScreen(
) {
item(TangemPayCardDetailsUM::class.java) {
cardDetailsBlockComponent.CardDetailsBlockContent(
modifier = Modifier.padding(horizontal = 16.dp).padding(top = 8.dp),
modifier = Modifier
.padding(horizontal = 16.dp)
.padding(top = 8.dp),
state = cardDetailsState,
)
}
@ -116,7 +117,7 @@ internal fun TangemPayDetailsScreen(
key = TangemPayDetailsBalanceBlockState::class.java,
content = {
TangemPayDetailsBalanceBlock(
modifier = modifier
modifier = Modifier
.padding(horizontal = TangemTheme.dimens.spacing16)
.padding(top = 12.dp)
.fillMaxWidth(),
@ -125,15 +126,32 @@ internal fun TangemPayDetailsScreen(
)
},
)
item(
key = "TANGEM_PAY_IS_IN_BETA",
content = {
TangemPayBetaBlock(
modifier = modifier
.padding(horizontal = TangemTheme.dimens.spacing16)
.padding(top = 12.dp)
.fillMaxWidth(),
config = state.betaNotificationConfig,
)
},
)
with(txHistoryComponent) { txHistoryContent(listState = listState, state = txHistoryState) }
}
}
}
}
@Composable
private fun TangemPayBetaBlock(config: NotificationConfig, modifier: Modifier = Modifier) {
Notification(modifier = modifier, config = config)
}
// region Balance block
@Composable
internal fun TangemPayDetailsBalanceBlock(
private fun TangemPayDetailsBalanceBlock(
state: TangemPayDetailsBalanceBlockState,
isBalanceHidden: Boolean,
modifier: Modifier = Modifier,
@ -157,12 +175,11 @@ internal fun TangemPayDetailsBalanceBlock(
state = state,
isBalanceHidden = isBalanceHidden,
)
// TODO [REDACTED_TASK_KEY]: Uncomment after adding crypto balance when the BFF is ready
// CryptoBalance(
// modifier = Modifier.padding(start = 12.dp, top = 4.dp),
// state = state,
// isBalanceHidden = isBalanceHidden,
// )
CryptoBalance(
modifier = Modifier.padding(start = 12.dp, top = 4.dp),
state = state,
isBalanceHidden = isBalanceHidden,
)
if (state.actionButtons.isNotEmpty()) {
HorizontalActionChips(
modifier = Modifier.padding(top = 12.dp),
@ -336,6 +353,16 @@ private class TangemPayDetailsUMProvider : CollectionPreviewParameterProvider<Ta
isBalanceHidden = false,
addFundsEnabled = true,
cardFrozenState = CardFrozenState.Frozen(onUnfreeze = {}),
betaNotificationConfig = NotificationConfig(
title = resourceReference(R.string.tangem_pay_beta_notification_title),
subtitle = resourceReference(R.string.tangem_pay_beta_notification_subtitle),
iconResId = R.drawable.img_visa_notification,
buttonsState = NotificationConfig.ButtonsState.SecondaryButtonConfig(
text = resourceReference(R.string.common_contact_support),
onClick = {},
),
iconSize = 36.dp,
),
),
TangemPayDetailsUM(
topBarConfig = TangemPayDetailsTopBarConfig(onBackClick = {}, items = null),
@ -345,6 +372,16 @@ private class TangemPayDetailsUMProvider : CollectionPreviewParameterProvider<Ta
isBalanceHidden = false,
addFundsEnabled = true,
cardFrozenState = CardFrozenState.Unfrozen,
betaNotificationConfig = NotificationConfig(
title = resourceReference(R.string.tangem_pay_beta_notification_title),
subtitle = resourceReference(R.string.tangem_pay_beta_notification_subtitle),
iconResId = R.drawable.img_visa_notification,
buttonsState = NotificationConfig.ButtonsState.SecondaryButtonConfig(
text = resourceReference(R.string.common_contact_support),
onClick = {},
),
iconSize = 36.dp,
),
),
),
)

View file

@ -3,6 +3,7 @@ package com.tangem.features.tangempay.utils
import com.tangem.core.ui.components.containers.pullToRefresh.PullToRefreshConfig.ShowRefreshState
internal interface TangemPayDetailIntents {
fun onContactSupportClicked()
fun onRefreshSwipe(refreshState: ShowRefreshState)
fun onClickAddFunds()
fun onClickWithdraw()

View file

@ -58,7 +58,7 @@ internal class TangemPayOnboardingModel @Inject constructor(
}
is TangemPayOnboardingComponent.Params.Deeplink -> {
repository.validateDeeplink(params.deeplink)
.onRight { isValid -> if (isValid) showOnboarding() }
.onRight { isValid -> if (isValid) showOnboarding() else back() }
.onLeft { back() }
}
}

View file

@ -93,7 +93,7 @@ internal class TangemPayClickIntentsImplementor @Inject constructor(
body = resourceReference(R.string.tangempay_failed_to_issue_card_support_description)
}
secondaryButton {
text = resourceReference(R.string.details_row_title_contact_to_support)
text = resourceReference(R.string.common_contact_support)
onClick {
onPaySupportClick()
closeBs()

View file

@ -51,7 +51,7 @@ sealed class WalletNotification(val config: NotificationConfig) {
title = resourceReference(R.string.warning_backup_errors_title),
subtitle = resourceReference(R.string.warning_backup_errors_message),
buttonsState = NotificationConfig.ButtonsState.PrimaryButtonConfig(
text = resourceReference(id = R.string.details_row_title_contact_to_support),
text = resourceReference(id = R.string.common_contact_support),
onClick = onSupportClick,
),
)