Updated on 2026-08-14
This commit is contained in:
parent
06d1f35002
commit
6ed1946ac3
16 changed files with 191 additions and 220 deletions
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" ?>
|
||||
<SmellBaseline>
|
||||
<ManuallySuppressedIssues/>
|
||||
<CurrentIssues>
|
||||
<ID>MultilineLambdaItParameter:DefaultCustomTokensRepository.kt$DefaultCustomTokensRepository${ // TODO: refactor https://tangem.atlassian.net/browse/AND-10006\ if (it.isTestnet() || it in excludedBlockchains || it in hotWalletExcludedBlockchains) { return@mapNotNull null } networkFactory.create( blockchain = it, extraDerivationPath = null, userWallet = userWallet, ) }</ID>
|
||||
<ID>MultilineLambdaItParameter:ManageTokensUpdateFetcher.kt$ManageTokensUpdateFetcher${ if (it.key == toUpdate[index].key) { Batch(it.key, updatedItems) } else { null } }</ID>
|
||||
<ID>UnsafeCallOnNullableType:DefaultCustomTokensRepository.kt$DefaultCustomTokensRepository$coinNetwork.decimalCount!!</ID>
|
||||
</CurrentIssues>
|
||||
</SmellBaseline>
|
||||
|
|
@ -13,11 +13,11 @@ import com.tangem.data.managetokens.utils.TokenAddressesConverter
|
|||
import com.tangem.datasource.api.common.response.getOrThrow
|
||||
import com.tangem.datasource.api.tangemTech.TangemTechApi
|
||||
import com.tangem.datasource.local.token.UserTokensResponseStore
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.card.common.extensions.canHandleBlockchain
|
||||
import com.tangem.domain.card.common.extensions.hotWalletExcludedBlockchains
|
||||
import com.tangem.domain.card.common.extensions.supportedBlockchains
|
||||
import com.tangem.domain.card.common.util.cardTypesResolver
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.managetokens.model.AddCustomTokenForm
|
||||
import com.tangem.domain.managetokens.model.ManagedCryptoCurrency
|
||||
import com.tangem.domain.managetokens.repository.CustomTokensRepository
|
||||
|
|
@ -32,7 +32,7 @@ import kotlinx.coroutines.withContext
|
|||
@Suppress("LongParameterList")
|
||||
internal class DefaultCustomTokensRepository(
|
||||
private val tangemTechApi: TangemTechApi,
|
||||
private val userWalletsStore: UserWalletsStore,
|
||||
private val userWalletsListRepository: UserWalletsListRepository,
|
||||
private val userTokensResponseStore: UserTokensResponseStore,
|
||||
private val walletManagersFacade: WalletManagersFacade,
|
||||
private val excludedBlockchains: ExcludedBlockchains,
|
||||
|
|
@ -96,9 +96,8 @@ internal class DefaultCustomTokensRepository(
|
|||
networkId: Network.ID,
|
||||
derivationPath: Network.DerivationPath,
|
||||
): CryptoCurrency.Token? = withContext(dispatchers.io) {
|
||||
val userWallet = requireNotNull(userWalletsStore.getSyncOrNull(userWalletId)) {
|
||||
"User wallet [$userWalletId] not found while finding token"
|
||||
}
|
||||
val userWallet = userWalletsListRepository.getSyncStrict(userWalletId)
|
||||
|
||||
val network = requireNotNull(
|
||||
networkFactory.create(
|
||||
networkId = networkId,
|
||||
|
|
@ -138,7 +137,7 @@ internal class DefaultCustomTokensRepository(
|
|||
rawId = CryptoCurrency.RawID(coin.id),
|
||||
name = coin.name,
|
||||
symbol = coin.symbol,
|
||||
decimals = coinNetwork.decimalCount!!.toInt(),
|
||||
decimals = requireNotNull(coinNetwork.decimalCount).toInt(),
|
||||
contractAddress = tokenAddress,
|
||||
)
|
||||
} else {
|
||||
|
|
@ -152,9 +151,7 @@ internal class DefaultCustomTokensRepository(
|
|||
networkId: Network.ID,
|
||||
derivationPath: Network.DerivationPath,
|
||||
): CryptoCurrency.Coin {
|
||||
val userWallet = requireNotNull(userWalletsStore.getSyncOrNull(userWalletId)) {
|
||||
"User wallet [$userWalletId] not found while creating coin"
|
||||
}
|
||||
val userWallet = userWalletsListRepository.getSyncStrict(userWalletId)
|
||||
val network = requireNotNull(
|
||||
networkFactory.create(
|
||||
networkId = networkId,
|
||||
|
|
@ -189,9 +186,7 @@ internal class DefaultCustomTokensRepository(
|
|||
derivationPath: Network.DerivationPath,
|
||||
formValues: AddCustomTokenForm.Validated.All,
|
||||
): CryptoCurrency.Token {
|
||||
val userWallet = requireNotNull(userWalletsStore.getSyncOrNull(userWalletId)) {
|
||||
"User wallet [$userWalletId] not found while creating custom token"
|
||||
}
|
||||
val userWallet = userWalletsListRepository.getSyncStrict(userWalletId)
|
||||
val network = requireNotNull(
|
||||
networkFactory.create(
|
||||
networkId = networkId,
|
||||
|
|
@ -217,6 +212,7 @@ internal class DefaultCustomTokensRepository(
|
|||
)
|
||||
}
|
||||
|
||||
@Deprecated("Use ManageCryptoCurrenciesUseCase")
|
||||
override suspend fun removeCurrency(userWalletId: UserWalletId, currency: ManagedCryptoCurrency.Custom) =
|
||||
withContext(dispatchers.io) {
|
||||
val cryptoCurrency = when (currency) {
|
||||
|
|
@ -273,20 +269,15 @@ internal class DefaultCustomTokensRepository(
|
|||
}
|
||||
|
||||
override suspend fun getSupportedNetworks(userWalletId: UserWalletId): List<Network> = withContext(dispatchers.io) {
|
||||
val userWallet = requireNotNull(userWalletsStore.getSyncOrNull(userWalletId)) {
|
||||
"User wallet [$userWalletId] not found while getting supported networks"
|
||||
}
|
||||
|
||||
when (userWallet) {
|
||||
when (val userWallet = userWalletsListRepository.getSyncStrict(userWalletId)) {
|
||||
is UserWallet.Hot -> {
|
||||
Blockchain.entries.mapNotNull {
|
||||
// TODO: refactor [REDACTED_JIRA]\
|
||||
if (it.isTestnet() || it in excludedBlockchains || it in hotWalletExcludedBlockchains) {
|
||||
return@mapNotNull null
|
||||
}
|
||||
Blockchain.entries.mapNotNull { blockchain ->
|
||||
// TODO: refactor [REDACTED_JIRA]
|
||||
val isExcluded = blockchain in excludedBlockchains || blockchain in hotWalletExcludedBlockchains
|
||||
if (blockchain.isTestnet() || isExcluded) return@mapNotNull null
|
||||
|
||||
networkFactory.create(
|
||||
blockchain = it,
|
||||
blockchain = blockchain,
|
||||
extraDerivationPath = null,
|
||||
userWallet = userWallet,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@ import com.tangem.datasource.api.tangemTech.models.UserTokensResponse
|
|||
import com.tangem.datasource.api.tangemTech.models.orDefault
|
||||
import com.tangem.datasource.local.config.testnet.TestnetTokensStorage
|
||||
import com.tangem.datasource.local.token.UserTokensResponseStore
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
|
||||
import com.tangem.domain.card.common.TapWorkarounds.isTestCard
|
||||
import com.tangem.domain.card.common.extensions.*
|
||||
import com.tangem.domain.card.common.util.cardTypesResolver
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.managetokens.model.*
|
||||
import com.tangem.domain.managetokens.model.ManagedCryptoCurrency.SourceNetwork
|
||||
import com.tangem.domain.managetokens.repository.ManageTokensRepository
|
||||
|
|
@ -46,7 +46,7 @@ import com.tangem.utils.coroutines.runSuspendCatching
|
|||
@Suppress("LongParameterList", "LargeClass")
|
||||
internal class DefaultManageTokensRepository(
|
||||
private val tangemTechApi: TangemTechApi,
|
||||
private val userWalletsStore: UserWalletsStore,
|
||||
private val userWalletsListRepository: UserWalletsListRepository,
|
||||
private val userTokenSaver: UserTokensSaver,
|
||||
private val manageTokensUpdateFetcher: ManageTokensUpdateFetcher,
|
||||
private val userTokensResponseStore: UserTokensResponseStore,
|
||||
|
|
@ -88,7 +88,7 @@ internal class DefaultManageTokensRepository(
|
|||
prefetchDistance = batchSize,
|
||||
batchSize = batchSize,
|
||||
subFetcher = { request, _, isFirstBatchFetching ->
|
||||
val userWallet = request.params.userWalletId?.let(userWalletsStore::getSyncStrict)
|
||||
val userWallet = request.params.userWalletId?.let(userWalletsListRepository::getSyncStrict)
|
||||
|
||||
if (userWallet is UserWallet.Cold && userWallet.scanResponse.card.isTestCard) {
|
||||
when (val params = request.params) {
|
||||
|
|
@ -438,7 +438,7 @@ internal class DefaultManageTokensRepository(
|
|||
userWalletId: UserWalletId,
|
||||
sourceNetwork: SourceNetwork,
|
||||
): CurrencyUnsupportedState? {
|
||||
val userWallet = userWalletsStore.getSyncStrict(key = userWalletId)
|
||||
val userWallet = userWalletsListRepository.getSyncStrict(id = userWalletId)
|
||||
val blockchain = sourceNetwork.id.toBlockchain()
|
||||
|
||||
return when (sourceNetwork) {
|
||||
|
|
@ -452,7 +452,7 @@ internal class DefaultManageTokensRepository(
|
|||
rawNetworkId: String,
|
||||
isMainNetwork: Boolean,
|
||||
): CurrencyUnsupportedState? {
|
||||
val userWallet = userWalletsStore.getSyncStrict(key = userWalletId)
|
||||
val userWallet = userWalletsListRepository.getSyncStrict(id = userWalletId)
|
||||
val blockchain = Blockchain.fromNetworkId(networkId = rawNetworkId)
|
||||
?: error("Can not create blockchain with given networkId -> $rawNetworkId")
|
||||
return if (isMainNetwork) {
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import com.tangem.data.managetokens.utils.ManageTokensUpdateFetcher
|
|||
import com.tangem.datasource.api.tangemTech.TangemTechApi
|
||||
import com.tangem.datasource.local.config.testnet.TestnetTokensStorage
|
||||
import com.tangem.datasource.local.token.UserTokensResponseStore
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.managetokens.repository.CustomTokensRepository
|
||||
import com.tangem.domain.managetokens.repository.ManageTokensRepository
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
|
|
@ -31,7 +31,7 @@ internal object ManageTokensDataModule {
|
|||
@Singleton
|
||||
fun provideManageTokensRepository(
|
||||
tangemTechApi: TangemTechApi,
|
||||
userWalletsStore: UserWalletsStore,
|
||||
userWalletsListRepository: UserWalletsListRepository,
|
||||
manageTokensUpdateFetcher: ManageTokensUpdateFetcher,
|
||||
userTokensResponseStore: UserTokensResponseStore,
|
||||
userTokensSaver: UserTokensSaver,
|
||||
|
|
@ -45,7 +45,7 @@ internal object ManageTokensDataModule {
|
|||
): ManageTokensRepository {
|
||||
return DefaultManageTokensRepository(
|
||||
tangemTechApi = tangemTechApi,
|
||||
userWalletsStore = userWalletsStore,
|
||||
userWalletsListRepository = userWalletsListRepository,
|
||||
manageTokensUpdateFetcher = manageTokensUpdateFetcher,
|
||||
userTokensResponseStore = userTokensResponseStore,
|
||||
userTokenSaver = userTokensSaver,
|
||||
|
|
@ -63,7 +63,7 @@ internal object ManageTokensDataModule {
|
|||
@Singleton
|
||||
fun provideCustomTokensRepository(
|
||||
tangemTechApi: TangemTechApi,
|
||||
userWalletsStore: UserWalletsStore,
|
||||
userWalletsListRepository: UserWalletsListRepository,
|
||||
userTokensResponseStore: UserTokensResponseStore,
|
||||
walletManagersFacade: WalletManagersFacade,
|
||||
dispatchers: CoroutineDispatcherProvider,
|
||||
|
|
@ -73,7 +73,7 @@ internal object ManageTokensDataModule {
|
|||
): CustomTokensRepository {
|
||||
return DefaultCustomTokensRepository(
|
||||
tangemTechApi = tangemTechApi,
|
||||
userWalletsStore = userWalletsStore,
|
||||
userWalletsListRepository = userWalletsListRepository,
|
||||
userTokensResponseStore = userTokensResponseStore,
|
||||
walletManagersFacade = walletManagersFacade,
|
||||
excludedBlockchains = excludedBlockchains,
|
||||
|
|
|
|||
|
|
@ -51,9 +51,9 @@ internal class ManageTokensUpdateFetcher @Inject constructor() :
|
|||
|
||||
update {
|
||||
BatchUpdateResult.Success(
|
||||
data = mapNotNull {
|
||||
if (it.key == toUpdate[index].key) {
|
||||
Batch(it.key, updatedItems)
|
||||
data = mapNotNull { batch ->
|
||||
if (batch.key == toUpdate[index].key) {
|
||||
Batch(batch.key, updatedItems)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue