Updated on 2026-08-14
This commit is contained in:
commit
9c4bc63281
2 changed files with 59 additions and 24 deletions
|
|
@ -431,14 +431,14 @@ internal class SwapTransferStateBuilder @Inject constructor(
|
|||
val fromCurrency = fromSwapCurrencyStatus.currency
|
||||
val toCurrency = toSwapCurrencyStatus.currency
|
||||
val fromAmountText = amount.format { crypto(fromCurrency.symbol, fromCurrency.decimals) }
|
||||
val toAmountText = amount.format { crypto(toCurrency.symbol, toCurrency.decimals) }
|
||||
val toAmountText = transferState.sendingAmount.format { crypto(toCurrency.symbol, toCurrency.decimals) }
|
||||
val fromFiatAmount = getFormattedFiatAmount(
|
||||
appCurrency = transferState.appCurrency,
|
||||
amount = fromSwapCurrencyStatus.status.value.fiatRate?.multiply(amount),
|
||||
)
|
||||
val toFiatAmount = getFormattedFiatAmount(
|
||||
appCurrency = transferState.appCurrency,
|
||||
amount = toSwapCurrencyStatus.status.value.fiatRate?.multiply(amount),
|
||||
amount = toSwapCurrencyStatus.status.value.fiatRate?.multiply(transferState.sendingAmount),
|
||||
)
|
||||
|
||||
return uiState.copy(
|
||||
|
|
@ -488,11 +488,15 @@ internal class SwapTransferStateBuilder @Inject constructor(
|
|||
val fromSwapCurrencyStatus = requireNotNull(dataState.fromSwapCurrencyStatus)
|
||||
val toSwapCurrencyStatus = requireNotNull(dataState.toSwapCurrencyStatus)
|
||||
val transferState = requireNotNull(dataState.currentTransferState)
|
||||
val amountValue = transferState.sendingAmount
|
||||
|
||||
val fiatAmount = getFormattedFiatAmount(
|
||||
val fromAmount = dataState.amount?.parseBigDecimalOrNull() ?: BigDecimal.ZERO
|
||||
val toAmount = transferState.sendingAmount
|
||||
val fromFiatAmount = getFormattedFiatAmount(
|
||||
appCurrency = transferState.appCurrency,
|
||||
amount = fromSwapCurrencyStatus.status.value.fiatRate?.multiply(amountValue),
|
||||
amount = fromSwapCurrencyStatus.status.value.fiatRate?.multiply(fromAmount),
|
||||
)
|
||||
val toFiatAmount = getFormattedFiatAmount(
|
||||
appCurrency = transferState.appCurrency,
|
||||
amount = fromSwapCurrencyStatus.status.value.fiatRate?.multiply(toAmount),
|
||||
)
|
||||
|
||||
return uiState.copy(
|
||||
|
|
@ -516,10 +520,10 @@ internal class SwapTransferStateBuilder @Inject constructor(
|
|||
isAccountsMode = transferState.isAccountsMode,
|
||||
isFromCard = false,
|
||||
),
|
||||
fromTokenAmount = stringReference(amountValue.toString()),
|
||||
toTokenAmount = stringReference(amountValue.toString()),
|
||||
fromTokenFiatAmount = fiatAmount,
|
||||
toTokenFiatAmount = fiatAmount,
|
||||
fromTokenAmount = stringReference(fromAmount.toString()),
|
||||
toTokenAmount = stringReference(toAmount.toString()),
|
||||
fromTokenFiatAmount = fromFiatAmount,
|
||||
toTokenFiatAmount = toFiatAmount,
|
||||
fromTokenIconState = iconConverter.convert(fromSwapCurrencyStatus.status),
|
||||
toTokenIconState = iconConverter.convert(toSwapCurrencyStatus.status),
|
||||
navigationUM = swapSuccessNavigation(
|
||||
|
|
|
|||
|
|
@ -505,16 +505,18 @@ internal class SwapTransferStateBuilderTest {
|
|||
|
||||
@Test
|
||||
fun `GIVEN dataState with from-to currencies WHEN createSuccessState THEN success holder is built in transfer mode with given fee and txUrl`() {
|
||||
val amount = BigDecimal("1.5")
|
||||
// from amount comes from dataState.amount, to amount from transferState.sendingAmount — keep them distinct
|
||||
val fromAmount = BigDecimal("2.0")
|
||||
val toAmount = BigDecimal("1.5")
|
||||
val transferState = buildTransferState(
|
||||
fromAmount = amount,
|
||||
toAmount = amount,
|
||||
fromAmount = fromAmount,
|
||||
toAmount = toAmount,
|
||||
isAccountsMode = true,
|
||||
)
|
||||
val dataState = SwapProcessDataState(
|
||||
fromSwapCurrencyStatus = fromCurrencyStatus,
|
||||
toSwapCurrencyStatus = toCurrencyStatus,
|
||||
amount = amount.toPlainString(),
|
||||
amount = fromAmount.toPlainString(),
|
||||
currentTransferState = transferState,
|
||||
)
|
||||
val feeValue = BigDecimal("0.001")
|
||||
|
|
@ -556,6 +558,26 @@ internal class SwapTransferStateBuilderTest {
|
|||
assertThat(success.fromTokenIconState).isEqualTo(fromIcon)
|
||||
assertThat(success.toTokenIconState).isEqualTo(toIcon)
|
||||
|
||||
// from side reflects dataState.amount, to side reflects transferState.sendingAmount
|
||||
assertThat(success.fromTokenAmount)
|
||||
.isEqualTo(stringReference(fromAmount.format { crypto(symbol = "ETH", decimals = 18) }))
|
||||
assertThat(success.toTokenAmount)
|
||||
.isEqualTo(stringReference(toAmount.format { crypto(symbol = "ETH", decimals = 18) }))
|
||||
assertThat(success.fromTokenFiatAmount).isEqualTo(
|
||||
stringReference(
|
||||
fromCurrencyStatus.status.value.fiatRate!!.multiply(fromAmount).format {
|
||||
fiat(fiatCurrencyCode = appCurrency.code, fiatCurrencySymbol = appCurrency.symbol)
|
||||
},
|
||||
),
|
||||
)
|
||||
assertThat(success.toTokenFiatAmount).isEqualTo(
|
||||
stringReference(
|
||||
toCurrencyStatus.status.value.fiatRate!!.multiply(toAmount).format {
|
||||
fiat(fiatCurrencyCode = appCurrency.code, fiatCurrencySymbol = appCurrency.symbol)
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
val portfolioAccount = fromCurrencyStatus.account as Account.CryptoPortfolio
|
||||
val expectedIcon = CryptoPortfolioIconConverter.convert(portfolioAccount.icon)
|
||||
val expectedName = portfolioAccount.accountName.toUM().value
|
||||
|
|
@ -643,21 +665,30 @@ internal class SwapTransferStateBuilderTest {
|
|||
|
||||
@Test
|
||||
fun `GIVEN transfer dataState WHEN createTangemPayWithdrawalSuccessState THEN feeless transfer success holder is built`() {
|
||||
val sendingAmount = BigDecimal("1.5")
|
||||
// from amount comes from dataState.amount, to amount from transferState.sendingAmount — keep them distinct
|
||||
val fromAmount = BigDecimal("2.0")
|
||||
val toAmount = BigDecimal("1.5")
|
||||
val transferState = buildTransferState(
|
||||
fromAmount = sendingAmount,
|
||||
toAmount = sendingAmount,
|
||||
fromAmount = fromAmount,
|
||||
toAmount = toAmount,
|
||||
isAccountsMode = true,
|
||||
)
|
||||
val dataState = SwapProcessDataState(
|
||||
fromSwapCurrencyStatus = fromCurrencyStatus,
|
||||
toSwapCurrencyStatus = toCurrencyStatus,
|
||||
amount = fromAmount.toPlainString(),
|
||||
currentTransferState = transferState,
|
||||
)
|
||||
val onExploreClick = {}
|
||||
val appCurrency = transferState.appCurrency
|
||||
val expectedFiat = stringReference(
|
||||
fromCurrencyStatus.status.value.fiatRate!!.multiply(sendingAmount).format {
|
||||
// both fiat amounts use the from-currency rate (see createTangemPayWithdrawalSuccessState)
|
||||
val expectedFromFiat = stringReference(
|
||||
fromCurrencyStatus.status.value.fiatRate!!.multiply(fromAmount).format {
|
||||
fiat(fiatCurrencyCode = appCurrency.code, fiatCurrencySymbol = appCurrency.symbol)
|
||||
},
|
||||
)
|
||||
val expectedToFiat = stringReference(
|
||||
fromCurrencyStatus.status.value.fiatRate!!.multiply(toAmount).format {
|
||||
fiat(fiatCurrencyCode = appCurrency.code, fiatCurrencySymbol = appCurrency.symbol)
|
||||
},
|
||||
)
|
||||
|
|
@ -683,10 +714,10 @@ internal class SwapTransferStateBuilderTest {
|
|||
assertThat(success.rate).isEqualTo(TextReference.EMPTY)
|
||||
assertThat(success.timestamp).isAtLeast(before)
|
||||
assertThat(success.timestamp).isAtMost(after)
|
||||
assertThat(success.fromTokenAmount).isEqualTo(stringReference(sendingAmount.toString()))
|
||||
assertThat(success.toTokenAmount).isEqualTo(stringReference(sendingAmount.toString()))
|
||||
assertThat(success.fromTokenFiatAmount).isEqualTo(expectedFiat)
|
||||
assertThat(success.toTokenFiatAmount).isEqualTo(expectedFiat)
|
||||
assertThat(success.fromTokenAmount).isEqualTo(stringReference(fromAmount.toString()))
|
||||
assertThat(success.toTokenAmount).isEqualTo(stringReference(toAmount.toString()))
|
||||
assertThat(success.fromTokenFiatAmount).isEqualTo(expectedFromFiat)
|
||||
assertThat(success.toTokenFiatAmount).isEqualTo(expectedToFiat)
|
||||
assertThat(success.fromTokenIconState).isEqualTo(fromIcon)
|
||||
assertThat(success.toTokenIconState).isEqualTo(toIcon)
|
||||
assertThat((success.navigationUM as NavigationUM.Content).primaryButton.onClick).isEqualTo(onExploreClick)
|
||||
|
|
@ -768,7 +799,7 @@ internal class SwapTransferStateBuilderTest {
|
|||
isBalanceHidden = false,
|
||||
isAccountsMode = isAccountsMode,
|
||||
isFeeCoverage = false,
|
||||
sendingAmount = fromAmount,
|
||||
sendingAmount = toAmount,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue