Updated on 2026-08-14
This commit is contained in:
commit
c50840894f
739 changed files with 27664 additions and 4701 deletions
|
|
@ -126,6 +126,7 @@ internal class SwapAmountModel @Inject constructor(
|
|||
private val amountAnalyticsSender = SwapAmountAnalyticsSender(analyticsEventHandler)
|
||||
|
||||
private var autoUpdateSubscriberJob: Job? = null
|
||||
private var navigationJob: Job? = null
|
||||
|
||||
val uiState: StateFlow<SwapAmountUM>
|
||||
field = MutableStateFlow(params.amountUM)
|
||||
|
|
@ -140,7 +141,6 @@ internal class SwapAmountModel @Inject constructor(
|
|||
?: UserCountry.Other(Locale.getDefault().country)
|
||||
isShowBestRateAnimation = swapBestRateAnimationStore.getSyncOrNull()
|
||||
}
|
||||
configAmountNavigation()
|
||||
subscribeOnCryptoCurrencyStatusFlow()
|
||||
subscribeOnAmountUpdateTriggerUpdates()
|
||||
observeChooseSelectToken()
|
||||
|
|
@ -153,6 +153,7 @@ internal class SwapAmountModel @Inject constructor(
|
|||
|
||||
fun onStart() {
|
||||
val isDelayFirst = params !is SwapAmountComponentParams.AmountBlockParams
|
||||
configAmountNavigation()
|
||||
quoteTaskScheduler.scheduleTask(
|
||||
scope = modelScope,
|
||||
task = loadQuotesTask(isDelayFirst = isDelayFirst),
|
||||
|
|
@ -163,6 +164,7 @@ internal class SwapAmountModel @Inject constructor(
|
|||
fun onStop() {
|
||||
quoteTaskScheduler.cancelTask()
|
||||
autoUpdateSubscriberJob?.cancel()
|
||||
navigationJob?.cancel()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
|
@ -880,7 +882,8 @@ internal class SwapAmountModel @Inject constructor(
|
|||
|
||||
private fun configAmountNavigation() {
|
||||
val params = params as? SwapAmountComponentParams.AmountParams ?: return
|
||||
combine(
|
||||
navigationJob?.cancel()
|
||||
navigationJob = combine(
|
||||
flow = uiState,
|
||||
flow2 = params.currentRoute,
|
||||
transform = { state, route -> state to route },
|
||||
|
|
|
|||
|
|
@ -62,7 +62,8 @@ internal class SwapAmountSelectQuoteTransformer(
|
|||
)
|
||||
|
||||
return prevState.copy(
|
||||
isPrimaryButtonEnabled = quoteUM is SwapQuoteUM.Content,
|
||||
isPrimaryButtonEnabled = quoteUM is SwapQuoteUM.Content &&
|
||||
!hasInsufficientBalance(prevState, quoteContent, newPrimaryAmount),
|
||||
selectedQuote = quoteUM,
|
||||
isShowFCAWarning = isNeedApplyFCARestrictions && quoteUM.provider?.isRestrictedByFCA() == true,
|
||||
primaryAmount = newPrimaryAmount,
|
||||
|
|
@ -202,4 +203,22 @@ internal class SwapAmountSelectQuoteTransformer(
|
|||
prevState.secondaryAmount
|
||||
}
|
||||
}
|
||||
|
||||
private fun hasInsufficientBalance(
|
||||
prevState: SwapAmountUM.Content,
|
||||
quoteContent: SwapQuoteUM.Content?,
|
||||
newPrimaryAmount: SwapAmountFieldUM,
|
||||
): Boolean {
|
||||
if (quoteContent == null) return false
|
||||
|
||||
val primaryBalance = prevState.primaryCryptoCurrencyStatus.value.amount ?: return false
|
||||
val fromAmount = if (prevState.selectedAmountType == SwapAmountType.To) {
|
||||
quoteContent.fromAmount
|
||||
} else {
|
||||
val amountData = (newPrimaryAmount as? SwapAmountFieldUM.Content)?.amountField as? AmountState.Data
|
||||
amountData?.amountTextField?.cryptoAmount?.value
|
||||
}
|
||||
|
||||
return fromAmount != null && fromAmount > primaryBalance
|
||||
}
|
||||
}
|
||||
|
|
@ -33,7 +33,6 @@ internal data object SwapAmountContentPreview {
|
|||
value = "bitcoin",
|
||||
derivationPath = Network.DerivationPath.None,
|
||||
),
|
||||
backendId = "bitcoin",
|
||||
name = "Bitcoin",
|
||||
currencySymbol = "BTC",
|
||||
derivationPath = Network.DerivationPath.None,
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ internal class SwapChooseContentStateTransformer(
|
|||
|
||||
val isMain = cryptoCurrency is CryptoCurrency.Coin
|
||||
val subtitle = when {
|
||||
BlockchainUtils.isL2Network(networkId = network.backendId) -> MAIN_NETWORK_L2_TYPE_NAME
|
||||
BlockchainUtils.isL2Network(networkId = network.rawId) -> MAIN_NETWORK_L2_TYPE_NAME
|
||||
isMain -> MAIN_NETWORK_TYPE_NAME
|
||||
network.standardType !is Network.StandardType.Unspecified -> network.standardType.name
|
||||
else -> ""
|
||||
|
|
|
|||
|
|
@ -75,8 +75,7 @@ internal class SwapAlertFactory @Inject constructor(
|
|||
saveBlockchainErrorUseCase(
|
||||
error = BlockchainErrorInfo(
|
||||
errorMessage = errorMessage.orEmpty(),
|
||||
blockchainId = cryptoCurrency?.network?.rawId.orEmpty(),
|
||||
derivationPath = cryptoCurrency?.network?.derivationPath?.value.orEmpty(),
|
||||
networkId = cryptoCurrency?.network?.id,
|
||||
destinationAddress = confirmData?.enteredDestination.orEmpty(),
|
||||
tokenSymbol = confirmData?.toCryptoCurrencyStatus?.currency?.symbol.orEmpty(),
|
||||
amount = confirmData?.enteredFromAmount?.toString().orEmpty(),
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import com.tangem.core.decompose.di.ModelScoped
|
|||
import com.tangem.core.decompose.model.Model
|
||||
import com.tangem.core.decompose.model.ParamsContainer
|
||||
import com.tangem.core.decompose.navigation.Router
|
||||
import com.tangem.core.ui.HoldToConfirmButtonFeatureToggles
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.domain.account.status.usecase.GetAccountCurrencyByAddressUseCase
|
||||
|
|
@ -100,7 +99,6 @@ internal class SendWithSwapConfirmModel @Inject constructor(
|
|||
private val feeSelectorReloadTrigger: FeeSelectorReloadTrigger,
|
||||
private val swapAlertFactory: SwapAlertFactory,
|
||||
private val analyticsEventHandler: AnalyticsEventHandler,
|
||||
private val holdToConfirmButtonFeatureToggles: HoldToConfirmButtonFeatureToggles,
|
||||
swapTransactionSenderFactory: SwapTransactionSender.Factory,
|
||||
paramsContainer: ParamsContainer,
|
||||
) : Model(), FeeSelectorModelCallback, SendNotificationsComponent.ModelCallback {
|
||||
|
|
@ -574,8 +572,7 @@ internal class SendWithSwapConfirmModel @Inject constructor(
|
|||
val confirmUM = state.confirmUM
|
||||
val isContent = confirmUM is ConfirmUM.Content
|
||||
val isReadyToSend = isContent && !confirmUM.isTransactionInProcess
|
||||
val isHoldToConfirm = holdToConfirmButtonFeatureToggles.isHoldToConfirmEnabled &&
|
||||
params.userWallet.isHotWallet && isContent
|
||||
val isHoldToConfirm = params.userWallet.isHotWallet && isContent
|
||||
params.callback.onResult(
|
||||
route = SendWithSwapRoute.Confirm,
|
||||
sendWithSwapUM = state.copy(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue