Updated on 2026-08-14
This commit is contained in:
parent
1f8386c05e
commit
0bfc7eee60
11 changed files with 112 additions and 9 deletions
|
|
@ -44,6 +44,7 @@ internal data class TangemPayTxHistoryDetailsUMV2(
|
|||
val subtitle: TextReference,
|
||||
val iconState: TangemIconUM,
|
||||
val transactionTitle: TextReference,
|
||||
val card: TextReference?,
|
||||
val transactionCategory: TextReference,
|
||||
val mcc: TextReference?,
|
||||
val transactionAmount: String,
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import com.tangem.domain.feedback.GetWalletMetaInfoUseCase
|
|||
import com.tangem.domain.feedback.SendFeedbackEmailUseCase
|
||||
import com.tangem.domain.feedback.models.FeedbackEmailType
|
||||
import com.tangem.domain.tangempay.TangemPayAnalyticsEvents
|
||||
import com.tangem.domain.tangempay.repository.TangemPayTxHistoryRepository
|
||||
import com.tangem.domain.visa.model.TangemPayTxHistoryItem
|
||||
import com.tangem.features.tangempay.components.TangemPayTransactionBottomSheetComponent
|
||||
import com.tangem.features.tangempay.entity.TangemPayTxHistoryDetailsUiStates
|
||||
import com.tangem.features.tangempay.model.transformers.TangemPayTxHistoryDetailsConverter
|
||||
|
|
@ -31,31 +33,51 @@ internal class TangemPayTxHistoryDetailsModel @Inject constructor(
|
|||
private val sendFeedbackEmailUseCase: SendFeedbackEmailUseCase,
|
||||
private val urlOpener: UrlOpener,
|
||||
private val balanceHidingSettings: GetBalanceHidingSettingsUseCase,
|
||||
private val tangemPayTxHistoryRepository: TangemPayTxHistoryRepository,
|
||||
private val analytics: AnalyticsEventHandler,
|
||||
paramsContainer: ParamsContainer,
|
||||
) : Model() {
|
||||
|
||||
private val params = paramsContainer.require<TangemPayTransactionBottomSheetComponent.Params>()
|
||||
val uiState: StateFlow<TangemPayTxHistoryDetailsUiStates>
|
||||
field = MutableStateFlow(buildUiStates(isBalanceHidden = params.isBalanceHidden))
|
||||
|
||||
private val transaction = MutableStateFlow(params.transaction)
|
||||
|
||||
val uiState: StateFlow<TangemPayTxHistoryDetailsUiStates> = combine(
|
||||
balanceHidingSettings.isBalanceHidden(),
|
||||
transaction,
|
||||
) { isBalanceHidden, transaction ->
|
||||
buildUiStates(isBalanceHidden, transaction)
|
||||
}.stateIn(
|
||||
scope = modelScope,
|
||||
started = SharingStarted.Eagerly,
|
||||
initialValue = buildUiStates(isBalanceHidden = params.isBalanceHidden, transaction = params.transaction),
|
||||
)
|
||||
|
||||
init {
|
||||
subscribeToBalanceHiding()
|
||||
loadTransaction()
|
||||
}
|
||||
|
||||
fun dismiss() {
|
||||
params.onDismiss()
|
||||
}
|
||||
|
||||
private fun subscribeToBalanceHiding() {
|
||||
balanceHidingSettings.isBalanceHidden()
|
||||
.onEach { isBalanceHidden -> uiState.update { buildUiStates(isBalanceHidden) } }
|
||||
.launchIn(modelScope)
|
||||
private fun loadTransaction() {
|
||||
val current = params.transaction
|
||||
if (current !is TangemPayTxHistoryItem.Spend) return
|
||||
modelScope.launch {
|
||||
tangemPayTxHistoryRepository.getTransaction(
|
||||
userWalletId = params.userWalletId,
|
||||
transactionId = current.id,
|
||||
).onRight { loaded -> if (loaded != null) transaction.value = loaded }
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildUiStates(isBalanceHidden: Boolean): TangemPayTxHistoryDetailsUiStates {
|
||||
private fun buildUiStates(
|
||||
isBalanceHidden: Boolean,
|
||||
transaction: TangemPayTxHistoryItem,
|
||||
): TangemPayTxHistoryDetailsUiStates {
|
||||
val converterInput = TangemPayTxHistoryDetailsConverter.Input(
|
||||
item = params.transaction,
|
||||
item = transaction,
|
||||
isBalanceHidden = isBalanceHidden,
|
||||
onExplorerClick = ::openExplorer,
|
||||
onDisputeClick = { dispute(customerId = params.customerId) },
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ internal object TangemPayTxHistoryDetailsConverterV2 :
|
|||
subtitle = transaction.extractDate(),
|
||||
iconState = transaction.extractIcon(),
|
||||
transactionTitle = transaction.extractTransactionTitle(),
|
||||
card = transaction.extractCard(),
|
||||
transactionCategory = transaction.extractTransactionCategory(),
|
||||
mcc = transaction.extractMcc(),
|
||||
transactionAmount = transaction.extractAmount(),
|
||||
|
|
@ -289,6 +290,18 @@ internal object TangemPayTxHistoryDetailsConverterV2 :
|
|||
}
|
||||
}
|
||||
|
||||
private fun TangemPayTxHistoryItem.extractCard(): TextReference? {
|
||||
if (this !is TangemPayTxHistoryItem.Spend) return null
|
||||
val name = cardName?.takeIf { it.isNotEmpty() }
|
||||
val last4 = cardNumberLast4?.takeIf { it.isNotEmpty() }
|
||||
return when {
|
||||
name != null && last4 != null -> stringReference("$name *$last4")
|
||||
last4 != null -> stringReference("*$last4")
|
||||
name != null -> stringReference(name)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
private fun Input.extractButtonState(): ButtonState {
|
||||
return ButtonState(
|
||||
text = resourceReference(R.string.tangem_pay_get_help),
|
||||
|
|
|
|||
|
|
@ -233,6 +233,24 @@ internal fun TransactionLabel(label: TransactionLabelUM, modifier: Modifier = Mo
|
|||
@Composable
|
||||
private fun TransactionDetailsBlock(state: TangemPayTxHistoryDetailsUMV2, modifier: Modifier = Modifier) {
|
||||
Column(modifier = modifier) {
|
||||
if (state.card != null) {
|
||||
TangemRow(
|
||||
divider = true,
|
||||
contentLead = TangemRowContentLead.Start,
|
||||
titleSlot = {
|
||||
TangemRowText(
|
||||
text = resourceReference(R.string.tangempay_common_card),
|
||||
role = TangemRowTextRole.Title,
|
||||
)
|
||||
},
|
||||
valueSlot = {
|
||||
TangemRowText(
|
||||
text = state.card,
|
||||
role = TangemRowTextRole.Value,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
TangemRow(
|
||||
divider = state.mcc != null,
|
||||
contentLead = TangemRowContentLead.Start,
|
||||
|
|
@ -289,6 +307,7 @@ private class TangemPayTxHistoryDetailsUMProviderV2 :
|
|||
subtitle = stringReference("12 June 2026, 12:40"),
|
||||
iconState = TangemIconUM.Icon(iconRes = R.drawable.ic_category_24),
|
||||
transactionTitle = stringReference("Starbucks"),
|
||||
card = stringReference("Basic card *9092"),
|
||||
transactionCategory = stringReference("Food and drinks"),
|
||||
mcc = stringReference("5814"),
|
||||
transactionAmount = "-$5.86",
|
||||
|
|
@ -310,6 +329,7 @@ private class TangemPayTxHistoryDetailsUMProviderV2 :
|
|||
subtitle = stringReference("12 June 2026, 12:40"),
|
||||
iconState = TangemIconUM.Icon(iconRes = R.drawable.ic_category_24),
|
||||
transactionTitle = stringReference("NuCaloric"),
|
||||
card = stringReference("Basic card *9092"),
|
||||
transactionCategory = stringReference("Groceries"),
|
||||
mcc = stringReference("0000"),
|
||||
transactionAmount = "-$820.52",
|
||||
|
|
@ -332,6 +352,7 @@ private class TangemPayTxHistoryDetailsUMProviderV2 :
|
|||
subtitle = stringReference("12 June 2026, 12:40"),
|
||||
iconState = TangemIconUM.Icon(iconRes = R.drawable.ic_category_24),
|
||||
transactionTitle = stringReference("Starbucks"),
|
||||
card = stringReference("Basic card *9092"),
|
||||
transactionCategory = stringReference("Food and drinks"),
|
||||
mcc = null,
|
||||
transactionAmount = "-$5.86",
|
||||
|
|
@ -353,6 +374,7 @@ private class TangemPayTxHistoryDetailsUMProviderV2 :
|
|||
subtitle = stringReference("12 June 2026, 12:40"),
|
||||
iconState = TangemIconUM.Icon(iconRes = R.drawable.ic_percent_24),
|
||||
transactionTitle = stringReference("Service fees"),
|
||||
card = null,
|
||||
transactionCategory = stringReference("Service fees"),
|
||||
mcc = null,
|
||||
transactionAmount = "-$5.86",
|
||||
|
|
@ -375,6 +397,7 @@ private class TangemPayTxHistoryDetailsUMProviderV2 :
|
|||
subtitle = stringReference("12 June 2026, 12:40"),
|
||||
iconState = TangemIconUM.Icon(imageVector = Icons.ic_arrow_down_24),
|
||||
transactionTitle = resourceReference(R.string.common_transfer),
|
||||
card = null,
|
||||
transactionCategory = resourceReference(R.string.common_transfer),
|
||||
mcc = null,
|
||||
transactionAmount = "+$20",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue