Updated on 2026-08-14
This commit is contained in:
parent
626d0914a0
commit
88ab462aa7
26 changed files with 365 additions and 428 deletions
|
|
@ -118,7 +118,7 @@ internal class DefaultSwapRepository(
|
|||
)
|
||||
} catch (exception: Exception) {
|
||||
if (exception is ApiResponseError.HttpException) {
|
||||
throw ExpressException(errorsDataConverter.convert(exception.errorBody ?: ""))
|
||||
throw ExpressException(errorsDataConverter.convert(exception.errorBody.orEmpty()))
|
||||
} else {
|
||||
throw exception
|
||||
}
|
||||
|
|
@ -138,12 +138,12 @@ internal class DefaultSwapRepository(
|
|||
network = initialCurrency.network,
|
||||
)
|
||||
val currenciesList = currencyList
|
||||
.filter {
|
||||
val requirements = walletManagersFacade.getAssetRequirements(userWallet.walletId, it)
|
||||
.filter { currency ->
|
||||
val requirements = walletManagersFacade.getAssetRequirements(userWallet.walletId, currency)
|
||||
val isAvailableForSwap = rampStateManager.checkAssetRequirements(requirements)
|
||||
isAvailableForSwap
|
||||
}
|
||||
.map { leastTokenInfoConverter.convert(it) }
|
||||
.map { currency -> leastTokenInfoConverter.convert(currency) }
|
||||
|
||||
val pairsDeferred = async {
|
||||
getPairsInternal(
|
||||
|
|
@ -174,7 +174,7 @@ internal class DefaultSwapRepository(
|
|||
)
|
||||
} catch (exception: Exception) {
|
||||
if (exception is ApiResponseError.HttpException) {
|
||||
throw ExpressException(errorsDataConverter.convert(exception.errorBody ?: ""))
|
||||
throw ExpressException(errorsDataConverter.convert(exception.errorBody.orEmpty()))
|
||||
} else {
|
||||
throw exception
|
||||
}
|
||||
|
|
@ -221,9 +221,9 @@ internal class DefaultSwapRepository(
|
|||
.getOrThrow(),
|
||||
)
|
||||
},
|
||||
catch = {
|
||||
Timber.e("getExchangeStatus error: $it")
|
||||
raise(UnknownError(it.message))
|
||||
catch = { exception ->
|
||||
Timber.e("getExchangeStatus error: $exception")
|
||||
raise(UnknownError(exception.message))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -420,7 +420,7 @@ internal class DefaultSwapRepository(
|
|||
|
||||
private fun getDataError(ex: Exception): ExpressDataError {
|
||||
return if (ex is ApiResponseError.HttpException) {
|
||||
errorsDataConverter.convert(ex.errorBody ?: "")
|
||||
errorsDataConverter.convert(ex.errorBody.orEmpty())
|
||||
} else {
|
||||
ExpressDataError.UnknownError
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,10 +51,10 @@ internal class DefaultSwapTransactionRepository(
|
|||
toAccount: Account.CryptoPortfolio?,
|
||||
transaction: SavedSwapTransactionModel,
|
||||
) {
|
||||
transaction.status?.let {
|
||||
transaction.status?.let { status ->
|
||||
storeTransactionState(
|
||||
txId = transaction.txId,
|
||||
status = it,
|
||||
status = status,
|
||||
accountWithCurrency = null,
|
||||
)
|
||||
}
|
||||
|
|
@ -63,8 +63,8 @@ internal class DefaultSwapTransactionRepository(
|
|||
key = PreferencesKeys.SWAP_TRANSACTIONS_KEY,
|
||||
)
|
||||
val tokenTransactions = savedTransactions
|
||||
?.firstOrNull {
|
||||
it.checkId(
|
||||
?.firstOrNull { savedTx ->
|
||||
savedTx.checkId(
|
||||
checkUserWalletId = userWalletId,
|
||||
fromCurrencyId = fromCryptoCurrency.id,
|
||||
toCurrencyId = toCryptoCurrency.id,
|
||||
|
|
@ -73,7 +73,7 @@ internal class DefaultSwapTransactionRepository(
|
|||
?.transactions
|
||||
?.addOrReplace(
|
||||
item = transaction,
|
||||
predicate = { it.txId == transaction.txId },
|
||||
predicate = { tx -> tx.txId == transaction.txId },
|
||||
) ?: listOf(transaction)
|
||||
|
||||
mutablePreferences.setObject(
|
||||
|
|
@ -117,31 +117,31 @@ internal class DefaultSwapTransactionRepository(
|
|||
},
|
||||
) { savedTransactions, txStatuses, accountList ->
|
||||
|
||||
val currencyToTxs = savedTransactions?.filter {
|
||||
val isUserWallet = it.userWalletId == userWallet.walletId.stringValue
|
||||
val toCurrency = it.toCryptoCurrencyId == cryptoCurrencyId.value
|
||||
isUserWallet && toCurrency
|
||||
val currencyToTxs = savedTransactions?.filter { savedTx ->
|
||||
val isUserWallet = savedTx.userWalletId == userWallet.walletId.stringValue
|
||||
val isToCurrency = savedTx.toCryptoCurrencyId == cryptoCurrencyId.value
|
||||
isUserWallet && isToCurrency
|
||||
}
|
||||
|
||||
val currencyFromTxs = savedTransactions?.filter {
|
||||
val isUserWallet = it.userWalletId == userWallet.walletId.stringValue
|
||||
val fromCurrency = it.fromCryptoCurrencyId == cryptoCurrencyId.value
|
||||
isUserWallet && fromCurrency
|
||||
val currencyFromTxs = savedTransactions?.filter { savedTx ->
|
||||
val isUserWallet = savedTx.userWalletId == userWallet.walletId.stringValue
|
||||
val isFromCurrency = savedTx.fromCryptoCurrencyId == cryptoCurrencyId.value
|
||||
isUserWallet && isFromCurrency
|
||||
}
|
||||
|
||||
val toTxs = currencyToTxs?.mapNotNull {
|
||||
val toTxs = currencyToTxs?.mapNotNull { savedTx ->
|
||||
converter.convertBack(
|
||||
value = it,
|
||||
value = savedTx,
|
||||
userWallet = userWallet,
|
||||
accountList = accountList,
|
||||
txStatuses = txStatuses,
|
||||
onFilter = { it.swapTxTypeDTO == SwapTxTypeDTO.Swap },
|
||||
onFilter = { tx -> tx.swapTxTypeDTO == SwapTxTypeDTO.Swap },
|
||||
)
|
||||
}.orEmpty()
|
||||
|
||||
val fromTxs = currencyFromTxs?.mapNotNull {
|
||||
val fromTxs = currencyFromTxs?.mapNotNull { savedTx ->
|
||||
converter.convertBack(
|
||||
value = it,
|
||||
value = savedTx,
|
||||
userWallet = userWallet,
|
||||
accountList = accountList,
|
||||
txStatuses = txStatuses,
|
||||
|
|
@ -161,9 +161,9 @@ internal class DefaultSwapTransactionRepository(
|
|||
)
|
||||
val tokenTransactions = savedList
|
||||
?.asSequence()
|
||||
?.map {
|
||||
it.copy(transactions = it.transactions.filterNot { it.txId == txId })
|
||||
}?.filterNot { it.transactions.isEmpty() }
|
||||
?.map { savedTx ->
|
||||
savedTx.copy(transactions = savedTx.transactions.filterNot { tx -> tx.txId == txId })
|
||||
}?.filterNot { savedTx -> savedTx.transactions.isEmpty() }
|
||||
?.toList()
|
||||
|
||||
if (tokenTransactions.isNullOrEmpty()) {
|
||||
|
|
@ -261,8 +261,8 @@ internal class DefaultSwapTransactionRepository(
|
|||
toAccount = toAccount,
|
||||
tokenTransactions = transactions,
|
||||
),
|
||||
predicate = {
|
||||
it.checkId(
|
||||
predicate = { savedTx ->
|
||||
savedTx.checkId(
|
||||
checkUserWalletId = userWalletId,
|
||||
fromCurrencyId = fromCryptoCurrency.id,
|
||||
toCurrencyId = toCryptoCurrency.id,
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ internal class ExpressDataConverter : Converter<ExchangeDataResponseWithTxDetail
|
|||
dataResponse: ExchangeDataResponse,
|
||||
): ExpressTransactionModel {
|
||||
return if (transactionDto.txType == TxType.SWAP) {
|
||||
val otherNativeFeeWei = transactionDto.otherNativeFee?.let {
|
||||
if (it == "0") {
|
||||
val otherNativeFeeWei = transactionDto.otherNativeFee?.let { feeValue ->
|
||||
if (feeValue == "0") {
|
||||
BigDecimal.ZERO
|
||||
} else {
|
||||
requireNotNull(it.toBigDecimalOrNull()) { "wrong amount format, use only digits" }
|
||||
requireNotNull(feeValue.toBigDecimalOrNull()) { "wrong amount format, use only digits" }
|
||||
}
|
||||
}
|
||||
ExpressTransactionModel.DEX(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue