Updated on 2026-08-14
This commit is contained in:
parent
eadf1a17c8
commit
2f3e6db10d
8 changed files with 51 additions and 16 deletions
|
|
@ -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<SavedSwapTransactionListModelInner>? = 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<ExchangeStatusModel>(
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -784,7 +784,6 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onGoToRefundedTokenClick(cryptoCurrency: CryptoCurrency) {
|
||||
onDisposeExpressStatus()
|
||||
router.openTokenDetails(userWalletId, cryptoCurrency)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue