Updated on 2026-08-14

This commit is contained in:
Tangem 2025-12-17 14:05:58 +03:00
commit 3cbc2dadfb
822 changed files with 12838 additions and 5366 deletions

View file

@ -1,19 +0,0 @@
<?xml version="1.0" ?>
<SmellBaseline>
<ManuallySuppressedIssues/>
<CurrentIssues>
<ID>MaxChainedCallsOnSameLine:DefaultSwapRepositoryV2.kt$DefaultSwapRepositoryV2$fromCryptoCurrencyStatus.value.networkAddress?.defaultAddress?.value.orEmpty()</ID>
<ID>MultilineLambdaItParameter:DefaultSwapRepositoryV2.kt$DefaultSwapRepositoryV2${ Timber.w(it, "Unable to get pairs") throw it }</ID>
<ID>MultilineLambdaItParameter:DefaultSwapRepositoryV2.kt$DefaultSwapRepositoryV2${ it.currency.getContractAddress() == pair.from.contractAddress &amp;&amp; it.currency.network.backendId == pair.from.network }</ID>
<ID>MultilineLambdaItParameter:DefaultSwapRepositoryV2.kt$DefaultSwapRepositoryV2${ it.currency.getContractAddress() == pair.to.contractAddress &amp;&amp; it.currency.network.backendId == pair.to.network }</ID>
<ID>MultilineLambdaItParameter:DefaultSwapRepositoryV2.kt$DefaultSwapRepositoryV2${ it.getContractAddress() == pair.from.contractAddress &amp;&amp; it.network.backendId == pair.from.network }</ID>
<ID>MultilineLambdaItParameter:DefaultSwapRepositoryV2.kt$DefaultSwapRepositoryV2${ it.getContractAddress() == pair.to.contractAddress &amp;&amp; it.network.backendId == pair.to.network }</ID>
<ID>MultilineLambdaItParameter:DefaultSwapTransactionRepository.kt$DefaultSwapTransactionRepository${ it.checkId( checkUserWalletId = userWalletId, fromCurrencyId = fromCryptoCurrency.id, toCurrencyId = toCryptoCurrency.id, ) }</ID>
<ID>MultilineLambdaItParameter:DefaultSwapTransactionRepository.kt$DefaultSwapTransactionRepository${ it.userWalletId == userWallet.walletId.stringValue &amp;&amp; ( it.toCryptoCurrencyId == cryptoCurrencyId.value || it.fromCryptoCurrencyId == cryptoCurrencyId.value ) }</ID>
<ID>MultilineLambdaItParameter:DefaultSwapTransactionRepository.kt$DefaultSwapTransactionRepository${ listConverter.convertBack( value = it, multiAccountList = multiAccountList, userWallet = userWallet, txStatuses = txStatuses, ) }</ID>
<ID>MultilineLambdaItParameter:DefaultSwapTransactionRepository.kt$DefaultSwapTransactionRepository${ storeTransactionState( txId = transaction.txId, status = it, accountWithCurrency = fromAccount?.accountId to fromCryptoCurrency, ) }</ID>
<ID>MultilineLambdaItParameter:SwapDataConverter.kt$SwapDataConverter${ if (it == "0") { BigDecimal.ZERO } else { requireNotNull(it.toBigDecimalOrNull()) { "wrong amount format, use only digits" } } }</ID>
<ID>NoNameShadowing:DefaultSwapRepositoryV2.kt$DefaultSwapRepositoryV2$mappedProviders</ID>
<ID>NoNameShadowing:DefaultSwapTransactionRepository.kt$DefaultSwapTransactionRepository${ it.txId == txId }</ID>
</CurrentIssues>
</SmellBaseline>

View file

@ -79,23 +79,23 @@ internal class DefaultSwapRepositoryV2 @Inject constructor(
userWallet = userWallet,
filterProviderTypes = filterProviderTypes,
)
val mappedProviders = providers.associateBy(ExpressProvider::providerId)
val expressProviders = providers.associateBy(ExpressProvider::providerId)
allPairs.map { pair ->
async {
val statusFrom = cryptoCurrencyStatusList
.firstOrNull {
it.currency.getContractAddress() == pair.from.contractAddress &&
it.currency.network.backendId == pair.from.network
.firstOrNull { currencyStatus ->
currencyStatus.currency.getContractAddress() == pair.from.contractAddress &&
currencyStatus.currency.network.backendId == pair.from.network
}
val statusTo = cryptoCurrencyStatusList
.firstOrNull {
it.currency.getContractAddress() == pair.to.contractAddress &&
it.currency.network.backendId == pair.to.network
.firstOrNull { currencyStatus ->
currencyStatus.currency.getContractAddress() == pair.to.contractAddress &&
currencyStatus.currency.network.backendId == pair.to.network
}
val mappedProviders = pair.providers.mapNotNull {
mappedProviders[it.providerId]
expressProviders[it.providerId]
}.filterYieldSupplyProvider(statusFrom)
if (statusFrom != null && statusTo != null && mappedProviders.isNotEmpty()) {
@ -135,16 +135,16 @@ internal class DefaultSwapRepositoryV2 @Inject constructor(
async {
val statusFromDeferred = async {
cryptoCurrencyList
.firstOrNull {
it.getContractAddress() == pair.from.contractAddress &&
it.network.backendId == pair.from.network
.firstOrNull { currency ->
currency.getContractAddress() == pair.from.contractAddress &&
currency.network.backendId == pair.from.network
}
}
val statusToDeferred = async {
cryptoCurrencyList
.firstOrNull {
it.getContractAddress() == pair.to.contractAddress &&
it.network.backendId == pair.to.network
.firstOrNull { currency ->
currency.getContractAddress() == pair.to.contractAddress &&
currency.network.backendId == pair.to.network
}
}
@ -213,27 +213,27 @@ internal class DefaultSwapRepositoryV2 @Inject constructor(
expressOperationType: ExpressOperationType,
): SwapDataModel = withContext(coroutineDispatcher.io) {
val requestId = UUID.randomUUID().toString()
val fromCryptoCurrency = fromCryptoCurrencyStatus.currency
val (fromCurrency, fromStatus) = fromCryptoCurrencyStatus
val refundData = when (expressProvider.type) {
ExpressProviderType.CEX,
ExpressProviderType.DEX_BRIDGE,
ExpressProviderType.DEX,
-> SwapRefundData(
refundAddress = fromCryptoCurrencyStatus.value.networkAddress?.defaultAddress?.value,
refundAddress = fromStatus.networkAddress?.defaultAddress?.value,
refundExtraId = null, // currently always null
)
else -> null
}
val response = tangemExpressApi.getExchangeData(
fromContractAddress = fromCryptoCurrency.getContractAddress(),
fromContractAddress = fromCurrency.getContractAddress(),
toContractAddress = toCryptoCurrency.getContractAddress(),
fromNetwork = fromCryptoCurrency.network.backendId,
fromNetwork = fromCurrency.network.backendId,
toNetwork = toCryptoCurrency.network.backendId,
fromAddress = fromCryptoCurrencyStatus.value.networkAddress?.defaultAddress?.value.orEmpty(),
fromAddress = fromStatus.networkAddress?.defaultAddress?.value.orEmpty(),
toAddress = toAddress,
fromDecimals = fromCryptoCurrency.decimals,
fromDecimals = fromCurrency.decimals,
toDecimals = toCryptoCurrency.decimals,
fromAmount = fromAmount,
providerId = expressProvider.providerId,
@ -277,6 +277,7 @@ internal class DefaultSwapRepositoryV2 @Inject constructor(
txHash: String,
txExtraId: String?,
) {
val (currency, status) = fromCryptoCurrencyStatus
withContext(coroutineDispatcher.io) {
tangemExpressApi.exchangeSent(
userWalletId = userWallet.walletId.stringValue,
@ -286,8 +287,8 @@ internal class DefaultSwapRepositoryV2 @Inject constructor(
),
body = ExchangeSentRequestBody(
txId = txId,
fromNetwork = fromCryptoCurrencyStatus.currency.network.backendId,
fromAddress = fromCryptoCurrencyStatus.value.networkAddress?.defaultAddress?.value.orEmpty(),
fromNetwork = currency.network.backendId,
fromAddress = status.networkAddress?.defaultAddress?.value.orEmpty(),
payinAddress = payInAddress,
payinExtraId = txExtraId,
txHash = txHash,
@ -364,9 +365,9 @@ internal class DefaultSwapRepositoryV2 @Inject constructor(
),
).getOrThrow()
},
onError = {
Timber.w(it, "Unable to get pairs")
throw it
onError = { error ->
Timber.w(error, "Unable to get pairs")
throw error
},
)
}
@ -403,7 +404,7 @@ internal class DefaultSwapRepositoryV2 @Inject constructor(
value = NetworkStatus.MissedDerivation, // Caution!!! Do not change this status
).some(),
maybeQuoteStatus = quoteStatus.toOption(),
maybeYieldBalance = none(),
maybeStakingBalance = none(),
)
}

View file

@ -64,10 +64,10 @@ internal class DefaultSwapTransactionRepository(
toAccount: Account.CryptoPortfolio?,
transaction: SwapTransactionModel,
) {
transaction.status?.let {
transaction.status?.let { swapTxList ->
storeTransactionState(
txId = transaction.txId,
status = it,
status = swapTxList,
accountWithCurrency = fromAccount?.accountId to fromCryptoCurrency,
)
}
@ -76,8 +76,8 @@ internal class DefaultSwapTransactionRepository(
key = PreferencesKeys.SWAP_TRANSACTIONS_KEY,
)
val tokenTransactions = savedTransactions
?.firstOrNull {
it.checkId(
?.firstOrNull { swapTxList ->
swapTxList.checkId(
checkUserWalletId = userWalletId,
fromCurrencyId = fromCryptoCurrency.id,
toCurrencyId = toCryptoCurrency.id,
@ -129,17 +129,17 @@ internal class DefaultSwapTransactionRepository(
},
) { savedTransactions, txStatuses, multiAccountList ->
val currencyTxs = savedTransactions
?.filter {
it.userWalletId == userWallet.walletId.stringValue &&
?.filter { swapTxList ->
swapTxList.userWalletId == userWallet.walletId.stringValue &&
(
it.toCryptoCurrencyId == cryptoCurrencyId.value ||
it.fromCryptoCurrencyId == cryptoCurrencyId.value
swapTxList.toCryptoCurrencyId == cryptoCurrencyId.value ||
swapTxList.fromCryptoCurrencyId == cryptoCurrencyId.value
)
}
currencyTxs?.mapNotNull {
currencyTxs?.mapNotNull { swapTxList ->
listConverter.convertBack(
value = it,
value = swapTxList,
multiAccountList = multiAccountList,
userWallet = userWallet,
txStatuses = txStatuses,
@ -155,8 +155,8 @@ internal class DefaultSwapTransactionRepository(
)
val tokenTransactions = savedList
?.asSequence()
?.map {
it.copy(transactions = it.transactions.filterNot { it.txId == txId })
?.map { swapTxList ->
swapTxList.copy(transactions = swapTxList.transactions.filterNot { swapTx -> swapTx.txId == txId })
}?.filterNot { it.transactions.isEmpty() }
?.toList()
@ -257,8 +257,8 @@ internal class DefaultSwapTransactionRepository(
toAccount = toAccount,
tokenTransactions = transactions,
),
predicate = {
it.checkId(
predicate = { swapTxList ->
swapTxList.checkId(
checkUserWalletId = userWalletId,
fromCurrencyId = fromCryptoCurrency.id,
toCurrencyId = toCryptoCurrency.id,

View file

@ -31,11 +31,11 @@ internal class SwapDataConverter : Converter<ExchangeDataResponseWithTxDetails,
)
return if (transactionDto.txType == TxType.SWAP) {
val otherNativeFeeWei = transactionDto.otherNativeFee?.let {
if (it == "0") {
val otherNativeFeeWei = transactionDto.otherNativeFee?.let { otherFee ->
if (otherFee == "0") {
BigDecimal.ZERO
} else {
requireNotNull(it.toBigDecimalOrNull()) { "wrong amount format, use only digits" }
requireNotNull(otherFee.toBigDecimalOrNull()) { "wrong amount format, use only digits" }
}
}
SwapDataTransactionModel.DEX(