Updated on 2026-08-14
This commit is contained in:
parent
87c43ab20f
commit
8261e72fec
25 changed files with 269 additions and 48 deletions
|
|
@ -7,9 +7,10 @@ import com.tangem.feature.swap.converters.QuotesConverter
|
|||
import com.tangem.feature.swap.converters.SwapConverter
|
||||
import com.tangem.feature.swap.converters.TokensConverter
|
||||
import com.tangem.feature.swap.domain.SwapRepository
|
||||
import com.tangem.feature.swap.domain.models.ApproveModel
|
||||
import com.tangem.feature.swap.domain.models.Currency
|
||||
import com.tangem.feature.swap.domain.models.QuoteModel
|
||||
import com.tangem.feature.swap.domain.models.data.ApproveModel
|
||||
import com.tangem.feature.swap.domain.models.data.Currency
|
||||
import com.tangem.feature.swap.domain.models.data.QuoteModel
|
||||
import com.tangem.feature.swap.domain.models.data.SwapDataModel
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.withContext
|
||||
import javax.inject.Inject
|
||||
|
|
@ -64,16 +65,16 @@ class SwapRepositoryImpl @Inject constructor(
|
|||
fromTokenAddress: String,
|
||||
toTokenAddress: String,
|
||||
amount: String,
|
||||
fromAddress: String,
|
||||
fromWalletAddress: String,
|
||||
slippage: Int,
|
||||
) {
|
||||
): SwapDataModel {
|
||||
return withContext(coroutineDispatcher.io) {
|
||||
swapConverter.convert(
|
||||
oneInchApi.swap(
|
||||
fromTokenAddress = fromTokenAddress,
|
||||
toTokenAddress = toTokenAddress,
|
||||
amount = amount,
|
||||
fromAddress = fromAddress,
|
||||
fromAddress = fromWalletAddress,
|
||||
slippage = slippage,
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.tangem.feature.swap.converters
|
||||
|
||||
import com.tangem.datasource.api.oneinch.models.ApproveCalldataResponse
|
||||
import com.tangem.feature.swap.domain.models.ApproveModel
|
||||
import com.tangem.feature.swap.domain.models.data.ApproveModel
|
||||
import com.tangem.utils.converter.Converter
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
package com.tangem.feature.swap.converters
|
||||
|
||||
import com.tangem.datasource.api.oneinch.models.QuoteResponse
|
||||
import com.tangem.feature.swap.domain.models.QuoteModel
|
||||
import com.tangem.feature.swap.domain.models.data.QuoteModel
|
||||
import com.tangem.utils.converter.Converter
|
||||
import javax.inject.Inject
|
||||
|
||||
class QuotesConverter : Converter<QuoteResponse, QuoteModel> {
|
||||
class QuotesConverter @Inject constructor(): Converter<QuoteResponse, QuoteModel> {
|
||||
|
||||
override fun convert(value: QuoteResponse): QuoteModel {
|
||||
return QuoteModel(
|
||||
|
|
|
|||
|
|
@ -1,24 +1,32 @@
|
|||
package com.tangem.feature.swap.converters
|
||||
|
||||
import com.tangem.datasource.api.oneinch.models.SwapResponse
|
||||
import com.tangem.feature.swap.domain.models.SwapTransactionModel
|
||||
import com.tangem.datasource.api.oneinch.models.TransactionDto
|
||||
import com.tangem.feature.swap.domain.models.data.SwapDataModel
|
||||
import com.tangem.feature.swap.domain.models.data.TransactionModel
|
||||
import com.tangem.utils.converter.Converter
|
||||
import javax.inject.Inject
|
||||
|
||||
class SwapConverter @Inject constructor() : Converter<SwapResponse, SwapTransactionModel> {
|
||||
class SwapConverter @Inject constructor() : Converter<SwapResponse, SwapDataModel> {
|
||||
|
||||
override fun convert(value: SwapResponse): SwapTransactionModel {
|
||||
return SwapTransactionModel(
|
||||
override fun convert(value: SwapResponse): SwapDataModel {
|
||||
return SwapDataModel(
|
||||
fromTokenAddress = value.fromToken.address,
|
||||
toTokenAddress = value.toToken.address,
|
||||
toTokenAmount = value.fromTokenAmount,
|
||||
fromTokenAmount = value.toTokenAmount,
|
||||
fromWalletAddress = value.transaction.fromAddress,
|
||||
toWalletAddress = value.transaction.toAddress,
|
||||
data = value.transaction.data,
|
||||
value = value.transaction.value,
|
||||
gasPrice = value.transaction.gasPrice,
|
||||
gas = value.transaction.gas,
|
||||
transaction = convertTransaction(value.transaction),
|
||||
)
|
||||
}
|
||||
|
||||
private fun convertTransaction(transactionDto: TransactionDto): TransactionModel {
|
||||
return TransactionModel(
|
||||
fromWalletAddress = transactionDto.fromAddress,
|
||||
toWalletAddress = transactionDto.toAddress,
|
||||
data = transactionDto.data,
|
||||
value = transactionDto.value,
|
||||
gasPrice = transactionDto.gasPrice,
|
||||
gas = transactionDto.gas,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package com.tangem.feature.swap.converters
|
||||
|
||||
import com.tangem.datasource.api.tangemTech.CoinsResponse
|
||||
import com.tangem.feature.swap.domain.models.Currency
|
||||
import com.tangem.feature.swap.domain.models.data.Currency
|
||||
import com.tangem.utils.converter.Converter
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ class TokensConverter @Inject constructor() : Converter<CoinsResponse.Coin, Curr
|
|||
networkId = network.networkId,
|
||||
contractAddress = network.contractAddress!!,
|
||||
decimalCount = network.decimalCount!!.intValueExact(),
|
||||
logoUrl = "",//todo add logo
|
||||
logoUrl = getSmallIconUrl(value.id),
|
||||
)
|
||||
} else {
|
||||
Currency.NativeToken(
|
||||
|
|
@ -25,8 +25,17 @@ class TokensConverter @Inject constructor() : Converter<CoinsResponse.Coin, Curr
|
|||
name = value.name,
|
||||
symbol = value.symbol,
|
||||
networkId = network.networkId,
|
||||
logoUrl = "", //todo add logo
|
||||
logoUrl = getSmallIconUrl(value.id),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSmallIconUrl(coin: String): String {
|
||||
return "$DEFAULT_IMAGE_HOST$SMALL_ICON_PATH/$coin.png"
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val DEFAULT_IMAGE_HOST = "https://s3.eu-central-1.amazonaws.com/tangem.api/coins/"
|
||||
private const val SMALL_ICON_PATH = "small"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.tangem.feature.swap.di
|
||||
|
||||
import com.tangem.datasource.api.oneinch.OneInchApi
|
||||
import com.tangem.datasource.api.tangemTech.TangemTechApi
|
||||
import com.tangem.datasource.di.qualifiers.OneInchEthereum
|
||||
import com.tangem.feature.swap.SwapRepositoryImpl
|
||||
import com.tangem.feature.swap.converters.ApproveConverter
|
||||
import com.tangem.feature.swap.converters.QuotesConverter
|
||||
import com.tangem.feature.swap.converters.SwapConverter
|
||||
import com.tangem.feature.swap.converters.TokensConverter
|
||||
import com.tangem.feature.swap.domain.SwapRepository
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
class SwapDataModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideSwapRepository(
|
||||
tangemTechApi: TangemTechApi,
|
||||
@OneInchEthereum oneInchApi: OneInchApi,
|
||||
tokensConverter: TokensConverter,
|
||||
quotesConverter: QuotesConverter,
|
||||
swapConverter: SwapConverter,
|
||||
approveConverter: ApproveConverter,
|
||||
coroutineDispatcher: CoroutineDispatcherProvider,
|
||||
): SwapRepository {
|
||||
return SwapRepositoryImpl(
|
||||
tangemTechApi = tangemTechApi,
|
||||
oneInchApi = oneInchApi,
|
||||
tokensConverter = tokensConverter,
|
||||
quotesConverter = quotesConverter,
|
||||
swapConverter = swapConverter,
|
||||
approveConverter = approveConverter,
|
||||
coroutineDispatcher = coroutineDispatcher,
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue