From 844f84cb35ffe20919a9e49344d61beb5693d122 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 9 Apr 2025 10:23:18 +0500 Subject: [PATCH 1/2] Updated on 2026-08-14 --- .../features/send/v2/common/SendNavigationModelCallback.kt | 2 +- .../java/com/tangem/features/send/v2/common/ui/SendContent.kt | 3 +-- .../send/v2/{send => common}/ui/SendNavigationButtons.kt | 4 ++-- .../send/v2/common/ui/state/{ => ui/state}/NavigationUM.kt | 2 +- .../v2/di/{SendModelModule.kt => CommonSendModelModule.kt} | 2 +- .../java/com/tangem/features/send/v2/send/ui/state/SendUM.kt | 2 +- .../com/tangem/features/send/v2/sendnft/model/NFTSendModel.kt | 2 +- .../com/tangem/features/send/v2/sendnft/ui/state/NFTSendUM.kt | 2 +- .../features/send/v2/subcomponents/fee/model/SendFeeModel.kt | 2 +- 9 files changed, 10 insertions(+), 11 deletions(-) rename features/send-v2/impl/src/main/java/com/tangem/features/send/v2/{send => common}/ui/SendNavigationButtons.kt (97%) rename features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/state/{ => ui/state}/NavigationUM.kt (92%) rename features/send-v2/impl/src/main/java/com/tangem/features/send/v2/di/{SendModelModule.kt => CommonSendModelModule.kt} (96%) diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/SendNavigationModelCallback.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/SendNavigationModelCallback.kt index 0ce1403ae8..b004bbe3cb 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/SendNavigationModelCallback.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/SendNavigationModelCallback.kt @@ -1,6 +1,6 @@ package com.tangem.features.send.v2.common -import com.tangem.features.send.v2.common.ui.state.NavigationUM +import com.tangem.features.send.v2.common.ui.state.ui.state.NavigationUM internal interface SendNavigationModelCallback { fun onNavigationResult(navigationUM: NavigationUM) diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/SendContent.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/SendContent.kt index d5ac9cd311..10e15ec143 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/SendContent.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/SendContent.kt @@ -14,8 +14,7 @@ import com.tangem.core.ui.decompose.ComposableContentComponent import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme import com.tangem.features.send.v2.send.SendRoute -import com.tangem.features.send.v2.common.ui.state.NavigationUM -import com.tangem.features.send.v2.send.ui.SendNavigationButtons +import com.tangem.features.send.v2.common.ui.state.ui.state.NavigationUM @Composable internal fun SendContent(navigationUM: NavigationUM, stackState: ChildStack) { diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/ui/SendNavigationButtons.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/SendNavigationButtons.kt similarity index 97% rename from features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/ui/SendNavigationButtons.kt rename to features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/SendNavigationButtons.kt index 7edc75815f..801e9063b7 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/ui/SendNavigationButtons.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/SendNavigationButtons.kt @@ -1,4 +1,4 @@ -package com.tangem.features.send.v2.send.ui +package com.tangem.features.send.v2.common.ui import androidx.compose.animation.* import androidx.compose.foundation.background @@ -29,7 +29,7 @@ import com.tangem.core.ui.components.buttons.common.TangemButtonsDefaults import com.tangem.features.send.v2.send.ui.state.ButtonsUM import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme -import com.tangem.features.send.v2.common.ui.state.NavigationUM +import com.tangem.features.send.v2.common.ui.state.ui.state.NavigationUM @Composable internal fun SendNavigationButtons(navigationUM: NavigationUM, modifier: Modifier = Modifier) { diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/state/NavigationUM.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/state/ui/state/NavigationUM.kt similarity index 92% rename from features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/state/NavigationUM.kt rename to features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/state/ui/state/NavigationUM.kt index 404f1a3e73..59f2e9ba3d 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/state/NavigationUM.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/state/ui/state/NavigationUM.kt @@ -1,4 +1,4 @@ -package com.tangem.features.send.v2.common.ui.state +package com.tangem.features.send.v2.common.ui.state.ui.state import androidx.annotation.DrawableRes import androidx.compose.runtime.Immutable diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/di/SendModelModule.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/di/CommonSendModelModule.kt similarity index 96% rename from features/send-v2/impl/src/main/java/com/tangem/features/send/v2/di/SendModelModule.kt rename to features/send-v2/impl/src/main/java/com/tangem/features/send/v2/di/CommonSendModelModule.kt index 3c21d1380d..bb0fc819ab 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/di/SendModelModule.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/di/CommonSendModelModule.kt @@ -14,7 +14,7 @@ import dagger.multibindings.IntoMap @Module @InstallIn(ModelComponent::class) -internal interface SendModelModule { +internal interface CommonSendModelModule { @Binds @IntoMap diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/ui/state/SendUM.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/ui/state/SendUM.kt index 8359df5247..51cd9a1ae2 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/ui/state/SendUM.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/ui/state/SendUM.kt @@ -1,7 +1,7 @@ package com.tangem.features.send.v2.send.ui.state import com.tangem.common.ui.amountScreen.models.AmountState -import com.tangem.features.send.v2.common.ui.state.NavigationUM +import com.tangem.features.send.v2.common.ui.state.ui.state.NavigationUM import com.tangem.features.send.v2.common.ui.state.ConfirmUM import com.tangem.features.send.v2.subcomponents.destination.ui.state.DestinationUM import com.tangem.features.send.v2.subcomponents.fee.ui.state.FeeUM diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/model/NFTSendModel.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/model/NFTSendModel.kt index 3d5d6d178a..7e9b3a29bd 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/model/NFTSendModel.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/model/NFTSendModel.kt @@ -16,7 +16,7 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.usecase.GetUserWalletUseCase import com.tangem.features.send.v2.api.NFTSendComponent -import com.tangem.features.send.v2.common.ui.state.NavigationUM +import com.tangem.features.send.v2.common.ui.state.ui.state.NavigationUM import com.tangem.features.send.v2.common.ui.state.ConfirmUM import com.tangem.features.send.v2.sendnft.ui.state.NFTSendUM import com.tangem.features.send.v2.subcomponents.destination.SendDestinationComponent diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/ui/state/NFTSendUM.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/ui/state/NFTSendUM.kt index 526bfdd621..f67a071468 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/ui/state/NFTSendUM.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/ui/state/NFTSendUM.kt @@ -1,6 +1,6 @@ package com.tangem.features.send.v2.sendnft.ui.state -import com.tangem.features.send.v2.common.ui.state.NavigationUM +import com.tangem.features.send.v2.common.ui.state.ui.state.NavigationUM import com.tangem.features.send.v2.common.ui.state.ConfirmUM import com.tangem.features.send.v2.subcomponents.destination.ui.state.DestinationUM import com.tangem.features.send.v2.subcomponents.fee.ui.state.FeeUM diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/fee/model/SendFeeModel.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/fee/model/SendFeeModel.kt index 3a8d73d809..e82500c413 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/fee/model/SendFeeModel.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/fee/model/SendFeeModel.kt @@ -11,7 +11,7 @@ import com.tangem.core.navigation.url.UrlOpener import com.tangem.core.ui.extensions.resourceReference import com.tangem.domain.transaction.usecase.GetFeeUseCase import com.tangem.domain.transaction.usecase.IsFeeApproximateUseCase -import com.tangem.features.send.v2.common.ui.state.NavigationUM +import com.tangem.features.send.v2.common.ui.state.ui.state.NavigationUM import com.tangem.features.send.v2.impl.R import com.tangem.features.send.v2.send.ui.state.ButtonsUM import com.tangem.features.send.v2.subcomponents.fee.SendFeeCheckReloadTrigger From 1794605e26455c76874bcc7ba233f14a9cfde699 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 9 Apr 2025 10:23:30 +0500 Subject: [PATCH 2/2] Updated on 2026-08-14 --- .../send/v2/common/PredefinedValues.kt | 24 ++++ .../send/v2/common/SendBalanceUpdater.kt | 87 +++++++++++++ .../v2/common/SendNavigationModelCallback.kt | 2 +- .../features/send/v2/common/ui/SendContent.kt | 2 +- .../v2/common/ui/SendNavigationButtons.kt | 2 +- .../ui/state/{ui/state => }/NavigationUM.kt | 2 +- .../send/v2/send/DefaultSendComponent.kt | 9 +- .../v2/send/confirm/SendConfirmComponent.kt | 45 +++---- .../send/v2/send/confirm/model/ConfirmData.kt | 15 +++ .../v2/send/confirm/model/SendConfirmModel.kt | 119 +++++------------- .../features/send/v2/send/model/SendModel.kt | 13 +- .../features/send/v2/send/ui/state/SendUM.kt | 2 +- .../send/v2/sendnft/model/NFTSendModel.kt | 2 +- .../send/v2/sendnft/ui/state/NFTSendUM.kt | 2 +- .../amount/SendAmountBlockComponent.kt | 3 +- .../amount/SendAmountComponentParams.kt | 8 +- .../amount/model/SendAmountModel.kt | 6 +- .../SendDestinationBlockComponent.kt | 3 +- .../SendDestinationComponentParams.kt | 5 +- .../destination/model/SendDestinationModel.kt | 13 +- .../subcomponents/fee/model/SendFeeModel.kt | 2 +- .../notifications/NotificationsComponent.kt | 12 +- .../notifications/model/NotificationsModel.kt | 39 ++---- 23 files changed, 227 insertions(+), 190 deletions(-) create mode 100644 features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/PredefinedValues.kt create mode 100644 features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/SendBalanceUpdater.kt rename features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/state/{ui/state => }/NavigationUM.kt (92%) create mode 100644 features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/ConfirmData.kt diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/PredefinedValues.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/PredefinedValues.kt new file mode 100644 index 0000000000..adbfd84dfc --- /dev/null +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/PredefinedValues.kt @@ -0,0 +1,24 @@ +package com.tangem.features.send.v2.common + +sealed class PredefinedValues { + data object Empty : PredefinedValues() + + sealed class Content : PredefinedValues() { + abstract val amount: String + abstract val address: String + abstract val memo: String? + + data class Deeplink( + override val amount: String, + override val address: String, + override val memo: String?, + val transactionId: String, + ) : Content() + + data class QrCode( + override val amount: String, + override val address: String, + override val memo: String?, + ) : Content() + } +} \ No newline at end of file diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/SendBalanceUpdater.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/SendBalanceUpdater.kt new file mode 100644 index 0000000000..69254405cf --- /dev/null +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/SendBalanceUpdater.kt @@ -0,0 +1,87 @@ +package com.tangem.features.send.v2.common + +import com.tangem.domain.tokens.FetchPendingTransactionsUseCase +import com.tangem.domain.tokens.UpdateDelayedNetworkStatusUseCase +import com.tangem.domain.tokens.model.CryptoCurrency +import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsCountUseCase +import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsUseCase +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.features.txhistory.TxHistoryFeatureToggles +import com.tangem.features.txhistory.entity.TxHistoryContentUpdateEmitter +import com.tangem.utils.coroutines.DelayedWork +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject +import kotlinx.coroutines.* + +@Suppress("LongParameterList") +internal class SendBalanceUpdater @AssistedInject constructor( + private val fetchPendingTransactionsUseCase: FetchPendingTransactionsUseCase, + private val updateDelayedNetworkStatusUseCase: UpdateDelayedNetworkStatusUseCase, + private val getTxHistoryItemsCountUseCase: GetTxHistoryItemsCountUseCase, + private val getTxHistoryItemsUseCase: GetTxHistoryItemsUseCase, + private val txHistoryFeatureToggles: TxHistoryFeatureToggles, + private val txHistoryContentUpdateEmitter: TxHistoryContentUpdateEmitter, + @DelayedWork private val coroutineScope: CoroutineScope, + @Assisted private val userWallet: UserWallet, + @Assisted private val cryptoCurrency: CryptoCurrency, +) { + fun scheduleUpdates() { + coroutineScope.launch { + listOf( + // we should update network to find pending tx after 1 sec + async { + fetchPendingTransactionsUseCase( + userWalletId = userWallet.walletId, + networks = setOf(cryptoCurrency.network), + ) + }, + // we should update tx history and network for new balances + async { + updateTxHistory() + }, + async { + updateNetworkStatuses() + }, + ).awaitAll() + } + } + + private suspend fun updateNetworkStatuses(delay: Long = BALANCE_UPDATE_DELAY) { + updateDelayedNetworkStatusUseCase( + userWalletId = userWallet.walletId, + network = cryptoCurrency.network, + delayMillis = delay, + refresh = true, + ) + } + + private suspend fun updateTxHistory() { + delay(BALANCE_UPDATE_DELAY) + val txHistoryItemsCountEither = getTxHistoryItemsCountUseCase( + userWalletId = userWallet.walletId, + currency = cryptoCurrency, + ) + + txHistoryItemsCountEither.onRight { + if (txHistoryFeatureToggles.isFeatureEnabled) { + txHistoryContentUpdateEmitter.triggerUpdate() + } else { + getTxHistoryItemsUseCase( + userWalletId = userWallet.walletId, + currency = cryptoCurrency, + refresh = true, + ) + } + } + } + + private companion object { + const val BALANCE_UPDATE_DELAY = 11_000L + } + + @AssistedFactory + interface Factory { + fun create(cryptoCurrency: CryptoCurrency, userWallet: UserWallet): SendBalanceUpdater + } +} \ No newline at end of file diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/SendNavigationModelCallback.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/SendNavigationModelCallback.kt index b004bbe3cb..0ce1403ae8 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/SendNavigationModelCallback.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/SendNavigationModelCallback.kt @@ -1,6 +1,6 @@ package com.tangem.features.send.v2.common -import com.tangem.features.send.v2.common.ui.state.ui.state.NavigationUM +import com.tangem.features.send.v2.common.ui.state.NavigationUM internal interface SendNavigationModelCallback { fun onNavigationResult(navigationUM: NavigationUM) diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/SendContent.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/SendContent.kt index 10e15ec143..265067a7df 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/SendContent.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/SendContent.kt @@ -14,7 +14,7 @@ import com.tangem.core.ui.decompose.ComposableContentComponent import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme import com.tangem.features.send.v2.send.SendRoute -import com.tangem.features.send.v2.common.ui.state.ui.state.NavigationUM +import com.tangem.features.send.v2.common.ui.state.NavigationUM @Composable internal fun SendContent(navigationUM: NavigationUM, stackState: ChildStack) { diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/SendNavigationButtons.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/SendNavigationButtons.kt index 801e9063b7..581e14ba92 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/SendNavigationButtons.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/SendNavigationButtons.kt @@ -29,7 +29,7 @@ import com.tangem.core.ui.components.buttons.common.TangemButtonsDefaults import com.tangem.features.send.v2.send.ui.state.ButtonsUM import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme -import com.tangem.features.send.v2.common.ui.state.ui.state.NavigationUM +import com.tangem.features.send.v2.common.ui.state.NavigationUM @Composable internal fun SendNavigationButtons(navigationUM: NavigationUM, modifier: Modifier = Modifier) { diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/state/ui/state/NavigationUM.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/state/NavigationUM.kt similarity index 92% rename from features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/state/ui/state/NavigationUM.kt rename to features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/state/NavigationUM.kt index 59f2e9ba3d..404f1a3e73 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/state/ui/state/NavigationUM.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/common/ui/state/NavigationUM.kt @@ -1,4 +1,4 @@ -package com.tangem.features.send.v2.common.ui.state.ui.state +package com.tangem.features.send.v2.common.ui.state import androidx.annotation.DrawableRes import androidx.compose.runtime.Immutable diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/DefaultSendComponent.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/DefaultSendComponent.kt index d54221cbd4..07a7427df4 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/DefaultSendComponent.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/DefaultSendComponent.kt @@ -19,6 +19,7 @@ import com.tangem.core.decompose.model.getOrCreateModel import com.tangem.core.decompose.navigation.inner.InnerRouter import com.tangem.core.ui.decompose.ComposableContentComponent import com.tangem.features.send.v2.api.SendComponent +import com.tangem.features.send.v2.common.PredefinedValues import com.tangem.features.send.v2.common.ui.SendContent import com.tangem.features.send.v2.common.ui.state.ConfirmUM import com.tangem.features.send.v2.send.analytics.SendAnalyticEvents @@ -152,7 +153,7 @@ internal class DefaultSendComponent @AssistedInject constructor( cryptoCurrencyStatus = model.cryptoCurrencyStatus, callback = model, isEditMode = route.isEditMode, - predefinedAmountValue = model.predefinedAmountValue, + predefinedValues = model.predefinedValues, ), ) @@ -187,14 +188,14 @@ internal class DefaultSendComponent @AssistedInject constructor( val predefinedAddress = params.destinationAddress val predefinedValues = if (predefinedAmount != null && predefinedTxId != null && predefinedAddress != null) { - SendConfirmComponent.Params.PredefinedValues.Content( + PredefinedValues.Content.Deeplink( amount = predefinedAmount, address = predefinedAddress, - tag = params.tag, + memo = params.tag, transactionId = predefinedTxId, ) } else { - SendConfirmComponent.Params.PredefinedValues.Empty + PredefinedValues.Empty } return SendConfirmComponent( appComponentContext = factoryContext, diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/SendConfirmComponent.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/SendConfirmComponent.kt index 0d5c803926..3acce0b9c5 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/SendConfirmComponent.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/SendConfirmComponent.kt @@ -11,6 +11,7 @@ import com.tangem.core.ui.decompose.ComposableContentComponent import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWallet +import com.tangem.features.send.v2.common.PredefinedValues import com.tangem.features.send.v2.send.SendRoute import com.tangem.features.send.v2.send.confirm.model.SendConfirmModel import com.tangem.features.send.v2.send.confirm.ui.SendConfirmContent @@ -19,10 +20,11 @@ import com.tangem.features.send.v2.send.ui.state.SendUM import com.tangem.features.send.v2.subcomponents.amount.SendAmountBlockComponent import com.tangem.features.send.v2.subcomponents.amount.SendAmountComponentParams import com.tangem.features.send.v2.subcomponents.destination.SendDestinationBlockComponent -import com.tangem.features.send.v2.subcomponents.destination.SendDestinationComponentParams +import com.tangem.features.send.v2.subcomponents.destination.SendDestinationComponentParams.DestinationBlockParams import com.tangem.features.send.v2.subcomponents.fee.SendFeeBlockComponent import com.tangem.features.send.v2.subcomponents.fee.SendFeeComponentParams import com.tangem.features.send.v2.subcomponents.notifications.NotificationsComponent +import com.tangem.features.send.v2.subcomponents.notifications.model.NotificationData import com.tangem.utils.extensions.orZero import kotlinx.coroutines.flow.* @@ -38,15 +40,13 @@ internal class SendConfirmComponent( private val destinationBlockComponent = SendDestinationBlockComponent( appComponentContext = child("sendConfirmDestinationBlock"), - params = SendDestinationComponentParams.DestinationBlockParams( + params = DestinationBlockParams( state = model.uiState.value.destinationUM, analyticsCategoryName = params.analyticsCategoryName, userWalletId = params.userWallet.walletId, cryptoCurrency = params.cryptoCurrencyStatus.currency, blockClickEnableFlow = blockClickEnableFlow.asStateFlow(), - isPredefinedValues = params.predefinedValues is Params.PredefinedValues.Content, - predefinedAddressValue = (params.predefinedValues as? Params.PredefinedValues.Content)?.address, - predefinedMemoValue = (params.predefinedValues as? Params.PredefinedValues.Content)?.tag, + predefinedValues = params.predefinedValues, ), onResult = model::onDestinationResult, onClick = model::showEditDestination, @@ -61,8 +61,7 @@ internal class SendConfirmComponent( cryptoCurrencyStatus = params.cryptoCurrencyStatus, appCurrency = params.appCurrency, blockClickEnableFlow = blockClickEnableFlow.asStateFlow(), - isPredefinedValues = params.predefinedValues is Params.PredefinedValues.Content, - predefinedAmountValue = (params.predefinedValues as? Params.PredefinedValues.Content)?.amount, + predefinedValues = params.predefinedValues, ), onResult = model::onAmountResult, onClick = model::showEditAmount, @@ -77,8 +76,8 @@ internal class SendConfirmComponent( cryptoCurrencyStatus = params.cryptoCurrencyStatus, feeCryptoCurrencyStatus = params.feeCryptoCurrencyStatus, appCurrency = params.appCurrency, - sendAmount = model.enteredAmount.orZero(), - destinationAddress = model.enteredDestination.orEmpty(), + sendAmount = model.confirmData.enteredAmount.orZero(), + destinationAddress = model.confirmData.enteredDestination.orEmpty(), blockClickEnableFlow = blockClickEnableFlow.asStateFlow(), ), onResult = model::onFeeResult, @@ -93,13 +92,15 @@ internal class SendConfirmComponent( cryptoCurrencyStatus = params.cryptoCurrencyStatus, feeCryptoCurrencyStatus = params.feeCryptoCurrencyStatus, appCurrency = params.appCurrency, - destinationAddress = model.enteredDestination.orEmpty(), - memo = model.enteredMemo, - amountValue = model.enteredAmount.orZero(), - reduceAmountBy = model.reduceAmountBy.orZero(), - isIgnoreReduce = model.isIgnoreReduce, - fee = model.fee, - feeError = model.feeError, + notificationData = NotificationData( + destinationAddress = model.confirmData.enteredDestination.orEmpty(), + memo = model.confirmData.enteredMemo, + amountValue = model.confirmData.enteredAmount.orZero(), + reduceAmountBy = model.confirmData.reduceAmountBy.orZero(), + isIgnoreReduce = model.confirmData.isIgnoreReduce, + fee = model.confirmData.fee, + feeError = model.confirmData.feeError, + ), ), ) @@ -143,17 +144,7 @@ internal class SendConfirmComponent( val currentRoute: Flow, val isBalanceHidingFlow: StateFlow, val predefinedValues: PredefinedValues, - ) { - sealed class PredefinedValues { - data object Empty : PredefinedValues() - data class Content( - val transactionId: String, - val amount: String, - val address: String, - val tag: String?, - ) : PredefinedValues() - } - } + ) interface ModelCallback { fun onResult(sendUM: SendUM) diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/ConfirmData.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/ConfirmData.kt new file mode 100644 index 0000000000..e6aa732445 --- /dev/null +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/ConfirmData.kt @@ -0,0 +1,15 @@ +package com.tangem.features.send.v2.send.confirm.model + +import com.tangem.blockchain.common.transaction.Fee +import com.tangem.domain.transaction.error.GetFeeError +import java.math.BigDecimal + +data class ConfirmData( + val enteredAmount: BigDecimal?, + val reduceAmountBy: BigDecimal, + val isIgnoreReduce: Boolean, + val enteredDestination: String?, + val enteredMemo: String?, + val fee: Fee?, + val feeError: GetFeeError?, +) \ No newline at end of file diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/SendConfirmModel.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/SendConfirmModel.kt index ebad9698e0..cb79ab86b1 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/SendConfirmModel.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/SendConfirmModel.kt @@ -5,7 +5,6 @@ import androidx.compose.runtime.Stable import arrow.core.getOrElse import com.tangem.blockchain.common.AmountType import com.tangem.blockchain.common.TransactionData -import com.tangem.blockchain.common.transaction.Fee import com.tangem.common.routing.AppRouter import com.tangem.common.ui.amountScreen.models.AmountState import com.tangem.core.analytics.api.AnalyticsEventHandler @@ -25,17 +24,13 @@ import com.tangem.domain.feedback.models.FeedbackEmailType import com.tangem.domain.settings.IsSendTapHelpEnabledUseCase import com.tangem.domain.settings.NeverShowTapHelpUseCase import com.tangem.domain.tokens.AddCryptoCurrenciesUseCase -import com.tangem.domain.tokens.FetchPendingTransactionsUseCase import com.tangem.domain.tokens.IsAmountSubtractAvailableUseCase -import com.tangem.domain.tokens.UpdateDelayedNetworkStatusUseCase import com.tangem.domain.tokens.model.CryptoCurrency -import com.tangem.domain.transaction.error.GetFeeError import com.tangem.domain.transaction.usecase.CreateTransactionUseCase import com.tangem.domain.transaction.usecase.SendTransactionUseCase import com.tangem.domain.txhistory.usecase.GetExplorerTransactionUrlUseCase -import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsCountUseCase -import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsUseCase import com.tangem.domain.utils.convertToSdkAmount +import com.tangem.features.send.v2.common.SendBalanceUpdater import com.tangem.features.send.v2.common.ui.state.ConfirmUM import com.tangem.features.send.v2.common.ui.state.NavigationUM import com.tangem.features.send.v2.impl.R @@ -57,17 +52,13 @@ import com.tangem.features.send.v2.subcomponents.fee.ui.state.FeeSelectorUM import com.tangem.features.send.v2.subcomponents.fee.ui.state.FeeUM import com.tangem.features.send.v2.subcomponents.notifications.NotificationsUpdateTrigger import com.tangem.features.send.v2.subcomponents.notifications.model.NotificationData -import com.tangem.features.txhistory.TxHistoryFeatureToggles -import com.tangem.features.txhistory.entity.TxHistoryContentUpdateEmitter import com.tangem.utils.coroutines.CoroutineDispatcherProvider -import com.tangem.utils.coroutines.DelayedWork import com.tangem.utils.extensions.orZero import com.tangem.utils.extensions.stripZeroPlainString import com.tangem.utils.transformer.update -import kotlinx.coroutines.* import kotlinx.coroutines.flow.* +import kotlinx.coroutines.launch import timber.log.Timber -import java.math.BigDecimal import javax.inject.Inject @Suppress("LongParameterList", "LargeClass") @@ -88,20 +79,14 @@ internal class SendConfirmModel @Inject constructor( private val sendFeedbackEmailUseCase: SendFeedbackEmailUseCase, private val addCryptoCurrenciesUseCase: AddCryptoCurrenciesUseCase, private val getExplorerTransactionUrlUseCase: GetExplorerTransactionUrlUseCase, - private val fetchPendingTransactionsUseCase: FetchPendingTransactionsUseCase, - private val updateDelayedCurrencyStatusUseCase: UpdateDelayedNetworkStatusUseCase, - private val getTxHistoryItemsCountUseCase: GetTxHistoryItemsCountUseCase, private val isAmountSubtractAvailableUseCase: IsAmountSubtractAvailableUseCase, - private val getTxHistoryItemsUseCase: GetTxHistoryItemsUseCase, private val sendFeeCheckReloadTrigger: SendFeeCheckReloadTrigger, - private val txHistoryContentUpdateEmitter: TxHistoryContentUpdateEmitter, private val notificationsUpdateTrigger: NotificationsUpdateTrigger, private val alertFactory: SendConfirmAlertFactory, private val sendAnalyticHelper: SendAnalyticHelper, - private val txHistoryFeatureToggles: TxHistoryFeatureToggles, - @DelayedWork private val coroutineScope: CoroutineScope, private val urlOpener: UrlOpener, private val shareManager: ShareManager, + sendBalanceUpdaterFactory: SendBalanceUpdater.Factory, ) : Model(), SendConfirmClickIntents { private val params: SendConfirmComponent.Params = paramsContainer.require() @@ -111,6 +96,8 @@ internal class SendConfirmModel @Inject constructor( private val cryptoCurrencyStatus = params.cryptoCurrencyStatus private val cryptoCurrency = cryptoCurrencyStatus.currency + private val sendBalanceUpdater = sendBalanceUpdaterFactory.create(cryptoCurrency, userWallet) + private val _uiState = MutableStateFlow(params.state) val uiState = _uiState.asStateFlow() @@ -123,20 +110,16 @@ internal class SendConfirmModel @Inject constructor( private val feeSelectorUM get() = feeUM?.feeSelectorUM as? FeeSelectorUM.Content - val enteredAmount: BigDecimal? - get() = amountState?.amountTextField?.cryptoAmount?.value - val reduceAmountBy: BigDecimal - get() = amountState?.reduceAmountBy.orZero() - val isIgnoreReduce: Boolean - get() = amountState?.isIgnoreReduce == true - val enteredDestination: String? - get() = destinationUM?.addressTextField?.value - val enteredMemo: String? - get() = destinationUM?.memoTextField?.value - val fee: Fee? - get() = feeSelectorUM?.selectedFee - val feeError: GetFeeError? - get() = (feeUM?.feeSelectorUM as? FeeSelectorUM.Error)?.error + val confirmData: ConfirmData + get() = ConfirmData( + enteredAmount = amountState?.amountTextField?.cryptoAmount?.value, + enteredMemo = destinationUM?.memoTextField?.value, + reduceAmountBy = amountState?.reduceAmountBy.orZero(), + isIgnoreReduce = amountState?.isIgnoreReduce == true, + enteredDestination = destinationUM?.addressTextField?.value, + fee = feeSelectorUM?.selectedFee, + feeError = (feeUM?.feeSelectorUM as? FeeSelectorUM.Error)?.error, + ) private var sendIdleTimer: Long = 0L private var isAmountSubtractAvailable = false @@ -234,15 +217,15 @@ internal class SendConfirmModel @Inject constructor( override fun onFailedTxEmailClick(errorMessage: String) { val amountValue = amountState?.amountTextField?.cryptoAmount?.value - val feeValue = fee?.amount?.value + val feeValue = confirmData.fee?.amount?.value val receivingAmount = if (amountValue != null && feeValue != null) { checkAndCalculateSubtractedAmount( isAmountSubtractAvailable = isAmountSubtractAvailable, cryptoCurrencyStatus = cryptoCurrencyStatus, - amountValue = enteredAmount.orZero(), + amountValue = confirmData.enteredAmount.orZero(), feeValue = feeValue, - reduceAmountBy = reduceAmountBy, + reduceAmountBy = confirmData.reduceAmountBy, ) } else { null @@ -255,7 +238,7 @@ internal class SendConfirmModel @Inject constructor( errorMessage = errorMessage, blockchainId = cryptoCurrency.network.id.value, derivationPath = cryptoCurrency.network.derivationPath.value, - destinationAddress = enteredDestination.orEmpty(), + destinationAddress = confirmData.enteredDestination.orEmpty(), tokenSymbol = if (amount?.type is AmountType.Token) { amount.currencySymbol } else { @@ -320,7 +303,7 @@ internal class SendConfirmModel @Inject constructor( cryptoCurrencyStatus = cryptoCurrencyStatus, amountValue = amountValue, feeValue = feeValue, - reduceAmountBy = reduceAmountBy.orZero(), + reduceAmountBy = confirmData.reduceAmountBy.orZero(), ) modelScope.launch { @@ -367,7 +350,7 @@ internal class SendConfirmModel @Inject constructor( ifRight = { updateTransactionStatus(txData) addTokenToWalletIfNeeded() - scheduleUpdates() + sendBalanceUpdater.scheduleUpdates() sendAnalyticHelper.sendSuccessAnalytics(cryptoCurrency, uiState.value) }, ) @@ -378,7 +361,7 @@ internal class SendConfirmModel @Inject constructor( val wallets = destinationUM?.wallets ?: return val receivingUserWallet = wallets - .firstOrNull { it.address == enteredDestination } + .firstOrNull { it.address == confirmData.enteredDestination } ?: return val userWalletId = receivingUserWallet.userWalletId ?: return @@ -401,49 +384,6 @@ internal class SendConfirmModel @Inject constructor( _uiState.update(SendConfirmSentStateTransformer(txData, txUrl)) } - private fun scheduleUpdates() { - coroutineScope.launch { - listOf( - // we should update network to find pending tx after 1 sec - async { - fetchPendingTransactionsUseCase(userWallet.walletId, setOf(cryptoCurrency.network)) - }, - // we should update tx history and network for new balance - async { - updateTxHistory() - }, - async { - updateDelayedCurrencyStatusUseCase( - userWalletId = userWallet.walletId, - network = cryptoCurrency.network, - delayMillis = BALANCE_UPDATE_DELAY, - refresh = true, - ) - }, - ).awaitAll() - } - } - - private suspend fun updateTxHistory() { - delay(BALANCE_UPDATE_DELAY) - val txHistoryItemsCountEither = getTxHistoryItemsCountUseCase( - userWalletId = userWallet.walletId, - currency = cryptoCurrency, - ) - - txHistoryItemsCountEither.onRight { - if (txHistoryFeatureToggles.isFeatureEnabled) { - txHistoryContentUpdateEmitter.triggerUpdate() - } else { - getTxHistoryItemsUseCase( - userWalletId = userWallet.walletId, - currency = cryptoCurrency, - refresh = true, - ) - } - } - } - private fun subscribeOnCheckFeeResultUpdates() { sendFeeCheckReloadTrigger.checkReloadResultFlow.onEach { isFeeResultSuccess -> if (isFeeResultSuccess) { @@ -460,13 +400,13 @@ internal class SendConfirmModel @Inject constructor( modelScope.launch { notificationsUpdateTrigger.triggerUpdate( data = NotificationData( - destinationAddress = enteredDestination.orEmpty(), - memo = enteredMemo, - amountValue = enteredAmount.orZero(), - reduceAmountBy = reduceAmountBy.orZero(), - isIgnoreReduce = isIgnoreReduce, - fee = fee, - feeError = feeError, + destinationAddress = confirmData.enteredDestination.orEmpty(), + memo = confirmData.enteredMemo, + amountValue = confirmData.enteredAmount.orZero(), + reduceAmountBy = confirmData.reduceAmountBy.orZero(), + isIgnoreReduce = confirmData.isIgnoreReduce, + fee = confirmData.fee, + feeError = confirmData.feeError, ), ) _uiState.update { @@ -552,6 +492,5 @@ internal class SendConfirmModel @Inject constructor( private companion object { const val CHECK_FEE_UPDATE_DELAY = 10_000L - const val BALANCE_UPDATE_DELAY = 11_000L } } \ No newline at end of file diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/model/SendModel.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/model/SendModel.kt index 44a2787062..ad59d24108 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/model/SendModel.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/model/SendModel.kt @@ -29,11 +29,12 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.usecase.GetUserWalletUseCase import com.tangem.features.send.v2.api.SendComponent +import com.tangem.features.send.v2.common.PredefinedValues +import com.tangem.features.send.v2.common.ui.state.ConfirmUM import com.tangem.features.send.v2.common.ui.state.NavigationUM import com.tangem.features.send.v2.send.SendRoute -import com.tangem.features.send.v2.send.confirm.model.SendConfirmAlertFactory import com.tangem.features.send.v2.send.confirm.SendConfirmComponent -import com.tangem.features.send.v2.common.ui.state.ConfirmUM +import com.tangem.features.send.v2.send.confirm.model.SendConfirmAlertFactory import com.tangem.features.send.v2.send.ui.state.SendUM import com.tangem.features.send.v2.subcomponents.amount.SendAmountComponent import com.tangem.features.send.v2.subcomponents.destination.SendDestinationComponent @@ -90,7 +91,7 @@ internal class SendModel @Inject constructor( var cryptoCurrencyStatus: CryptoCurrencyStatus by Delegates.notNull() var feeCryptoCurrencyStatus: CryptoCurrencyStatus by Delegates.notNull() var appCurrency: AppCurrency = AppCurrency.Default - var predefinedAmountValue: String? = null + var predefinedValues: PredefinedValues = PredefinedValues.Empty private var balanceHidingJobHolder = JobHolder() @@ -227,7 +228,11 @@ internal class SendModel @Inject constructor( private fun onQrCodeScanned(address: String) { val parsedQrCode = parseQrCodeUseCase(address, cryptoCurrency).getOrNull() - predefinedAmountValue = parsedQrCode?.amount?.parseBigDecimal(cryptoCurrency.decimals) + predefinedValues = PredefinedValues.Content.QrCode( + amount = parsedQrCode?.amount?.parseBigDecimal(cryptoCurrency.decimals).orEmpty(), + address = parsedQrCode?.address.orEmpty(), + memo = parsedQrCode?.memo, + ) } private fun onFailedTxEmailClick(errorMessage: String? = null) { diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/ui/state/SendUM.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/ui/state/SendUM.kt index 51cd9a1ae2..8359df5247 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/ui/state/SendUM.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/ui/state/SendUM.kt @@ -1,7 +1,7 @@ package com.tangem.features.send.v2.send.ui.state import com.tangem.common.ui.amountScreen.models.AmountState -import com.tangem.features.send.v2.common.ui.state.ui.state.NavigationUM +import com.tangem.features.send.v2.common.ui.state.NavigationUM import com.tangem.features.send.v2.common.ui.state.ConfirmUM import com.tangem.features.send.v2.subcomponents.destination.ui.state.DestinationUM import com.tangem.features.send.v2.subcomponents.fee.ui.state.FeeUM diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/model/NFTSendModel.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/model/NFTSendModel.kt index 7e9b3a29bd..3d5d6d178a 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/model/NFTSendModel.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/model/NFTSendModel.kt @@ -16,7 +16,7 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.usecase.GetUserWalletUseCase import com.tangem.features.send.v2.api.NFTSendComponent -import com.tangem.features.send.v2.common.ui.state.ui.state.NavigationUM +import com.tangem.features.send.v2.common.ui.state.NavigationUM import com.tangem.features.send.v2.common.ui.state.ConfirmUM import com.tangem.features.send.v2.sendnft.ui.state.NFTSendUM import com.tangem.features.send.v2.subcomponents.destination.SendDestinationComponent diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/ui/state/NFTSendUM.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/ui/state/NFTSendUM.kt index f67a071468..526bfdd621 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/ui/state/NFTSendUM.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/ui/state/NFTSendUM.kt @@ -1,6 +1,6 @@ package com.tangem.features.send.v2.sendnft.ui.state -import com.tangem.features.send.v2.common.ui.state.ui.state.NavigationUM +import com.tangem.features.send.v2.common.ui.state.NavigationUM import com.tangem.features.send.v2.common.ui.state.ConfirmUM import com.tangem.features.send.v2.subcomponents.destination.ui.state.DestinationUM import com.tangem.features.send.v2.subcomponents.fee.ui.state.FeeUM diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/SendAmountBlockComponent.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/SendAmountBlockComponent.kt index b616b506f7..b05e56c031 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/SendAmountBlockComponent.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/SendAmountBlockComponent.kt @@ -9,6 +9,7 @@ import com.tangem.common.ui.amountScreen.ui.AmountBlock import com.tangem.core.decompose.context.AppComponentContext import com.tangem.core.decompose.model.getOrCreateModel import com.tangem.core.ui.decompose.ComposableContentComponent +import com.tangem.features.send.v2.common.PredefinedValues import com.tangem.features.send.v2.subcomponents.amount.SendAmountComponentParams.AmountBlockParams import com.tangem.features.send.v2.subcomponents.amount.model.SendAmountModel import kotlinx.coroutines.flow.launchIn @@ -39,7 +40,7 @@ internal class SendAmountBlockComponent( AmountBlock( amountState = state, isClickDisabled = !isClickEnabled, - isEditingDisabled = params.isPredefinedValues, + isEditingDisabled = params.predefinedValues is PredefinedValues.Content.Deeplink, onClick = onClick, ) } diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/SendAmountComponentParams.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/SendAmountComponentParams.kt index 0df4012c9d..05f4e2a828 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/SendAmountComponentParams.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/SendAmountComponentParams.kt @@ -4,6 +4,7 @@ import com.tangem.common.ui.amountScreen.models.AmountState import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.wallets.models.UserWallet +import com.tangem.features.send.v2.common.PredefinedValues import com.tangem.features.send.v2.send.SendRoute import com.tangem.features.send.v2.subcomponents.amount.SendAmountComponent.ModelCallback import kotlinx.coroutines.flow.Flow @@ -16,7 +17,7 @@ internal sealed class SendAmountComponentParams { abstract val userWallet: UserWallet abstract val appCurrency: AppCurrency abstract val cryptoCurrencyStatus: CryptoCurrencyStatus - abstract val predefinedAmountValue: String? + abstract val predefinedValues: PredefinedValues data class AmountParams( override val state: AmountState, @@ -24,7 +25,7 @@ internal sealed class SendAmountComponentParams { override val userWallet: UserWallet, override val appCurrency: AppCurrency, override val cryptoCurrencyStatus: CryptoCurrencyStatus, - override val predefinedAmountValue: String?, + override val predefinedValues: PredefinedValues, val isEditMode: Boolean, val callback: ModelCallback, val currentRoute: Flow, @@ -37,8 +38,7 @@ internal sealed class SendAmountComponentParams { override val userWallet: UserWallet, override val appCurrency: AppCurrency, override val cryptoCurrencyStatus: CryptoCurrencyStatus, - override val predefinedAmountValue: String?, + override val predefinedValues: PredefinedValues, val blockClickEnableFlow: StateFlow, - val isPredefinedValues: Boolean, ) : SendAmountComponentParams() } \ No newline at end of file diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/model/SendAmountModel.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/model/SendAmountModel.kt index c222bfce07..18e832c369 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/model/SendAmountModel.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/model/SendAmountModel.kt @@ -18,6 +18,7 @@ import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.stringReference import com.tangem.domain.tokens.GetMinimumTransactionAmountSyncUseCase +import com.tangem.features.send.v2.common.PredefinedValues import com.tangem.features.send.v2.common.ui.state.NavigationUM import com.tangem.features.send.v2.impl.R import com.tangem.features.send.v2.send.SendRoute @@ -98,7 +99,10 @@ internal class SendAmountModel @Inject constructor( ), ) } - params.predefinedAmountValue?.let(::onAmountValueChange) + val predefinedValues = params.predefinedValues as? PredefinedValues.Content + if (predefinedValues?.amount != null) { + onAmountValueChange(predefinedValues.amount) + } } } diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/destination/SendDestinationBlockComponent.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/destination/SendDestinationBlockComponent.kt index ff98000eed..5f500027fa 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/destination/SendDestinationBlockComponent.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/destination/SendDestinationBlockComponent.kt @@ -7,6 +7,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.tangem.core.decompose.context.AppComponentContext import com.tangem.core.decompose.model.getOrCreateModel import com.tangem.core.ui.decompose.ComposableContentComponent +import com.tangem.features.send.v2.common.PredefinedValues import com.tangem.features.send.v2.subcomponents.destination.model.SendDestinationModel import com.tangem.features.send.v2.subcomponents.destination.ui.DestinationBlock import com.tangem.features.send.v2.subcomponents.destination.ui.state.DestinationUM @@ -38,7 +39,7 @@ internal class SendDestinationBlockComponent( DestinationBlock( destinationUM = state, isClickDisabled = !isClickEnabled, - isEditingDisabled = params.isPredefinedValues, + isEditingDisabled = params.predefinedValues is PredefinedValues.Content.Deeplink, onClick = onClick, ) } diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/destination/SendDestinationComponentParams.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/destination/SendDestinationComponentParams.kt index f4a69acb24..15b8c7bb6c 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/destination/SendDestinationComponentParams.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/destination/SendDestinationComponentParams.kt @@ -2,6 +2,7 @@ package com.tangem.features.send.v2.subcomponents.destination import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.wallets.models.UserWalletId +import com.tangem.features.send.v2.common.PredefinedValues import com.tangem.features.send.v2.send.SendRoute import com.tangem.features.send.v2.subcomponents.destination.SendDestinationComponent.ModelCallback import com.tangem.features.send.v2.subcomponents.destination.ui.state.DestinationUM @@ -32,8 +33,6 @@ internal sealed class SendDestinationComponentParams { override val userWalletId: UserWalletId, override val cryptoCurrency: CryptoCurrency, val blockClickEnableFlow: StateFlow, - val predefinedAddressValue: String?, - val predefinedMemoValue: String?, - val isPredefinedValues: Boolean, + val predefinedValues: PredefinedValues, ) : SendDestinationComponentParams() } \ No newline at end of file diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/destination/model/SendDestinationModel.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/destination/model/SendDestinationModel.kt index c83153b4c4..c31c86c96d 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/destination/model/SendDestinationModel.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/destination/model/SendDestinationModel.kt @@ -22,6 +22,7 @@ import com.tangem.domain.transaction.usecase.ValidateWalletMemoUseCase import com.tangem.domain.txhistory.usecase.GetFixedTxHistoryItemsUseCase import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.usecase.GetWalletsUseCase +import com.tangem.features.send.v2.common.PredefinedValues import com.tangem.features.send.v2.common.ui.state.NavigationUM import com.tangem.features.send.v2.impl.R import com.tangem.features.send.v2.send.SendRoute @@ -29,6 +30,7 @@ import com.tangem.features.send.v2.send.analytics.SendAnalyticEvents import com.tangem.features.send.v2.send.analytics.SendAnalyticEvents.SendScreenSource import com.tangem.features.send.v2.send.ui.state.ButtonsUM import com.tangem.features.send.v2.subcomponents.destination.SendDestinationComponentParams +import com.tangem.features.send.v2.subcomponents.destination.SendDestinationComponentParams.DestinationBlockParams import com.tangem.features.send.v2.subcomponents.destination.analytics.EnterAddressSource import com.tangem.features.send.v2.subcomponents.destination.analytics.SendDestinationAnalyticEvents import com.tangem.features.send.v2.subcomponents.destination.model.transformers.* @@ -96,19 +98,20 @@ internal class SendDestinationModel @Inject constructor( } private fun initialState() { - if ((uiState.value as? DestinationUM.Content)?.isInitialized == false) { + if ((uiState.value as? DestinationUM.Content)?.isInitialized == false || uiState.value is DestinationUM.Empty) { _uiState.update( SendDestinationInitialStateTransformer( cryptoCurrency = cryptoCurrency, isInitialized = true, ), ) - val params = params as? SendDestinationComponentParams.DestinationBlockParams - if (params?.predefinedAddressValue != null && params.predefinedMemoValue != null) { + val params = params as? DestinationBlockParams + val predefinedValues = params?.predefinedValues as? PredefinedValues.Content.Deeplink + if (predefinedValues?.address != null) { _uiState.update( SendDestinationPredefinedStateTransformer( - address = params.predefinedAddressValue, - memo = params.predefinedMemoValue, + address = predefinedValues.address, + memo = predefinedValues.memo, ), ) } diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/fee/model/SendFeeModel.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/fee/model/SendFeeModel.kt index e82500c413..3a8d73d809 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/fee/model/SendFeeModel.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/fee/model/SendFeeModel.kt @@ -11,7 +11,7 @@ import com.tangem.core.navigation.url.UrlOpener import com.tangem.core.ui.extensions.resourceReference import com.tangem.domain.transaction.usecase.GetFeeUseCase import com.tangem.domain.transaction.usecase.IsFeeApproximateUseCase -import com.tangem.features.send.v2.common.ui.state.ui.state.NavigationUM +import com.tangem.features.send.v2.common.ui.state.NavigationUM import com.tangem.features.send.v2.impl.R import com.tangem.features.send.v2.send.ui.state.ButtonsUM import com.tangem.features.send.v2.subcomponents.fee.SendFeeCheckReloadTrigger diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/notifications/NotificationsComponent.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/notifications/NotificationsComponent.kt index 14760575ab..4f163c1a61 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/notifications/NotificationsComponent.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/notifications/NotificationsComponent.kt @@ -2,19 +2,17 @@ package com.tangem.features.send.v2.subcomponents.notifications import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.ui.Modifier -import com.tangem.blockchain.common.transaction.Fee import com.tangem.common.ui.notifications.NotificationUM import com.tangem.core.decompose.context.AppComponentContext import com.tangem.core.decompose.model.getOrCreateModel import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus -import com.tangem.domain.transaction.error.GetFeeError import com.tangem.domain.wallets.models.UserWalletId import com.tangem.features.send.v2.subcomponents.notifications +import com.tangem.features.send.v2.subcomponents.notifications.model.NotificationData import com.tangem.features.send.v2.subcomponents.notifications.model.NotificationsModel import kotlinx.collections.immutable.ImmutableList import kotlinx.coroutines.flow.StateFlow -import java.math.BigDecimal internal class NotificationsComponent( appComponentContext: AppComponentContext, @@ -45,12 +43,6 @@ internal class NotificationsComponent( val cryptoCurrencyStatus: CryptoCurrencyStatus, val feeCryptoCurrencyStatus: CryptoCurrencyStatus, val appCurrency: AppCurrency, - val destinationAddress: String, - val memo: String?, - val amountValue: BigDecimal, - val reduceAmountBy: BigDecimal, - val isIgnoreReduce: Boolean, - val fee: Fee?, - val feeError: GetFeeError?, + val notificationData: NotificationData, ) } \ No newline at end of file diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/notifications/model/NotificationsModel.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/notifications/model/NotificationsModel.kt index b27fefd5e3..34013568f6 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/notifications/model/NotificationsModel.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/notifications/model/NotificationsModel.kt @@ -78,13 +78,7 @@ internal class NotificationsModel @Inject constructor( private val currency = cryptoCurrencyStatus.currency private val appCurrency = params.appCurrency - private var destinationAddress = params.destinationAddress - private var memo = params.memo - private var amountValue = params.amountValue - private var reduceAmountBy = params.reduceAmountBy - private var isIgnoreReduce = params.isIgnoreReduce - private var fee = params.fee - private var feeError = params.feeError + private var notificationData = params.notificationData private val _uiState = MutableStateFlow>(persistentListOf()) val uiState = _uiState.asStateFlow() @@ -110,14 +104,7 @@ internal class NotificationsModel @Inject constructor( } private suspend fun updateState(data: NotificationData) { - destinationAddress = data.destinationAddress - memo = data.memo - amountValue = data.amountValue - reduceAmountBy = data.reduceAmountBy - isIgnoreReduce = data.isIgnoreReduce - fee = data.fee - feeError = data.feeError - + notificationData = data buildNotifications() } @@ -126,7 +113,7 @@ internal class NotificationsModel @Inject constructor( addFeeUnreachableNotification( tokenStatus = cryptoCurrencyStatus, coinStatus = feeCryptoCurrencyStatus, - feeError = feeError, + feeError = notificationData.feeError, onReload = { modelScope.launch { sendFeeReloadTrigger.triggerUpdate() @@ -134,13 +121,7 @@ internal class NotificationsModel @Inject constructor( }, onClick = ::showTokenDetails, ) - addDomainNotifications( - destinationAddress = destinationAddress, - memo = memo, - amountValue = amountValue, - reduceAmountBy = reduceAmountBy, - fee = fee, - ) + addDomainNotifications() } notificationsUpdateTrigger.callbackHasError(notifications.any { it is NotificationUM.Error }) @@ -161,13 +142,7 @@ internal class NotificationsModel @Inject constructor( } } - private suspend fun MutableList.addDomainNotifications( - destinationAddress: String, - memo: String?, - amountValue: BigDecimal, - reduceAmountBy: BigDecimal, - fee: Fee?, - ) { + private suspend fun MutableList.addDomainNotifications() = with(notificationData) { val balance = cryptoCurrencyStatus.value.amount ?: return val feeValue = fee?.amount?.value ?: return val isFeeCoverage = checkFeeCoverage( @@ -305,7 +280,7 @@ internal class NotificationsModel @Inject constructor( ) { val validationError = validateTransactionUseCase( userWalletId = userWalletId, - amount = amountValue.convertToSdkAmount(cryptoCurrencyStatus.currency), + amount = enteredAmount.convertToSdkAmount(currency), fee = fee, memo = memo, destination = destinationAddress, @@ -353,7 +328,7 @@ internal class NotificationsModel @Inject constructor( addHighFeeWarningNotification( enteredAmountValue = enteredAmount, cryptoCurrencyStatus = cryptoCurrencyStatus, - ignoreAmountReduce = isIgnoreReduce, + ignoreAmountReduce = notificationData.isIgnoreReduce, onReduceClick = { reduceBy, reduceByDiff, _ -> modelScope.launch { sendAmountReduceTrigger.triggerReduceBy(