From 8fc579ba5cdc5a2198c7c07e85f462d10057a1d0 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 24 Jul 2024 15:31:02 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../models/response/ExchangeStatusResponse.kt | 6 ++ .../repository/DefaultCurrenciesRepository.kt | 49 +++++++++++++++- .../tokens/AddCryptoCurrenciesUseCase.kt | 57 +++++++++++++++++-- .../tokens/repository/CurrenciesRepository.kt | 10 ++++ .../repository/MockCurrenciesRepository.kt | 8 +++ .../converters/ExchangeStatusConverter.kt | 2 + .../domain/models/domain/ExchangeStatus.kt | 2 + .../state/SwapTransactionsState.kt | 1 + .../components/ExchangeStatusNotifications.kt | 17 ++++++ ...enDetailsSwapTransactionsStateConverter.kt | 34 ++++++++--- .../exchange/ExchangeStatusBlock.kt | 6 ++ .../viewmodels/ExchangeStatusFactory.kt | 46 +++++++++++---- .../viewmodels/TokenDetailsClickIntents.kt | 2 + .../viewmodels/TokenDetailsViewModel.kt | 15 ++++- 14 files changed, 228 insertions(+), 27 deletions(-) diff --git a/core/datasource/src/main/java/com/tangem/datasource/api/express/models/response/ExchangeStatusResponse.kt b/core/datasource/src/main/java/com/tangem/datasource/api/express/models/response/ExchangeStatusResponse.kt index 5b43c9cea5..7682c70d4f 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/api/express/models/response/ExchangeStatusResponse.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/api/express/models/response/ExchangeStatusResponse.kt @@ -18,6 +18,12 @@ data class ExchangeStatusResponse( @Json(name = "error") val error: ExchangeStatusError?, + + @Json(name = "refundNetwork") + val refundNetwork: String? = null, + + @Json(name = "refundContractAddress") + val refundContractAddress: String? = null, ) enum class ExchangeStatus { diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt index 9459984032..214d9721e1 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt @@ -39,7 +39,7 @@ import kotlinx.coroutines.withContext import timber.log.Timber import com.tangem.blockchain.common.FeePaidCurrency as FeePaidSdkCurrency -@Suppress("LargeClass", "LongParameterList") +@Suppress("LargeClass", "LongParameterList", "TooManyFunctions") internal class DefaultCurrenciesRepository( private val tangemTechApi: TangemTechApi, private val tangemExpressApi: TangemExpressApi, @@ -53,6 +53,7 @@ internal class DefaultCurrenciesRepository( private val demoConfig = DemoConfig() private val responseCurrenciesFactory = ResponseCryptoCurrenciesFactory() + private val cryptoCurrencyFactory = CryptoCurrencyFactory() private val cardCurrenciesFactory = CardCryptoCurrenciesFactory(demoConfig) private val userTokensResponseFactory = UserTokensResponseFactory() private val userTokensBackwardCompatibility = UserTokensBackwardCompatibility() @@ -125,7 +126,7 @@ internal class DefaultCurrenciesRepository( return newTokens .filterNot { savedCurrencies.hasCoinForToken(it) } // tokens without coins .mapNotNull { - CryptoCurrencyFactory().createCoin( + cryptoCurrencyFactory.createCoin( blockchain = getBlockchain(networkId = it.network.id), extraDerivationPath = it.network.derivationPath.value, derivationStyleProvider = getUserWallet(userWalletId).scanResponse.derivationStyleProvider, @@ -413,12 +414,54 @@ internal class DefaultCurrenciesRepository( } override fun createTokenCurrency(cryptoCurrency: CryptoCurrency.Token, network: Network): CryptoCurrency.Token { - return CryptoCurrencyFactory().createToken( + return cryptoCurrencyFactory.createToken( cryptoCurrency = cryptoCurrency, network = network, ) } + override suspend fun createTokenCurrency( + userWalletId: UserWalletId, + contractAddress: String, + networkId: String, + ): CryptoCurrency.Token { + val userWallet = getUserWallet(userWalletId) + val token = withContext(dispatchers.io) { + val foundToken = tangemTechApi.getCoins( + contractAddress = contractAddress, + networkIds = networkId, + ) + .getOrThrow() + .coins + .firstNotNullOfOrNull { coin -> + val networksWithTheSameAddress = coin.networks.filter { network -> + (network.contractAddress != null || network.decimalCount != null) && + network.contractAddress?.equals(contractAddress, ignoreCase = true) == true + } + + if (networksWithTheSameAddress.isNotEmpty()) { + coin.copy(networks = networksWithTheSameAddress) + } else { + null + } + } ?: error("Token not found") + val network = foundToken.networks.firstOrNull { it.networkId == networkId } ?: error("Network not found") + CryptoCurrencyFactory.Token( + symbol = foundToken.symbol, + name = foundToken.name, + contractAddress = contractAddress, + decimals = network.decimalCount?.toInt() ?: error("Decimals not found"), + id = foundToken.id, + ) + } + return cryptoCurrencyFactory.createToken( + token = token, + networkId = networkId, + extraDerivationPath = null, + derivationStyleProvider = userWallet.scanResponse.derivationStyleProvider, + ) ?: error("Unable to create token") + } + private fun getMultiCurrencyWalletCurrencies(userWallet: UserWallet): Flow> { return userTokensStore.get(userWallet.walletId).map { storedTokens -> responseCurrenciesFactory.createCurrencies( diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/AddCryptoCurrenciesUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/AddCryptoCurrenciesUseCase.kt index e8c6f0b7a8..01223c61a3 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/AddCryptoCurrenciesUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/AddCryptoCurrenciesUseCase.kt @@ -79,13 +79,35 @@ class AddCryptoCurrenciesUseCase( .toNonEmptyListOrNull() ?: return@either - catch({ currenciesRepository.addCurrencies(userWalletId, currenciesToAdd) }) { - raise(it) - } - + addCurrencies(userWalletId, currenciesToAdd) refreshUpdatedNetworks(userWalletId, currenciesToAdd, existingCurrencies) } + suspend operator fun invoke( + userWalletId: UserWalletId, + contractAddress: String, + networkId: String, + ): Either = either { + val existingCurrencies = + catch({ currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWalletId) }) { + raise(it) + } + val foundToken = existingCurrencies + .filterIsInstance() + .firstOrNull { + it.network.backendId == networkId && + !it.isCustom && + it.contractAddress.equals(contractAddress, true) + } + if (foundToken != null) { + return@either foundToken + } + val tokenToAdd = createTokenCurrency(userWalletId, contractAddress, networkId) + addCurrencies(userWalletId, listOf(tokenToAdd)) + refreshUpdatedNetworks(userWalletId, listOf(tokenToAdd), existingCurrencies) + tokenToAdd + } + /** * Refreshes the network statuses for tokens that have corresponding coins in the * [existingCurrencies] list. @@ -117,6 +139,33 @@ class AddCryptoCurrenciesUseCase( } } + private suspend fun Raise.createTokenCurrency( + userWalletId: UserWalletId, + contractAddress: String, + networkId: String, + ): CryptoCurrency.Token { + return catch( + block = { + currenciesRepository.createTokenCurrency( + userWalletId = userWalletId, + contractAddress = contractAddress, + networkId = networkId, + ) + }, + catch = { + raise(it) + }, + ) + } + + private suspend fun Raise.addCurrencies(userWalletId: UserWalletId, tokens: List) { + catch( + { currenciesRepository.addCurrencies(userWalletId, tokens) }, + ) { + raise(it) + } + } + /** * Determines if the [existingCurrencies] list contains a coin that corresponds * to the given [token]. diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrenciesRepository.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrenciesRepository.kt index 5bdf7b4067..d5daebcd8e 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrenciesRepository.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/repository/CurrenciesRepository.kt @@ -12,6 +12,7 @@ import kotlinx.coroutines.flow.Flow /** * Repository for everything related to the tokens of user wallet * */ +@Suppress("TooManyFunctions") interface CurrenciesRepository { /** @@ -210,4 +211,13 @@ interface CurrenciesRepository { * Creates token [cryptoCurrency] based on current token and [network] it`s will be added */ fun createTokenCurrency(cryptoCurrency: CryptoCurrency.Token, network: Network): CryptoCurrency.Token + + /** + * Creates token [cryptoCurrency] based on [contractAddress] and [networkId] it`s will be added + */ + suspend fun createTokenCurrency( + userWalletId: UserWalletId, + contractAddress: String, + networkId: String, + ): CryptoCurrency.Token } \ No newline at end of file diff --git a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt index d4d616d88a..ff73d40462 100644 --- a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt +++ b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/repository/MockCurrenciesRepository.kt @@ -136,4 +136,12 @@ internal class MockCurrenciesRepository( override fun createTokenCurrency(cryptoCurrency: CryptoCurrency.Token, network: Network): CryptoCurrency.Token { return cryptoCurrency } + + override suspend fun createTokenCurrency( + userWalletId: UserWalletId, + contractAddress: String, + networkId: String, + ): CryptoCurrency.Token { + error("not implemented") + } } \ No newline at end of file diff --git a/features/swap/data/src/main/java/com/tangem/feature/swap/converters/ExchangeStatusConverter.kt b/features/swap/data/src/main/java/com/tangem/feature/swap/converters/ExchangeStatusConverter.kt index 0a566d5500..d782b606f9 100644 --- a/features/swap/data/src/main/java/com/tangem/feature/swap/converters/ExchangeStatusConverter.kt +++ b/features/swap/data/src/main/java/com/tangem/feature/swap/converters/ExchangeStatusConverter.kt @@ -15,6 +15,8 @@ internal class ExchangeStatusConverter : Converter Unit, val onGoToProviderClick: (String) -> Unit, ) diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/components/ExchangeStatusNotifications.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/components/ExchangeStatusNotifications.kt index ac825983b8..58b0829319 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/components/ExchangeStatusNotifications.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/components/ExchangeStatusNotifications.kt @@ -3,6 +3,8 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.state.componen import androidx.compose.runtime.Immutable import com.tangem.core.ui.components.notifications.NotificationConfig import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.stringReference +import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.features.tokendetails.impl.R @Immutable @@ -35,4 +37,19 @@ internal sealed class ExchangeStatusNotifications(val config: NotificationConfig ), ), ) + + data class TokenRefunded( + val cryptoCurrency: CryptoCurrency, + val onGoToTokenClick: () -> Unit, + ) : ExchangeStatusNotifications( + config = NotificationConfig( + title = stringReference("TITLE FOR TOKEN REFUND"), + subtitle = stringReference("SUBTITLE FOR TOKEN REFUND"), + iconResId = R.drawable.ic_alert_triangle_20, + buttonsState = NotificationConfig.ButtonsState.SecondaryButtonConfig( + text = stringReference("Go to token"), + onClick = onGoToTokenClick, + ), + ), + ) } \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsSwapTransactionsStateConverter.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsSwapTransactionsStateConverter.kt index 6c1a71f7af..fba5085305 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsSwapTransactionsStateConverter.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsSwapTransactionsStateConverter.kt @@ -62,7 +62,7 @@ internal class TokenDetailsSwapTransactionsStateConverter( }?.fiatRate?.multiply(fromAmount) val timestamp = transaction.timestamp val notifications = - getNotification(transaction.status?.status, transaction.status?.txExternalUrl) + getNotification(transaction.status?.status, transaction.status?.txExternalUrl, null) val showProviderLink = getShowProviderLink(notifications, transaction.status) result.add( SwapTransactionsState( @@ -77,10 +77,7 @@ internal class TokenDetailsSwapTransactionsStateConverter( statuses = getStatuses(transaction.status?.status), hasFailed = transaction.status?.status == ExchangeStatus.Failed, activeStatus = transaction.status?.status, - notification = getNotification( - transaction.status?.status, - transaction.status?.txExternalUrl, - ), + notification = notifications, toCryptoCurrency = toCryptoCurrency, toCryptoAmount = BigDecimalFormatter.formatCryptoAmount( cryptoAmount = toAmount, @@ -110,10 +107,15 @@ internal class TokenDetailsSwapTransactionsStateConverter( return result.toPersistentList() } - fun updateTxStatus(tx: SwapTransactionsState, statusModel: ExchangeStatusModel?): SwapTransactionsState { + fun updateTxStatus( + tx: SwapTransactionsState, + statusModel: ExchangeStatusModel?, + refundToken: CryptoCurrency?, + isRefundTerminalStatus: Boolean, + ): SwapTransactionsState { if (statusModel == null || tx.activeStatus == statusModel.status) return tx val hasFailed = tx.hasFailed || statusModel.status == ExchangeStatus.Failed - val notifications = getNotification(statusModel.status, statusModel.txExternalUrl) + val notifications = getNotification(statusModel.status, statusModel.txExternalUrl, refundToken) val showProviderLink = getShowProviderLink(notifications, statusModel) return tx.copy( activeStatus = statusModel.status, @@ -122,6 +124,7 @@ internal class TokenDetailsSwapTransactionsStateConverter( statuses = getStatuses(statusModel.status, hasFailed), txUrl = statusModel.txExternalUrl, showProviderLink = showProviderLink, + isRefundTerminalStatus = isRefundTerminalStatus, ) } @@ -133,7 +136,11 @@ internal class TokenDetailsSwapTransactionsStateConverter( ) } - private fun getNotification(status: ExchangeStatus?, txUrl: String?): ExchangeStatusNotifications? { + private fun getNotification( + status: ExchangeStatus?, + txUrl: String?, + refundToken: CryptoCurrency?, + ): ExchangeStatusNotifications? { if (txUrl == null) return null return when (status) { ExchangeStatus.Failed -> { @@ -152,6 +159,15 @@ internal class TokenDetailsSwapTransactionsStateConverter( clickIntents.onGoToProviderClick(txUrl) } } + ExchangeStatus.Refunded -> { + if (refundToken == null) { + null + } else { + ExchangeStatusNotifications.TokenRefunded(refundToken) { + clickIntents.onGoToRefundedTokenClick(refundToken) + } + } + } else -> null } } @@ -287,7 +303,7 @@ internal class TokenDetailsSwapTransactionsStateConverter( status = ExchangeStatus.Refunded, text = TextReference.Res(R.string.express_exchange_status_refunded), isActive = false, - isDone = isRefunded, + isDone = false, ) else -> ExchangeStatusState( status = ExchangeStatus.Sending, diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/exchange/ExchangeStatusBlock.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/exchange/ExchangeStatusBlock.kt index c715a6c6bd..ff2dd3baff 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/exchange/ExchangeStatusBlock.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/exchange/ExchangeStatusBlock.kt @@ -115,6 +115,11 @@ private fun ExchangeStatusStep( color = TangemTheme.colors.icon.warning, isDone = it.isDone, ) + it.status == ExchangeStatus.Refunded -> ExchangeStep( + iconRes = R.drawable.ic_close_24, + color = TangemTheme.colors.icon.warning, + isDone = it.isDone, + ) it.status == ExchangeStatus.Verifying -> ExchangeStep( iconRes = R.drawable.ic_exclamation_24, color = TangemTheme.colors.icon.attention, @@ -141,6 +146,7 @@ private fun ExchangeStatusStep( private fun ExchangeStatusStepText(stepStatus: ExchangeStatusState) { val textColor = when { stepStatus.status == ExchangeStatus.Cancelled -> TangemTheme.colors.icon.warning + stepStatus.status == ExchangeStatus.Refunded -> TangemTheme.colors.icon.warning stepStatus.status == ExchangeStatus.Failed && !stepStatus.isDone -> TangemTheme.colors.icon.warning stepStatus.status == ExchangeStatus.Verifying && !stepStatus.isDone -> TangemTheme.colors.icon.attention stepStatus.isDone -> TangemTheme.colors.text.primary1 diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/ExchangeStatusFactory.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/ExchangeStatusFactory.kt index 54356f4665..e4118e7141 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/ExchangeStatusFactory.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/ExchangeStatusFactory.kt @@ -4,6 +4,7 @@ import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.datasource.local.swaptx.ExchangeAnalyticsStatus import com.tangem.datasource.local.swaptx.SwapTransactionStatusStore import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.tokens.AddCryptoCurrenciesUseCase import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.Quote import com.tangem.domain.tokens.models.analytics.TokenExchangeAnalyticsEvent @@ -38,6 +39,7 @@ internal class ExchangeStatusFactory( private val swapRepository: SwapRepository, private val quotesRepository: QuotesRepository, private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, + private val addCryptoCurrenciesUseCase: AddCryptoCurrenciesUseCase, private val swapTransactionStatusStore: SwapTransactionStatusStore, private val dispatchers: CoroutineDispatcherProvider, private val clickIntents: TokenDetailsClickIntents, @@ -85,7 +87,7 @@ internal class ExchangeStatusFactory( val bottomSheetConfig = state.bottomSheetConfig?.content as? ExchangeStatusBottomSheetConfig ?: return state val selectedTx = bottomSheetConfig.value - return if (selectedTx.activeStatus.isTerminal()) { + return if (selectedTx.activeStatus.isTerminal(selectedTx.isRefundTerminalStatus)) { swapTransactionRepository.removeTransaction( userWalletId = userWalletId, fromCryptoCurrency = selectedTx.fromCryptoCurrency, @@ -104,12 +106,19 @@ internal class ExchangeStatusFactory( suspend fun updateSwapTxStatuses(swapTxList: PersistentList) = withContext(dispatchers.io) { swapTxList.map { tx -> async { - if (tx.activeStatus.isTerminal()) { + val statusModel = getExchangeStatus(tx.txId) + val isRefundTerminalStatus = statusModel?.refundNetwork == null && + statusModel?.refundContractAddress == null + if (tx.activeStatus.isTerminal(isRefundTerminalStatus)) { tx } else { - val statusModel = getExchangeStatus(tx.txId) - swapTransactionsStateConverter - .updateTxStatus(tx, statusModel) + val addedRefundToken = addRefundCurrencyIfNeeded(statusModel) + swapTransactionsStateConverter.updateTxStatus( + tx = tx, + statusModel = statusModel, + refundToken = addedRefundToken, + isRefundTerminalStatus = isRefundTerminalStatus, + ) } } } @@ -142,6 +151,20 @@ internal class ExchangeStatusFactory( } } + private suspend fun addRefundCurrencyIfNeeded(status: ExchangeStatusModel?): CryptoCurrency? { + status ?: return null + val refundNetwork = status.refundNetwork + val refundContractAddress = status.refundContractAddress + if (refundNetwork != null && refundContractAddress != null) { + return addCryptoCurrenciesUseCase( + userWalletId = userWalletId, + contractAddress = refundContractAddress, + networkId = refundNetwork, + ).getOrNull() + } + return null + } + private fun getExchangeStatusState( savedTransactions: List?, quotes: Set, @@ -156,11 +179,14 @@ internal class ExchangeStatusFactory( ) } - private fun ExchangeStatus?.isTerminal() = this == ExchangeStatus.Refunded || - this == ExchangeStatus.Finished || - this == ExchangeStatus.Cancelled || - this == ExchangeStatus.TxFailed || - this == ExchangeStatus.Unknown + private fun ExchangeStatus?.isTerminal(isRefundTerminal: Boolean): Boolean { + val needTerminalRefund = this == ExchangeStatus.Refunded && isRefundTerminal + return needTerminalRefund || + this == ExchangeStatus.Finished || + this == ExchangeStatus.Cancelled || + this == ExchangeStatus.TxFailed || + this == ExchangeStatus.Unknown + } private fun toAnalyticStatus(status: ExchangeStatus?): ExchangeAnalyticsStatus? { return when (status) { diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsClickIntents.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsClickIntents.kt index 751b8dcd92..387d2f3482 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsClickIntents.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsClickIntents.kt @@ -55,4 +55,6 @@ interface TokenDetailsClickIntents { fun onCopyAddress(): TextReference? fun onAssociateClick() + + fun onGoToRefundedTokenClick(cryptoCurrency: CryptoCurrency) } \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt index 4d115db24e..9fa0481605 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt @@ -96,6 +96,7 @@ internal class TokenDetailsViewModel @Inject constructor( private val getCurrencyWarningsUseCase: GetCurrencyWarningsUseCase, private val getExplorerTransactionUrlUseCase: GetExplorerTransactionUrlUseCase, private val getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase, + private val addCryptoCurrenciesUseCase: AddCryptoCurrenciesUseCase, private val shouldShowSwapPromoTokenUseCase: ShouldShowSwapPromoTokenUseCase, private val updateDelayedCurrencyStatusUseCase: UpdateDelayedNetworkStatusUseCase, private val getExtendedPublicKeyForCurrencyUseCase: GetExtendedPublicKeyForCurrencyUseCase, @@ -156,6 +157,7 @@ internal class TokenDetailsViewModel @Inject constructor( swapRepository = swapRepository, quotesRepository = quotesRepository, getSelectedWalletSyncUseCase = getSelectedWalletSyncUseCase, + addCryptoCurrenciesUseCase = addCryptoCurrenciesUseCase, swapTransactionStatusStore = swapTransactionStatusStore, dispatchers = dispatchers, clickIntents = this, @@ -691,7 +693,8 @@ internal class TokenDetailsViewModel @Inject constructor( } override fun onDismissBottomSheet() { - if (internalUiState.value.bottomSheetConfig?.content is ExchangeStatusBottomSheetConfig) { + val bsContent = internalUiState.value.bottomSheetConfig?.content + if (bsContent is ExchangeStatusBottomSheetConfig) { viewModelScope.launch(dispatchers.main) { internalUiState.value = exchangeStatusFactory.removeTransactionOnBottomSheetClosed() } @@ -713,6 +716,16 @@ internal class TokenDetailsViewModel @Inject constructor( router.openUrl(url) } + override fun onGoToRefundedTokenClick(cryptoCurrency: CryptoCurrency) { + if (internalUiState.value.bottomSheetConfig?.content is ExchangeStatusBottomSheetConfig) { + viewModelScope.launch(dispatchers.main) { + internalUiState.value = exchangeStatusFactory.removeTransactionOnBottomSheetClosed() + } + } + internalUiState.value = stateFactory.getStateWithClosedBottomSheet() + router.openTokenDetails(userWalletId, cryptoCurrency) + } + override fun onSwapPromoDismiss() { viewModelScope.launch(dispatchers.main) { shouldShowSwapPromoTokenUseCase.neverToShow()