Updated on 2026-08-14

This commit is contained in:
Tangem 2023-12-26 15:10:32 +03:00
parent 049de86770
commit 1995610c6a
3 changed files with 39 additions and 21 deletions

View file

@ -42,7 +42,7 @@ private fun ChooseProviderBottomSheetContent(content: ChooseProviderBottomSheetC
style = TangemTheme.typography.subtitle1,
color = TangemTheme.colors.text.primary1,
modifier = Modifier
.padding(top = TangemTheme.dimens.spacing10)
.padding(top = TangemTheme.dimens.spacing10),
)
Text(
text = stringResource(R.string.express_choose_providers_subtitle),

View file

@ -18,7 +18,9 @@ import com.tangem.feature.swap.domain.models.domain.ExchangeStatus
import com.tangem.feature.swap.domain.models.domain.ExchangeStatusModel
import com.tangem.feature.swap.domain.models.domain.SavedSwapTransactionListModel
import com.tangem.feature.tokendetails.presentation.tokendetails.state.SwapTransactionsState
import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsState
import com.tangem.feature.tokendetails.presentation.tokendetails.state.factory.TokenDetailsSwapTransactionsStateConverter
import com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.exchange.ExchangeStatusBottomSheetConfig
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
@ -41,6 +43,7 @@ internal class ExchangeStatusFactory(
private val clickIntents: TokenDetailsClickIntents,
private val appCurrencyProvider: Provider<AppCurrency>,
private val analyticsEventsHandlerProvider: Provider<AnalyticsEventHandler>,
private val currentStateProvider: Provider<TokenDetailsState>,
private val userWalletId: UserWalletId,
private val cryptoCurrency: CryptoCurrency,
) {
@ -64,6 +67,27 @@ internal class ExchangeStatusFactory(
)
}
suspend fun removeTransactionOnBottomSheetClosed(): TokenDetailsState {
val state = currentStateProvider()
val bottomSheetConfig = state.bottomSheetConfig?.content as? ExchangeStatusBottomSheetConfig ?: return state
val selectedTx = bottomSheetConfig.value
return if (selectedTx.activeStatus.isTerminal()) {
swapTransactionRepository.removeTransaction(
userWalletId = userWalletId,
fromCryptoCurrencyId = selectedTx.fromCryptoCurrencyId,
toCryptoCurrencyId = selectedTx.toCryptoCurrencyId,
txId = selectedTx.txId,
)
val filteredTxs = state.swapTxs
.filterNot { it.txId == selectedTx.txId }
.toPersistentList()
state.copy(swapTxs = filteredTxs)
} else {
state
}
}
private fun getWalletCryptoCurrencies() = flow {
val selectedWallet = getSelectedWalletSyncUseCase().fold(
ifLeft = { null },
@ -80,14 +104,16 @@ internal class ExchangeStatusFactory(
suspend fun updateSwapTxStatuses(swapTxList: PersistentList<SwapTransactionsState>) = withContext(dispatchers.io) {
swapTxList.map { tx ->
async {
val statusModel = getExchangeStatus(tx.txId)
swapTransactionsStateConverter
.updateTxStatus(tx, statusModel)
.removeIfFinished(statusModel?.status)
if (tx.activeStatus.isTerminal()) {
tx
} else {
val statusModel = getExchangeStatus(tx.txId)
swapTransactionsStateConverter
.updateTxStatus(tx, statusModel)
}
}
}
.awaitAll()
.filterNotNull()
.toPersistentList()
}
@ -130,21 +156,8 @@ internal class ExchangeStatusFactory(
)
}
private suspend fun SwapTransactionsState.removeIfFinished(status: ExchangeStatus?) = when (status) {
null -> null // not found
ExchangeStatus.Refunded, ExchangeStatus.Finished -> {
swapTransactionRepository.removeTransaction(
userWalletId = userWalletId,
fromCryptoCurrencyId = fromCryptoCurrencyId,
toCryptoCurrencyId = toCryptoCurrencyId,
txId = txId,
)
null
}
else -> {
this
}
}
private fun ExchangeStatus?.isTerminal() =
this == ExchangeStatus.Refunded || this == ExchangeStatus.Finished || this == ExchangeStatus.Cancelled
private fun toAnalyticStatus(status: ExchangeStatus?): ExchangeAnalyticsStatus? {
return when (status) {

View file

@ -548,6 +548,11 @@ internal class TokenDetailsViewModel @Inject constructor(
}
override fun onDismissBottomSheet() {
if (uiState.bottomSheetConfig?.content is ExchangeStatusBottomSheetConfig) {
viewModelScope.launch(dispatchers.main) {
uiState = exchangeStatusFactory.removeTransactionOnBottomSheetClosed()
}
}
uiState = stateFactory.getStateWithClosedBottomSheet()
}