Updated on 2026-08-14

This commit is contained in:
Tangem 2026-04-23 18:01:25 +05:00
parent 53b02cfb10
commit 2be7445212
81 changed files with 4444 additions and 3434 deletions

View file

@ -23,6 +23,7 @@ import com.tangem.domain.exchange.RampStateManager
import com.tangem.domain.express.models.ExpressOperationType
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.wallet.UserWallet
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.feature.swap.converters.*
import com.tangem.feature.swap.domain.api.SwapRepository
@ -226,7 +227,8 @@ internal class DefaultSwapRepository(
}
override suspend fun getExchangeStatus(
userWallet: UserWallet,
userWallet: UserWallet?,
userWalletId: UserWalletId,
txId: String,
): Either<UnknownError, ExchangeStatusModel> {
return withContext(coroutineDispatcher.io) {
@ -236,7 +238,7 @@ internal class DefaultSwapRepository(
exchangeStatusConverter.convert(
tangemExpressApi
.getExchangeStatus(
userWalletId = userWallet.walletId.stringValue,
userWalletId = userWalletId.stringValue,
refCode = ExpressUtils.getRefCode(
userWallet = userWallet,
appPreferencesStore = appPreferencesStore,

View file

@ -41,7 +41,8 @@ internal class DefaultSwapTransactionRepository(
private val userTokensResponseFactory = UserTokensResponseFactory()
override suspend fun storeTransaction(
userWalletId: UserWalletId,
fromUserWalletId: UserWalletId,
toUserWalletId: UserWalletId,
fromCryptoCurrency: CryptoCurrency,
toCryptoCurrency: CryptoCurrency,
fromAccount: Account?,
@ -62,7 +63,8 @@ internal class DefaultSwapTransactionRepository(
val tokenTransactions = savedTransactions
?.firstOrNull { savedTx ->
savedTx.checkId(
checkUserWalletId = userWalletId,
fromUserWalletId = fromUserWalletId,
toUserWalletId = toUserWalletId,
fromCurrencyId = fromCryptoCurrency.id,
toCurrencyId = toCryptoCurrency.id,
)
@ -76,7 +78,8 @@ internal class DefaultSwapTransactionRepository(
mutablePreferences.setObject(
key = PreferencesKeys.SWAP_TRANSACTIONS_KEY,
value = savedTransactions?.updateList(
userWalletId = userWalletId,
fromUserWalletId = fromUserWalletId,
toUserWalletId = toUserWalletId,
fromCryptoCurrency = fromCryptoCurrency,
toCryptoCurrency = toCryptoCurrency,
fromAccount = fromAccount,
@ -84,7 +87,8 @@ internal class DefaultSwapTransactionRepository(
transactions = tokenTransactions,
) ?: listOf(
converter.default(
userWalletId = userWalletId,
fromUserWalletId = fromUserWalletId,
toUserWalletId = toUserWalletId,
fromCryptoCurrency = fromCryptoCurrency,
toCryptoCurrency = toCryptoCurrency,
fromAccount = fromAccount,
@ -111,13 +115,13 @@ internal class DefaultSwapTransactionRepository(
) { savedTransactions, txStatuses, accountList ->
val currencyToTxs = savedTransactions?.filter { savedTx ->
val isUserWallet = savedTx.userWalletId == userWallet.walletId.stringValue
val isUserWallet = savedTx.toUserWalletId == userWallet.walletId.stringValue
val isToCurrency = savedTx.toCryptoCurrencyId == cryptoCurrencyId.value
isUserWallet && isToCurrency
}
val currencyFromTxs = savedTransactions?.filter { savedTx ->
val isUserWallet = savedTx.userWalletId == userWallet.walletId.stringValue
val isUserWallet = savedTx.fromUserWalletId == userWallet.walletId.stringValue
val isFromCurrency = savedTx.fromCryptoCurrencyId == cryptoCurrencyId.value
isUserWallet && isFromCurrency
}
@ -227,18 +231,21 @@ internal class DefaultSwapTransactionRepository(
}
private fun SavedSwapTransactionListModelInner.checkId(
checkUserWalletId: UserWalletId,
fromUserWalletId: UserWalletId,
toUserWalletId: UserWalletId,
fromCurrencyId: CryptoCurrency.ID,
toCurrencyId: CryptoCurrency.ID,
): Boolean {
return userWalletId == checkUserWalletId.stringValue &&
return this.fromUserWalletId == fromUserWalletId.stringValue &&
this.toUserWalletId == toUserWalletId.stringValue &&
toCryptoCurrencyId == toCurrencyId.value &&
fromCryptoCurrencyId == fromCurrencyId.value
}
@Suppress("LongParameterList")
private fun List<SavedSwapTransactionListModelInner>.updateList(
userWalletId: UserWalletId,
fromUserWalletId: UserWalletId,
toUserWalletId: UserWalletId,
fromCryptoCurrency: CryptoCurrency,
toCryptoCurrency: CryptoCurrency,
fromAccount: Account?,
@ -247,7 +254,8 @@ internal class DefaultSwapTransactionRepository(
): List<SavedSwapTransactionListModelInner> {
return addOrReplace(
item = converter.default(
userWalletId = userWalletId,
fromUserWalletId = fromUserWalletId,
toUserWalletId = toUserWalletId,
fromCryptoCurrency = fromCryptoCurrency,
toCryptoCurrency = toCryptoCurrency,
fromAccount = fromAccount,
@ -256,7 +264,8 @@ internal class DefaultSwapTransactionRepository(
),
predicate = { savedTx ->
savedTx.checkId(
checkUserWalletId = userWalletId,
fromUserWalletId = fromUserWalletId,
toUserWalletId = toUserWalletId,
fromCurrencyId = fromCryptoCurrency.id,
toCurrencyId = toCryptoCurrency.id,
)

View file

@ -28,7 +28,8 @@ internal class SavedSwapTransactionListConverter(
private val userTokensResponseFactory = UserTokensResponseFactory()
override fun convert(value: SavedSwapTransactionListModel) = SavedSwapTransactionListModelInner(
userWalletId = value.userWalletId,
fromUserWalletId = value.fromUserWalletId,
toUserWalletId = value.toUserWalletId,
fromCryptoCurrencyId = value.fromCryptoCurrencyId,
toCryptoCurrencyId = value.toCryptoCurrencyId,
fromTokensResponse = userTokensResponseFactory.createResponseToken(
@ -98,7 +99,8 @@ internal class SavedSwapTransactionListConverter(
val statusWithRefundCurrency = status?.copy(refundCurrency = refundCurrency)
tx.copy(status = statusWithRefundCurrency)
},
userWalletId = value.userWalletId,
fromUserWalletId = value.fromUserWalletId,
toUserWalletId = value.toUserWalletId,
fromCryptoCurrencyId = value.fromCryptoCurrencyId,
toCryptoCurrencyId = value.toCryptoCurrencyId,
fromCryptoCurrency = fromCryptoCurrency,
@ -117,14 +119,16 @@ internal class SavedSwapTransactionListConverter(
@Suppress("LongParameterList")
fun default(
userWalletId: UserWalletId,
fromUserWalletId: UserWalletId,
toUserWalletId: UserWalletId,
fromCryptoCurrency: CryptoCurrency,
toCryptoCurrency: CryptoCurrency,
fromAccount: Account?,
toAccount: Account?,
tokenTransactions: List<SavedSwapTransactionModel>,
) = SavedSwapTransactionListModelInner(
userWalletId = userWalletId.stringValue,
fromUserWalletId = fromUserWalletId.stringValue,
toUserWalletId = toUserWalletId.stringValue,
fromCryptoCurrencyId = fromCryptoCurrency.id.value,
toCryptoCurrencyId = toCryptoCurrency.id.value,
fromTokensResponse = userTokensResponseFactory.createResponseToken(