Updated on 2026-08-14
This commit is contained in:
parent
82c19782eb
commit
f3aa08093d
21 changed files with 657 additions and 129 deletions
|
|
@ -8,6 +8,7 @@ data class SwapSuccessStateHolder(
|
|||
val txUrl: String,
|
||||
val fee: TextReference,
|
||||
val rate: TextReference,
|
||||
val showStatusButton: Boolean,
|
||||
val providerName: TextReference,
|
||||
val providerType: TextReference,
|
||||
val providerIcon: String,
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
|||
import com.tangem.feature.swap.converters.TokensDataConverter
|
||||
import com.tangem.feature.swap.domain.models.DataError
|
||||
import com.tangem.feature.swap.domain.models.SwapAmount
|
||||
import com.tangem.feature.swap.domain.models.domain.ExchangeProviderType
|
||||
import com.tangem.feature.swap.domain.models.domain.NetworkInfo
|
||||
import com.tangem.feature.swap.domain.models.domain.SwapProvider
|
||||
import com.tangem.feature.swap.domain.models.formatToUIRepresentation
|
||||
|
|
@ -592,6 +593,7 @@ internal class StateBuilder(
|
|||
txUrl = txUrl,
|
||||
providerName = TextReference.Str(providerState.name),
|
||||
providerType = TextReference.Str(providerState.type),
|
||||
showStatusButton = providerState.type == ExchangeProviderType.CEX.name,
|
||||
providerIcon = providerState.iconUrl,
|
||||
fee = TextReference.Str("${fee.amountCrypto} ${fee.symbolCrypto} (${fee.amountFiatFormatted})"),
|
||||
rate = TextReference.Str(providerState.rate),
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ fun SwapSuccessScreen(state: SwapSuccessStateHolder, onBack: () -> Unit) {
|
|||
SwapSuccessScreenButtons(
|
||||
textRes = R.string.common_close,
|
||||
txUrl = state.txUrl,
|
||||
showStatusButton = state.showStatusButton,
|
||||
onExploreClick = state.onSecondaryButtonClick,
|
||||
onDoneClick = onBack,
|
||||
)
|
||||
|
|
@ -105,6 +106,7 @@ private fun SwapSuccessScreenContent(state: SwapSuccessStateHolder, padding: Pad
|
|||
private fun SwapSuccessScreenButtons(
|
||||
@StringRes textRes: Int,
|
||||
txUrl: String,
|
||||
showStatusButton: Boolean,
|
||||
onExploreClick: () -> Unit,
|
||||
onDoneClick: () -> Unit,
|
||||
) {
|
||||
|
|
@ -119,21 +121,23 @@ private fun SwapSuccessScreenButtons(
|
|||
if (txUrl.isNotBlank()) {
|
||||
Row {
|
||||
SecondaryButtonIconStart(
|
||||
text = stringResource(id = com.tangem.core.ui.R.string.common_explore),
|
||||
iconResId = com.tangem.core.ui.R.drawable.ic_web_24,
|
||||
text = stringResource(id = R.string.common_explore),
|
||||
iconResId = R.drawable.ic_web_24,
|
||||
onClick = onExploreClick,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
SpacerW12()
|
||||
SecondaryButtonIconStart(
|
||||
text = stringResource(id = com.tangem.core.ui.R.string.common_share),
|
||||
iconResId = com.tangem.core.ui.R.drawable.ic_share_24,
|
||||
onClick = {
|
||||
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
context.shareText(txUrl)
|
||||
},
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
if (showStatusButton) {
|
||||
SpacerW12()
|
||||
SecondaryButtonIconStart(
|
||||
text = stringResource(id = R.string.express_cex_status_button_title),
|
||||
iconResId = R.drawable.ic_arrow_top_right_24,
|
||||
onClick = {
|
||||
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
context.shareText(txUrl)
|
||||
},
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
}
|
||||
}
|
||||
SpacerH12()
|
||||
}
|
||||
|
|
@ -154,6 +158,7 @@ private val state = SwapSuccessStateHolder(
|
|||
fee = TextReference.Str("1 000 DAI ~ 1 000 MATIC"),
|
||||
providerName = TextReference.Str("1inch"),
|
||||
providerType = TextReference.Str(ExchangeProviderType.DEX.name),
|
||||
showStatusButton = false,
|
||||
providerIcon = "",
|
||||
fromTokenAmount = TextReference.Str("1 000 DAI"),
|
||||
toTokenAmount = TextReference.Str("1 000 MATIC"),
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
package com.tangem.feature.swap.viewmodels
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
class PeriodicTask<T>(
|
||||
private val delay: Long,
|
||||
private val task: suspend () -> Result<T>,
|
||||
private val onSuccess: (T) -> Unit,
|
||||
private val onError: (Throwable) -> Unit,
|
||||
) {
|
||||
|
||||
private var isActive: AtomicBoolean = AtomicBoolean(false)
|
||||
|
||||
suspend fun runTaskWithDelay() {
|
||||
isActive.set(true)
|
||||
while (isActive.get()) {
|
||||
task.invoke()
|
||||
.onSuccess {
|
||||
if (!isActive.get()) {
|
||||
return@onSuccess
|
||||
}
|
||||
onSuccess.invoke(it)
|
||||
}
|
||||
.onFailure {
|
||||
if (!isActive.get()) {
|
||||
return@onFailure
|
||||
}
|
||||
onError.invoke(it)
|
||||
}
|
||||
delay(delay)
|
||||
}
|
||||
}
|
||||
|
||||
fun cancel() {
|
||||
isActive.set(false)
|
||||
}
|
||||
}
|
||||
|
||||
class SingleTaskScheduler<T> {
|
||||
|
||||
private var lastTask: PeriodicTask<T>? = null
|
||||
|
||||
fun scheduleTask(scope: CoroutineScope, task: PeriodicTask<T>) {
|
||||
lastTask?.cancel()
|
||||
lastTask = task
|
||||
scope.launch {
|
||||
task.runTaskWithDelay()
|
||||
}
|
||||
}
|
||||
|
||||
fun cancelTask() {
|
||||
lastTask?.cancel()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue