Updated on 2026-08-14
This commit is contained in:
parent
b623a457d9
commit
3af4539567
12 changed files with 56 additions and 35 deletions
|
|
@ -20,6 +20,6 @@ interface SendComponent : ComposableContentComponent {
|
|||
interface Factory : ComponentFactory<Params, SendComponent>
|
||||
|
||||
interface ModelCallback {
|
||||
fun onConvertToAnotherToken(lastAmount: String)
|
||||
fun onConvertToAnotherToken(lastAmount: String, isEnterInFiatSelected: Boolean)
|
||||
}
|
||||
}
|
||||
|
|
@ -30,9 +30,11 @@ internal class SendEntryPointModel @Inject constructor(
|
|||
ChooseManagedTokensComponent.ModelCallback {
|
||||
|
||||
private var lastSavedAmount = ""
|
||||
private var isEnterInFiat = false
|
||||
|
||||
override fun onConvertToAnotherToken(lastAmount: String) {
|
||||
override fun onConvertToAnotherToken(lastAmount: String, isEnterInFiatSelected: Boolean) {
|
||||
lastSavedAmount = lastAmount
|
||||
isEnterInFiat = isEnterInFiatSelected
|
||||
modelScope.launch {
|
||||
val showSendViaSwapNotification = shouldShowNotificationUseCase(
|
||||
NotificationId.SendViaSwapTokenSelectorNotification.key,
|
||||
|
|
@ -45,12 +47,11 @@ internal class SendEntryPointModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCloseSwap(lastAmount: String) {
|
||||
override fun onCloseSwap(lastAmount: String, isEnterInFiatSelected: Boolean) {
|
||||
lastSavedAmount = lastAmount
|
||||
isEnterInFiat = isEnterInFiatSelected
|
||||
modelScope.launch {
|
||||
if (lastAmount.isNotBlank()) {
|
||||
sendAmountUpdateTrigger.triggerUpdateAmount(lastAmount)
|
||||
}
|
||||
sendAmountUpdateTrigger.triggerUpdateAmount(lastAmount, isEnterInFiat)
|
||||
router.replaceAll(SendEntryRoute.Send)
|
||||
}
|
||||
}
|
||||
|
|
@ -58,9 +59,7 @@ internal class SendEntryPointModel @Inject constructor(
|
|||
@Suppress("MagicNumber")
|
||||
override fun onResult() {
|
||||
modelScope.launch {
|
||||
if (lastSavedAmount.isNotBlank()) {
|
||||
swapAmountUpdateTrigger.triggerUpdateAmount(lastSavedAmount)
|
||||
}
|
||||
swapAmountUpdateTrigger.triggerUpdateAmount(lastSavedAmount, isEnterInFiat)
|
||||
// Workaround in order to execute correct exit animation on SendEntryRoute.ChooseToken
|
||||
router.pop()
|
||||
delay(10L)
|
||||
|
|
@ -70,7 +69,7 @@ internal class SendEntryPointModel @Inject constructor(
|
|||
|
||||
override fun onBack() {
|
||||
modelScope.launch {
|
||||
sendAmountUpdateTrigger.triggerUpdateAmount(lastSavedAmount)
|
||||
sendAmountUpdateTrigger.triggerUpdateAmount(lastSavedAmount, isEnterInFiat)
|
||||
router.pop()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -227,14 +227,14 @@ internal class SendModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun onConvertToAnotherToken(lastAmount: String) {
|
||||
override fun onConvertToAnotherToken(lastAmount: String, isEnterInFiatSelected: Boolean) {
|
||||
analyticsEventHandler.send(
|
||||
SendAnalyticEvents.ConvertTokenButtonClicked(
|
||||
token = cryptoCurrency.symbol,
|
||||
blockchain = cryptoCurrency.network.name,
|
||||
),
|
||||
)
|
||||
params.callback?.onConvertToAnotherToken(lastAmount = lastAmount)
|
||||
params.callback?.onConvertToAnotherToken(lastAmount = lastAmount, isEnterInFiatSelected = isEnterInFiatSelected)
|
||||
}
|
||||
|
||||
override fun resetSendNavigation() {
|
||||
|
|
@ -455,7 +455,7 @@ internal class SendModel @Inject constructor(
|
|||
)
|
||||
// If it is in active state use flow to update value in amount component
|
||||
modelScope.launch {
|
||||
amount?.let { sendAmountUpdateTrigger.triggerUpdateAmount(it) }
|
||||
amount?.let { sendAmountUpdateTrigger.triggerUpdateAmount(it, null) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ internal class SendAmountComponent(
|
|||
|
||||
interface ModelCallback : NavigationModelCallback {
|
||||
fun onAmountResult(amountUM: AmountState, isResetPredefined: Boolean)
|
||||
fun onConvertToAnotherToken(lastAmount: String)
|
||||
fun onConvertToAnotherToken(lastAmount: String, isEnterInFiatSelected: Boolean)
|
||||
fun resetSendNavigation()
|
||||
fun onError(error: GetUserWalletError)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ interface SendAmountReduceListener {
|
|||
* Different from another triggers because it takes raw string instead of BigDecimal
|
||||
*/
|
||||
interface SendAmountUpdateTrigger {
|
||||
suspend fun triggerUpdateAmount(amountValue: String)
|
||||
suspend fun triggerUpdateAmount(amountValue: String, isEnterInFiatSelected: Boolean?)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -38,7 +38,7 @@ interface SendAmountUpdateTrigger {
|
|||
* Different from another triggers because it takes raw string instead of BigDecimal
|
||||
*/
|
||||
interface SendAmountUpdateListener {
|
||||
val updateAmountTriggerFlow: Flow<String>
|
||||
val updateAmountTriggerFlow: Flow<Pair<String, Boolean?>>
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
|
@ -51,7 +51,7 @@ internal class DefaultSendAmountReduceTrigger @Inject constructor() :
|
|||
override val reduceToTriggerFlow = MutableSharedFlow<BigDecimal>()
|
||||
override val reduceByTriggerFlow = MutableSharedFlow<ReduceByData>()
|
||||
override val ignoreReduceTriggerFlow = MutableSharedFlow<Unit>()
|
||||
override val updateAmountTriggerFlow = MutableSharedFlow<String>()
|
||||
override val updateAmountTriggerFlow = MutableSharedFlow<Pair<String, Boolean?>>()
|
||||
|
||||
override suspend fun triggerReduceBy(reduceBy: ReduceByData) {
|
||||
reduceByTriggerFlow.emit(reduceBy)
|
||||
|
|
@ -65,7 +65,7 @@ internal class DefaultSendAmountReduceTrigger @Inject constructor() :
|
|||
ignoreReduceTriggerFlow.emit(Unit)
|
||||
}
|
||||
|
||||
override suspend fun triggerUpdateAmount(amountValue: String) {
|
||||
updateAmountTriggerFlow.emit(amountValue)
|
||||
override suspend fun triggerUpdateAmount(amountValue: String, isEnterInFiatSelected: Boolean?) {
|
||||
updateAmountTriggerFlow.emit(amountValue to isEnterInFiatSelected)
|
||||
}
|
||||
}
|
||||
|
|
@ -290,7 +290,15 @@ internal class SendAmountModel @Inject constructor(
|
|||
isPrimaryButtonEnabled = false,
|
||||
) ?: it
|
||||
}
|
||||
amountParams.callback.onConvertToAnotherToken(amountFieldData?.amountTextField?.value.orEmpty())
|
||||
|
||||
val isEnterInFiatSelected = amountFieldData?.amountTextField?.isFiatValue == true
|
||||
val lastAmount = if (isEnterInFiatSelected) {
|
||||
amountFieldData.amountTextField.fiatValue
|
||||
} else {
|
||||
amountFieldData?.amountTextField?.value
|
||||
}
|
||||
|
||||
amountParams.callback.onConvertToAnotherToken(lastAmount.orEmpty(), isEnterInFiatSelected)
|
||||
}
|
||||
|
||||
private fun subscribeOnAmountReduceToTriggerUpdates() {
|
||||
|
|
@ -346,7 +354,8 @@ internal class SendAmountModel @Inject constructor(
|
|||
|
||||
private fun subscribeOnAmountUpdateTriggerUpdates() {
|
||||
sendAmountUpdateListener.updateAmountTriggerFlow
|
||||
.onEach { amount ->
|
||||
.onEach { (amount, isEnterInFiat) ->
|
||||
isEnterInFiat?.let { onCurrencyChangeClick(isEnterInFiat) }
|
||||
onAmountValueChange(amount)
|
||||
saveResult()
|
||||
}.launchIn(modelScope)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,6 @@ interface SendWithSwapComponent : ComposableContentComponent {
|
|||
interface Factory : ComponentFactory<Params, SendWithSwapComponent>
|
||||
|
||||
interface ModelCallback {
|
||||
fun onCloseSwap(lastAmount: String)
|
||||
fun onCloseSwap(lastAmount: String, isEnterInFiatSelected: Boolean)
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ package com.tangem.features.swap.v2.api.subcomponents
|
|||
* Different from another triggers because it takes raw string instead of BigDecimal
|
||||
*/
|
||||
interface SwapAmountUpdateTrigger {
|
||||
suspend fun triggerUpdateAmount(amountValue: String)
|
||||
suspend fun triggerUpdateAmount(amountValue: String, isEnterInFiatSelected: Boolean)
|
||||
|
||||
suspend fun triggerQuoteReload()
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ import javax.inject.Singleton
|
|||
* Different from another triggers because it takes raw string instead of BigDecimal
|
||||
*/
|
||||
interface SwapAmountUpdateListener {
|
||||
val updateAmountTriggerFlow: Flow<String>
|
||||
val updateAmountTriggerFlow: Flow<Pair<String, Boolean>>
|
||||
|
||||
val reloadQuotesTriggerFlow: Flow<Unit>
|
||||
}
|
||||
|
|
@ -44,8 +44,8 @@ internal class DefaultSwapAmountUpdateTrigger @Inject constructor() :
|
|||
SwapAmountReduceTrigger,
|
||||
SwapAmountReduceListener {
|
||||
|
||||
override val updateAmountTriggerFlow: SharedFlow<String>
|
||||
field = MutableSharedFlow<String>()
|
||||
override val updateAmountTriggerFlow: SharedFlow<Pair<String, Boolean>>
|
||||
field = MutableSharedFlow<Pair<String, Boolean>>()
|
||||
|
||||
override val reduceToTriggerFlow: SharedFlow<BigDecimal>
|
||||
field = MutableSharedFlow<BigDecimal>()
|
||||
|
|
@ -59,8 +59,8 @@ internal class DefaultSwapAmountUpdateTrigger @Inject constructor() :
|
|||
override val reloadQuotesTriggerFlow: Flow<Unit>
|
||||
field = MutableSharedFlow<Unit>()
|
||||
|
||||
override suspend fun triggerUpdateAmount(amountValue: String) {
|
||||
updateAmountTriggerFlow.emit(amountValue)
|
||||
override suspend fun triggerUpdateAmount(amountValue: String, isEnterInFiatSelected: Boolean) {
|
||||
updateAmountTriggerFlow.emit(amountValue to isEnterInFiatSelected)
|
||||
}
|
||||
|
||||
override suspend fun triggerQuoteReload() {
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ internal class SwapAmountComponent @AssistedInject constructor(
|
|||
|
||||
interface ModelCallback : NavigationModelCallback {
|
||||
fun onAmountResult(amountUM: SwapAmountUM)
|
||||
fun onSeparatorClick(lastAmount: String)
|
||||
fun onSeparatorClick(lastAmount: String, isEnterInFiatSelected: Boolean)
|
||||
fun resetSendWithSwapNavigation(resetNavigation: Boolean)
|
||||
}
|
||||
}
|
||||
|
|
@ -348,7 +348,10 @@ internal class SwapAmountModel @Inject constructor(
|
|||
|
||||
private fun confirmSendWithSwapClose() {
|
||||
val amountParams = params as? SwapAmountComponentParams.AmountParams ?: return
|
||||
val amountFieldData = uiState.value.primaryAmount.amountField as? AmountState.Data
|
||||
val amountField = uiState.value.swapDirection.withSwapDirection(
|
||||
onDirect = { uiState.value.primaryAmount },
|
||||
onReverse = { uiState.value.secondaryAmount },
|
||||
).amountField as? AmountState.Data
|
||||
|
||||
val primaryCryptoCurrencyStatus = (uiState.value as? SwapAmountUM.Content)?.primaryCryptoCurrencyStatus
|
||||
if (primaryCryptoCurrencyStatus != null) {
|
||||
|
|
@ -367,7 +370,16 @@ internal class SwapAmountModel @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
amountParams.callback.onSeparatorClick(lastAmount = amountFieldData?.amountTextField?.value.orEmpty())
|
||||
val isEnterInFiatSelected = amountField?.amountTextField?.isFiatValue == true
|
||||
val lastAmount = if (isEnterInFiatSelected) {
|
||||
amountField.amountTextField.fiatValue
|
||||
} else {
|
||||
amountField?.amountTextField?.value
|
||||
}
|
||||
amountParams.callback.onSeparatorClick(
|
||||
lastAmount = lastAmount.orEmpty(),
|
||||
isEnterInFiatSelected = isEnterInFiatSelected,
|
||||
)
|
||||
}
|
||||
|
||||
private fun subscribeOnCryptoCurrencyStatusFlow() {
|
||||
|
|
@ -407,9 +419,10 @@ internal class SwapAmountModel @Inject constructor(
|
|||
|
||||
private fun subscribeOnAmountUpdateTriggerUpdates() {
|
||||
swapAmountUpdateListener.updateAmountTriggerFlow
|
||||
.onEach {
|
||||
.onEach { (amount, isEnterInFiat) ->
|
||||
if (uiState.value is SwapAmountUM.Content) {
|
||||
onAmountValueChange(it)
|
||||
onCurrencyChangeClick(isEnterInFiat)
|
||||
onAmountValueChange(amount)
|
||||
saveResult()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,8 +110,8 @@ internal class SendWithSwapModel @Inject constructor(
|
|||
uiState.update { it.copy(navigationUM = navigationUM) }
|
||||
}
|
||||
|
||||
override fun onSeparatorClick(lastAmount: String) {
|
||||
params.callback?.onCloseSwap(lastAmount)
|
||||
override fun onSeparatorClick(lastAmount: String, isEnterInFiatSelected: Boolean) {
|
||||
params.callback?.onCloseSwap(lastAmount, isEnterInFiatSelected)
|
||||
router.popTo(initialRoute)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue