Updated on 2026-08-14
This commit is contained in:
parent
8ff70e4615
commit
91415eb0d9
7 changed files with 41 additions and 21 deletions
|
|
@ -38,8 +38,6 @@ class UserWalletManagerImpl(
|
|||
private val walletFeatureToggles: WalletFeatureToggles,
|
||||
) : UserWalletManager {
|
||||
|
||||
val cryptoCurrencyFactory = CryptoCurrencyFactory()
|
||||
|
||||
override suspend fun getUserTokens(
|
||||
networkId: String,
|
||||
derivationPath: String?,
|
||||
|
|
@ -84,21 +82,13 @@ class UserWalletManagerImpl(
|
|||
}
|
||||
}
|
||||
|
||||
override fun getNativeTokenForNetwork(networkId: String): CryptoCurrency {
|
||||
override fun getNativeTokenForNetwork(networkId: String): Currency {
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" }
|
||||
|
||||
return requireNotNull(
|
||||
cryptoCurrencyFactory.createCoin(
|
||||
blockchain = blockchain,
|
||||
extraDerivationPath = null,
|
||||
derivationStyleProvider = requireNotNull(
|
||||
store.state.globalState
|
||||
.userWalletsListManager
|
||||
?.selectedUserWalletSync
|
||||
?.scanResponse
|
||||
?.derivationStyleProvider,
|
||||
),
|
||||
)
|
||||
return NativeToken(
|
||||
id = blockchain.toCoinId(),
|
||||
name = blockchain.fullName,
|
||||
symbol = blockchain.currency,
|
||||
networkId = networkId,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ dependencies {
|
|||
implementation(projects.domain.tokens.models)
|
||||
implementation(projects.domain.legacy)
|
||||
implementation(projects.domain.models)
|
||||
implementation(projects.domain.wallets)
|
||||
implementation(projects.domain.wallets.models)
|
||||
|
||||
/** Data */
|
||||
|
|
@ -32,5 +33,6 @@ dependencies {
|
|||
|
||||
/** DI */
|
||||
implementation(deps.hilt.android)
|
||||
|
||||
kapt(deps.hilt.kapt)
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import com.tangem.blockchain.common.Approver
|
|||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.Token
|
||||
import com.tangem.blockchain.extensions.Result
|
||||
import com.tangem.data.tokens.utils.CryptoCurrencyFactory
|
||||
import com.tangem.datasource.api.common.response.getOrThrow
|
||||
import com.tangem.datasource.api.express.TangemExpressApi
|
||||
import com.tangem.datasource.api.express.models.request.PairsRequestBody
|
||||
|
|
@ -15,8 +16,11 @@ import com.tangem.datasource.api.oneinch.errors.OneIncResponseException
|
|||
import com.tangem.datasource.api.tangemTech.TangemTechApi
|
||||
import com.tangem.datasource.config.ConfigManager
|
||||
import com.tangem.domain.common.extensions.fromNetworkId
|
||||
import com.tangem.domain.common.util.derivationStyleProvider
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
import com.tangem.domain.wallets.legacy.UserWalletsListManager
|
||||
import com.tangem.domain.wallets.legacy.WalletsStateHolder
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.feature.swap.converters.*
|
||||
import com.tangem.feature.swap.domain.SwapRepository
|
||||
|
|
@ -40,6 +44,7 @@ internal class SwapRepositoryImpl @Inject constructor(
|
|||
private val coroutineDispatcher: CoroutineDispatcherProvider,
|
||||
private val configManager: ConfigManager,
|
||||
private val walletManagersFacade: WalletManagersFacade,
|
||||
private val walletsStateHolder: WalletsStateHolder,
|
||||
) : SwapRepository {
|
||||
|
||||
private val tokensConverter = TokensConverter()
|
||||
|
|
@ -47,6 +52,7 @@ internal class SwapRepositoryImpl @Inject constructor(
|
|||
private val leastTokenInfoConverter = LeastTokenInfoConverter()
|
||||
private val swapPairInfoConverter = SwapPairInfoConverter()
|
||||
private val swapProviderConverter = SwapProviderConverter()
|
||||
private val cryptoCurrencyFactory = CryptoCurrencyFactory()
|
||||
|
||||
override suspend fun getPairs(
|
||||
initialCurrency: LeastTokenInfo,
|
||||
|
|
@ -304,6 +310,23 @@ internal class SwapRepositoryImpl @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
override fun getNativeTokenForNetwork(networkId: String): CryptoCurrency {
|
||||
val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" }
|
||||
|
||||
return requireNotNull(
|
||||
cryptoCurrencyFactory.createCoin(
|
||||
blockchain = blockchain,
|
||||
extraDerivationPath = null,
|
||||
derivationStyleProvider = requireNotNull(
|
||||
walletsStateHolder.userWalletsListManager
|
||||
?.selectedUserWalletSync
|
||||
?.scanResponse
|
||||
?.derivationStyleProvider,
|
||||
),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
// TODO("get this ids from blockchain enum later")
|
||||
private const val OPTIMISM_ID = "optimistic-ethereum"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import com.tangem.datasource.api.oneinch.OneInchErrorsHandler
|
|||
import com.tangem.datasource.api.tangemTech.TangemTechApi
|
||||
import com.tangem.datasource.config.ConfigManager
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
import com.tangem.domain.wallets.legacy.UserWalletsListManager
|
||||
import com.tangem.domain.wallets.legacy.WalletsStateHolder
|
||||
import com.tangem.feature.swap.SwapRepositoryImpl
|
||||
import com.tangem.feature.swap.domain.SwapRepository
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
|
|
@ -29,6 +31,7 @@ class SwapDataModule {
|
|||
coroutineDispatcher: CoroutineDispatcherProvider,
|
||||
configManager: ConfigManager,
|
||||
walletManagerFacade: WalletManagersFacade,
|
||||
walletsStateHolder: WalletsStateHolder
|
||||
): SwapRepository {
|
||||
return SwapRepositoryImpl(
|
||||
tangemTechApi = tangemTechApi,
|
||||
|
|
@ -38,6 +41,7 @@ class SwapDataModule {
|
|||
coroutineDispatcher = coroutineDispatcher,
|
||||
configManager = configManager,
|
||||
walletManagersFacade = walletManagerFacade,
|
||||
walletsStateHolder = walletsStateHolder,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -506,7 +506,7 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
|
||||
private suspend fun getFormattedFiatFees(networkId: String, vararg fees: BigDecimal): List<String> {
|
||||
val appCurrency = userWalletManager.getUserAppCurrency()
|
||||
val nativeToken = userWalletManager.getNativeTokenForNetwork(networkId)
|
||||
val nativeToken = repository.getNativeTokenForNetwork(networkId)
|
||||
val rates = getQuotes(nativeToken.id)
|
||||
return rates[nativeToken.id]?.fiatRate?.let { rate ->
|
||||
fees.map { fee ->
|
||||
|
|
@ -596,8 +596,7 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
): SwapState.QuotesLoadedState {
|
||||
val fromToken = fromTokenStatus.currency
|
||||
val toToken = toTokenStatus.currency
|
||||
val appCurrency = userWalletManager.getUserAppCurrency()
|
||||
val nativeToken = userWalletManager.getNativeTokenForNetwork(networkId)
|
||||
val nativeToken = repository.getNativeTokenForNetwork(networkId)
|
||||
|
||||
val rates = getQuotes(fromToken.id, toToken.id, nativeToken.id)
|
||||
return SwapState.QuotesLoadedState(
|
||||
|
|
@ -654,7 +653,7 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
val feeData = transactionManager.getFee(
|
||||
networkId = networkId,
|
||||
amountToSend = BigDecimal.ZERO,
|
||||
currencyToSend = swapCurrencyConverter.convert(userWalletManager.getNativeTokenForNetwork(networkId)),
|
||||
currencyToSend = swapCurrencyConverter.convert(repository.getNativeTokenForNetwork(networkId)),
|
||||
destinationAddress = getTokenAddress(fromToken),
|
||||
increaseBy = INCREASE_GAS_LIMIT_BY,
|
||||
data = transactionData,
|
||||
|
|
|
|||
|
|
@ -78,4 +78,6 @@ interface SwapRepository {
|
|||
providerId: String,
|
||||
rateType: RateType,
|
||||
): ExchangeQuote
|
||||
|
||||
fun getNativeTokenForNetwork(networkId: String): CryptoCurrency
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ interface UserWalletManager {
|
|||
suspend fun getUserTokens(networkId: String, derivationPath: String?, isExcludeCustom: Boolean): List<Currency>
|
||||
|
||||
@Throws(IllegalStateException::class)
|
||||
fun getNativeTokenForNetwork(networkId: String): CryptoCurrency
|
||||
fun getNativeTokenForNetwork(networkId: String): Currency
|
||||
|
||||
/**
|
||||
* Returns user walletId or empty string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue