Updated on 2026-08-14
This commit is contained in:
parent
6e92e35a38
commit
4d0cb6a243
24 changed files with 697 additions and 887 deletions
|
|
@ -18,10 +18,12 @@ import com.tangem.datasource.api.express.models.response.SwapPairsWithProviders
|
|||
import com.tangem.datasource.api.express.models.response.TxDetails
|
||||
import com.tangem.datasource.crypto.DataSignatureVerifier
|
||||
import com.tangem.datasource.exchangeservice.swap.ExpressUtils
|
||||
import com.tangem.datasource.local.converter.toEntity
|
||||
import com.tangem.datasource.local.preferences.AppPreferencesStore
|
||||
import com.tangem.datasource.local.preferences.PreferencesKeys
|
||||
import com.tangem.datasource.local.preferences.utils.getObjectSyncOrNull
|
||||
import com.tangem.datasource.local.preferences.utils.storeObject
|
||||
import com.tangem.datasource.local.txhistory.db.dao.ExpressHistoryDao
|
||||
import com.tangem.domain.exchange.RampStateManager
|
||||
import com.tangem.domain.express.models.ExpressOperationType
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
|
|
@ -52,13 +54,14 @@ internal class DefaultSwapRepository(
|
|||
private val dataSignatureVerifier: DataSignatureVerifier,
|
||||
private val appPreferencesStore: AppPreferencesStore,
|
||||
private val rampStateManager: RampStateManager,
|
||||
private val expressHistoryDao: ExpressHistoryDao,
|
||||
moshi: Moshi,
|
||||
) : SwapRepository {
|
||||
|
||||
private val expressDataConverter = ExpressDataConverter()
|
||||
private val leastTokenInfoConverter = LeastTokenInfoConverter()
|
||||
private val swapPairInfoConverter = SwapPairInfoConverter()
|
||||
private val exchangeStatusConverter = ExchangeStatusConverter()
|
||||
private val exchangeStatusConverter = ExchangeStatusConverter(moshi)
|
||||
private val txDetailsMoshiAdapter = moshi.adapter(TxDetails::class.java)
|
||||
|
||||
override suspend fun getPairs(
|
||||
|
|
@ -238,18 +241,21 @@ internal class DefaultSwapRepository(
|
|||
either {
|
||||
catch(
|
||||
block = {
|
||||
exchangeStatusConverter.convert(
|
||||
tangemExpressApi
|
||||
.getExchangeStatus(
|
||||
userWalletId = userWalletId.stringValue,
|
||||
refCode = ExpressUtils.getRefCode(
|
||||
userWallet = userWallet,
|
||||
appPreferencesStore = appPreferencesStore,
|
||||
),
|
||||
txId = txId,
|
||||
)
|
||||
.getOrThrow(),
|
||||
)
|
||||
val response = tangemExpressApi
|
||||
.getExchangeStatus(
|
||||
userWalletId = userWalletId.stringValue,
|
||||
refCode = ExpressUtils.getRefCode(
|
||||
userWallet = userWallet,
|
||||
appPreferencesStore = appPreferencesStore,
|
||||
),
|
||||
txId = txId,
|
||||
)
|
||||
.getOrThrow()
|
||||
|
||||
val entity = response.toEntity(ownerAddress = response.fromAddress.orEmpty())
|
||||
expressHistoryDao.upsertExchanges(listOf(entity))
|
||||
|
||||
exchangeStatusConverter.convert(response)
|
||||
},
|
||||
catch = { exception ->
|
||||
TangemLogger.e("getExchangeStatus error", exception)
|
||||
|
|
|
|||
|
|
@ -1,24 +1,33 @@
|
|||
package com.tangem.feature.swap.converters
|
||||
|
||||
import com.tangem.datasource.api.express.models.response.ExchangeStatusResponse
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.tangem.datasource.api.express.models.response.ExchangeItemResponse
|
||||
import com.tangem.feature.swap.domain.models.domain.ExchangeStatus
|
||||
import com.tangem.feature.swap.domain.models.domain.ExchangeStatusModel
|
||||
import com.tangem.utils.converter.Converter
|
||||
import org.joda.time.DateTime
|
||||
import com.tangem.datasource.api.express.models.response.ExchangeStatus as ResponseExchangeStatus
|
||||
|
||||
internal class ExchangeStatusConverter : Converter<ExchangeStatusResponse, ExchangeStatusModel> {
|
||||
override fun convert(value: ExchangeStatusResponse): ExchangeStatusModel {
|
||||
internal class ExchangeStatusConverter(moshi: Moshi) : Converter<ExchangeItemResponse, ExchangeStatusModel> {
|
||||
|
||||
private val responseStatusAdapter = moshi.adapter(ResponseExchangeStatus::class.java)
|
||||
|
||||
override fun convert(value: ExchangeItemResponse): ExchangeStatusModel {
|
||||
return ExchangeStatusModel(
|
||||
providerId = value.providerId,
|
||||
status = ExchangeStatus.entries.firstOrNull {
|
||||
it.name.lowercase() == value.status.name.lowercase()
|
||||
},
|
||||
status = value.status.toExchangeStatus(),
|
||||
txId = value.externalTxId,
|
||||
txExternalUrl = value.externalTxUrl,
|
||||
txExternalId = value.externalTxId,
|
||||
refundNetwork = value.refundNetwork,
|
||||
refundContractAddress = value.refundContractAddress,
|
||||
createdAt = value.createdAt,
|
||||
averageDuration = value.averageDuration,
|
||||
createdAt = runCatching { DateTime.parse(value.createdAt) }.getOrNull(),
|
||||
averageDuration = value.averageDuration?.toInt(),
|
||||
)
|
||||
}
|
||||
|
||||
private fun String.toExchangeStatus(): ExchangeStatus? {
|
||||
val responseStatus = responseStatusAdapter.fromJsonValue(this) ?: return null
|
||||
return ExchangeStatus.entries.firstOrNull { it.name == responseStatus.name }
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ import com.tangem.datasource.crypto.DataSignatureVerifier
|
|||
import com.tangem.datasource.di.NetworkMoshi
|
||||
import com.tangem.datasource.local.config.environment.EnvironmentConfig
|
||||
import com.tangem.datasource.local.preferences.AppPreferencesStore
|
||||
import com.tangem.datasource.local.txhistory.db.dao.ExpressHistoryDao
|
||||
import com.tangem.domain.account.supplier.SingleAccountListSupplier
|
||||
import com.tangem.domain.exchange.RampStateManager
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
|
|
@ -43,6 +44,7 @@ internal class SwapDataModule {
|
|||
@NetworkMoshi moshi: Moshi,
|
||||
appPreferencesStore: AppPreferencesStore,
|
||||
rampStateManager: RampStateManager,
|
||||
expressHistoryDao: ExpressHistoryDao,
|
||||
): SwapRepository {
|
||||
return DefaultSwapRepository(
|
||||
tangemExpressApi = tangemExpressApi,
|
||||
|
|
@ -53,6 +55,7 @@ internal class SwapDataModule {
|
|||
moshi = moshi,
|
||||
appPreferencesStore = appPreferencesStore,
|
||||
rampStateManager = rampStateManager,
|
||||
expressHistoryDao = expressHistoryDao,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue