From 2f3e6db10d18c1a0aa9337addfe3877166cae9e6 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 31 Jan 2025 18:24:49 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../swap/DefaultSwapTransactionRepository.kt | 22 ++++++++++++++++--- .../SavedSwapTransactionListConverter.kt | 10 ++++++++- features/swap/domain/build.gradle.kts | 1 + .../domain/models/domain/ExchangeStatus.kt | 6 +++++ .../swap/domain/SwapTransactionRepository.kt | 2 +- ...enDetailsSwapTransactionsStateConverter.kt | 16 +++++++++----- .../factory/express/ExchangeStatusFactory.kt | 9 ++++---- .../viewmodels/TokenDetailsViewModel.kt | 1 - 8 files changed, 51 insertions(+), 16 deletions(-) diff --git a/features/swap/data/src/main/java/com/tangem/feature/swap/DefaultSwapTransactionRepository.kt b/features/swap/data/src/main/java/com/tangem/feature/swap/DefaultSwapTransactionRepository.kt index ed7aa550c5..082f1b8ec9 100644 --- a/features/swap/data/src/main/java/com/tangem/feature/swap/DefaultSwapTransactionRepository.kt +++ b/features/swap/data/src/main/java/com/tangem/feature/swap/DefaultSwapTransactionRepository.kt @@ -1,6 +1,7 @@ package com.tangem.feature.swap import com.tangem.blockchainsdk.utils.ExcludedBlockchains +import com.tangem.data.common.currency.UserTokensResponseFactory import com.tangem.datasource.local.preferences.AppPreferencesStore import com.tangem.datasource.local.preferences.PreferencesKeys import com.tangem.datasource.local.preferences.utils.getObjectList @@ -26,6 +27,7 @@ internal class DefaultSwapTransactionRepository( ) : SwapTransactionRepository { private val converter = SavedSwapTransactionListConverter(excludedBlockchains) + private val userTokensResponseFactory = UserTokensResponseFactory() override suspend fun storeTransaction( userWalletId: UserWalletId, @@ -33,7 +35,13 @@ internal class DefaultSwapTransactionRepository( toCryptoCurrency: CryptoCurrency, transaction: SavedSwapTransactionModel, ) { - transaction.status?.let { storeTransactionState(transaction.txId, it) } + transaction.status?.let { + storeTransactionState( + txId = transaction.txId, + status = it, + refundTokenCurrency = null, + ) + } appPreferencesStore.editData { mutablePreferences -> val savedTransactions: List? = mutablePreferences.getObjectList( key = PreferencesKeys.SWAP_TRANSACTIONS_KEY, @@ -154,14 +162,22 @@ internal class DefaultSwapTransactionRepository( } } - override suspend fun storeTransactionState(txId: String, status: ExchangeStatusModel) { + override suspend fun storeTransactionState( + txId: String, + status: ExchangeStatusModel, + refundTokenCurrency: CryptoCurrency?, + ) { appPreferencesStore.editData { mutablePreferences -> val savedMap = mutablePreferences.getObjectMap( key = PreferencesKeys.SWAP_TRANSACTIONS_STATUSES_KEY, ) val updatesMap = savedMap.toMutableMap() - updatesMap[txId] = status + updatesMap[txId] = status.copy( + refundTokensResponse = refundTokenCurrency?.let { + userTokensResponseFactory.createResponseToken(refundTokenCurrency) + }, + ) mutablePreferences.setObjectMap( key = PreferencesKeys.SWAP_TRANSACTIONS_STATUSES_KEY, diff --git a/features/swap/data/src/main/java/com/tangem/feature/swap/converters/SavedSwapTransactionListConverter.kt b/features/swap/data/src/main/java/com/tangem/feature/swap/converters/SavedSwapTransactionListConverter.kt index d3d6093b01..ed4ce2cf2e 100644 --- a/features/swap/data/src/main/java/com/tangem/feature/swap/converters/SavedSwapTransactionListConverter.kt +++ b/features/swap/data/src/main/java/com/tangem/feature/swap/converters/SavedSwapTransactionListConverter.kt @@ -53,7 +53,15 @@ internal class SavedSwapTransactionListConverter( return SavedSwapTransactionListModel( transactions = value.transactions.map { tx -> - tx.copy(status = txStatuses[tx.txId]) + val status = txStatuses[tx.txId] + val refundCurrency = status?.refundTokensResponse?.let { id -> + responseCryptoCurrenciesFactory.createCurrency( + responseToken = id, + scanResponse = scanResponse, + ) + } + val statusWithRefundCurrency = status?.copy(refundCurrency = refundCurrency) + tx.copy(status = statusWithRefundCurrency) }, userWalletId = value.userWalletId, fromCryptoCurrencyId = value.fromCryptoCurrencyId, diff --git a/features/swap/domain/build.gradle.kts b/features/swap/domain/build.gradle.kts index bbf66619e0..ed5fe567e7 100644 --- a/features/swap/domain/build.gradle.kts +++ b/features/swap/domain/build.gradle.kts @@ -42,6 +42,7 @@ dependencies { /** Core modules */ implementation(projects.core.utils) implementation(projects.core.ui) + implementation(projects.core.datasource) /** Feature Apis */ implementation(projects.features.wallet.api) diff --git a/features/swap/domain/models/src/main/java/com/tangem/feature/swap/domain/models/domain/ExchangeStatus.kt b/features/swap/domain/models/src/main/java/com/tangem/feature/swap/domain/models/domain/ExchangeStatus.kt index 5247fa7145..bd5e63b506 100644 --- a/features/swap/domain/models/src/main/java/com/tangem/feature/swap/domain/models/domain/ExchangeStatus.kt +++ b/features/swap/domain/models/src/main/java/com/tangem/feature/swap/domain/models/domain/ExchangeStatus.kt @@ -2,6 +2,8 @@ package com.tangem.feature.swap.domain.models.domain import com.squareup.moshi.Json import com.squareup.moshi.JsonClass +import com.tangem.datasource.api.tangemTech.models.UserTokensResponse +import com.tangem.domain.tokens.model.CryptoCurrency @JsonClass(generateAdapter = true) data class ExchangeStatusModel( @@ -19,6 +21,10 @@ data class ExchangeStatusModel( val refundNetwork: String? = null, @Json(name = "refundContractAddress") val refundContractAddress: String? = null, + @Json(name = "refundTokensResponse") + val refundTokensResponse: UserTokensResponse.Token? = null, + @Json(ignore = true) + val refundCurrency: CryptoCurrency? = null, ) @JsonClass(generateAdapter = false) diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapTransactionRepository.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapTransactionRepository.kt index f02a93f2ab..812499d47f 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapTransactionRepository.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapTransactionRepository.kt @@ -30,7 +30,7 @@ interface SwapTransactionRepository { txId: String, ) - suspend fun storeTransactionState(txId: String, status: ExchangeStatusModel) + suspend fun storeTransactionState(txId: String, status: ExchangeStatusModel, refundTokenCurrency: CryptoCurrency?) suspend fun storeLastSwappedCryptoCurrencyId(userWalletId: UserWalletId, cryptoCurrencyId: CryptoCurrency.ID) 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 967df9169b..ba05cd229d 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 @@ -80,15 +80,19 @@ internal class TokenDetailsSwapTransactionsStateConverter( fromFiatAmount = quote.fiatRate.multiply(fromAmount) } } - val notifications = - getNotification(transaction.status?.status, transaction.status?.txExternalUrl, null) + val statusModel = transaction.status + val notifications = getNotification( + status = statusModel?.status, + txUrl = statusModel?.txExternalUrl, + refundToken = statusModel?.refundCurrency, + ) val showProviderLink = getShowProviderLink(notifications, transaction.status) result.add( ExchangeUM( provider = transaction.provider, - statuses = getStatuses(transaction.status?.status), + statuses = getStatuses(statusModel?.status), notification = notifications, - activeStatus = transaction.status?.status, + activeStatus = statusModel?.status, showProviderLink = showProviderLink, fromCryptoCurrency = fromCryptoCurrency, toCryptoCurrency = toCryptoCurrency, @@ -106,13 +110,13 @@ internal class TokenDetailsSwapTransactionsStateConverter( return result.toPersistentList() } - fun updateTxStatus(tx: ExchangeUM, statusModel: ExchangeStatusModel?, refundToken: CryptoCurrency?): ExchangeUM { + fun updateTxStatus(tx: ExchangeUM, statusModel: ExchangeStatusModel?): ExchangeUM { if (statusModel == null || tx.activeStatus == statusModel.status) { Timber.e("UpdateTxStatus isn't required. Current status isn't changed") return tx } val hasFailed = statusModel.status == ExchangeStatus.Failed - val notifications = getNotification(statusModel.status, statusModel.txExternalUrl, refundToken) + val notifications = getNotification(statusModel.status, statusModel.txExternalUrl, statusModel.refundCurrency) val showProviderLink = getShowProviderLink(notifications, statusModel) return tx.copy( activeStatus = statusModel.status, diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/express/ExchangeStatusFactory.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/express/ExchangeStatusFactory.kt index fc416a7196..68d4f25bed 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/express/ExchangeStatusFactory.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/express/ExchangeStatusFactory.kt @@ -101,11 +101,9 @@ internal class ExchangeStatusFactory @AssistedInject constructor( } else { val statusModel = getExchangeStatus(swapTx.info.txId, swapTx.provider) - val addedRefundToken = addRefundCurrencyIfNeeded(statusModel, swapTx.provider.type) swapTransactionsStateConverter.updateTxStatus( tx = swapTx, statusModel = statusModel, - refundToken = addedRefundToken, ) } } @@ -116,8 +114,11 @@ internal class ExchangeStatusFactory @AssistedInject constructor( ifLeft = { null }, ifRight = { statusModel -> sendStatusUpdateAnalytics(statusModel, provider) - swapTransactionRepository.storeTransactionState(txId, statusModel) - statusModel + + val refundTokenCurrency = addRefundCurrencyIfNeeded(statusModel, provider.type) + + swapTransactionRepository.storeTransactionState(txId, statusModel, refundTokenCurrency) + statusModel.copy(refundCurrency = refundTokenCurrency) }, ) } 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 fa3df91c63..744218305e 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 @@ -784,7 +784,6 @@ internal class TokenDetailsViewModel @Inject constructor( } override fun onGoToRefundedTokenClick(cryptoCurrency: CryptoCurrency) { - onDisposeExpressStatus() router.openTokenDetails(userWalletId, cryptoCurrency) }