Updated on 2026-08-14

This commit is contained in:
Tangem 2026-06-18 12:36:46 +05:00
parent 26201c5c0b
commit 0be1358760
39 changed files with 581 additions and 124 deletions

View file

@ -7,7 +7,10 @@ import com.tangem.core.decompose.model.Model
import com.tangem.core.decompose.model.ParamsContainer
import com.tangem.core.ui.format.bigdecimal.crypto
import com.tangem.core.ui.format.bigdecimal.format
import com.tangem.domain.account.status.usecase.GetBackupProblematicWalletForAddressUseCase
import com.tangem.domain.express.models.ExpressError
import com.tangem.domain.feedback.SendBackupProblemEmailUseCase
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.transaction.usecase.IsMemoRequiredUseCase
import com.tangem.features.swap.v2.api.subcomponents.SwapAmountUpdateTrigger
import com.tangem.features.swap.v2.impl.amount.entity.PriceImpact
@ -28,6 +31,7 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import java.math.BigDecimal
import java.util.concurrent.atomic.AtomicReference
import javax.inject.Inject
@Suppress("LongParameterList")
@ -38,6 +42,8 @@ internal class SwapNotificationsModel @Inject constructor(
private val swapNotificationsUpdateTrigger: DefaultSwapNotificationsUpdateTrigger,
private val swapAmountUpdateTrigger: SwapAmountUpdateTrigger,
private val isMemoRequiredUseCase: IsMemoRequiredUseCase,
private val getBackupProblematicWalletForAddressUseCase: GetBackupProblematicWalletForAddressUseCase,
private val sendBackupProblemEmailUseCase: SendBackupProblemEmailUseCase,
private val analyticsEventHandler: AnalyticsEventHandler,
paramsContainer: ParamsContainer,
) : Model() {
@ -47,6 +53,8 @@ internal class SwapNotificationsModel @Inject constructor(
private var notificationData = params.swapNotificationData
private var lastSentErrorKeys: Set<Pair<String, Map<String, String>>> = emptySet()
private val backupProblematicWalletCache = AtomicReference<Pair<String, UserWalletId?>?>(null)
val uiState: StateFlow<ImmutableList<NotificationUM>>
field = MutableStateFlow<ImmutableList<NotificationUM>>(persistentListOf())
@ -73,6 +81,7 @@ internal class SwapNotificationsModel @Inject constructor(
addInsufficientFundsNotification()
addExpressErrorNotification()
addDestinationTagRequiredNotification()
addDestinationBackupErrorNotification()
maybeAddPriceImpactNotification()
}
@ -134,6 +143,25 @@ internal class SwapNotificationsModel @Inject constructor(
}
}
private suspend fun MutableList<NotificationUM>.addDestinationBackupErrorNotification() {
val destinationAddress = notificationData.destinationAddress
if (destinationAddress.isEmpty()) return
val problematicWalletId = resolveBackupProblematicWallet(destinationAddress) ?: return
add(
NotificationUM.Error.DestinationBackupError(
onContactSupport = { modelScope.launch { sendBackupProblemEmailUseCase(problematicWalletId) } },
),
)
}
private suspend fun resolveBackupProblematicWallet(address: String): UserWalletId? {
backupProblematicWalletCache.get()?.let { if (it.first == address) return it.second }
return getBackupProblematicWalletForAddressUseCase(address)
.also { backupProblematicWalletCache.set(address to it) }
}
private fun MutableList<NotificationUM>.addInsufficientFundsNotification() {
val enteredFromAmount = notificationData.enteredFromAmount ?: return
val balance = notificationData.fromCryptoCurrencyStatus?.value?.amount ?: return