Updated on 2026-08-14

This commit is contained in:
Tangem 2026-02-03 11:12:10 +04:00
parent 42b4c894bb
commit bec5334529
2 changed files with 25 additions and 26 deletions

View file

@ -55,7 +55,8 @@ internal class CustomTokenFormModel @Inject constructor(
private val params: CustomTokenFormComponent.Params = paramsContainer.require() private val params: CustomTokenFormComponent.Params = paramsContainer.require()
private var createdCurrency: CryptoCurrency? = null private var createdCurrency: CryptoCurrency? = null
private var useCasesFacade: CustomTokenFormUseCasesFacade = customTokenFormUseCasesFacadeFactory.create(params.mode) private val useCasesFacade: CustomTokenFormUseCasesFacade =
customTokenFormUseCasesFacadeFactory.create(params.mode.userWalletId)
private val customCurrencyValidator = CustomCurrencyValidator( private val customCurrencyValidator = CustomCurrencyValidator(
userWalletId = params.mode.userWalletId, userWalletId = params.mode.userWalletId,
useCasesFacade = useCasesFacade, useCasesFacade = useCasesFacade,

View file

@ -18,9 +18,9 @@ import com.tangem.domain.models.account.AccountId
import com.tangem.domain.models.account.DerivationIndex import com.tangem.domain.models.account.DerivationIndex
import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.network.Network import com.tangem.domain.models.network.Network
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.tokens.AddCryptoCurrenciesUseCase import com.tangem.domain.tokens.AddCryptoCurrenciesUseCase
import com.tangem.domain.wallets.usecase.DerivePublicKeysUseCase import com.tangem.domain.wallets.usecase.DerivePublicKeysUseCase
import com.tangem.features.managetokens.component.AddCustomTokenMode
import com.tangem.lib.crypto.derivation.AccountNodeRecognizer import com.tangem.lib.crypto.derivation.AccountNodeRecognizer
import dagger.assisted.Assisted import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory import dagger.assisted.AssistedFactory
@ -29,7 +29,7 @@ import timber.log.Timber
@Suppress("LongParameterList") @Suppress("LongParameterList")
internal class CustomTokenFormUseCasesFacade @AssistedInject constructor( internal class CustomTokenFormUseCasesFacade @AssistedInject constructor(
@Assisted private val mode: AddCustomTokenMode, @Assisted private val userWalletId: UserWalletId,
private val addCryptoCurrenciesUseCase: AddCryptoCurrenciesUseCase, private val addCryptoCurrenciesUseCase: AddCryptoCurrenciesUseCase,
private val derivePublicKeysUseCase: DerivePublicKeysUseCase, private val derivePublicKeysUseCase: DerivePublicKeysUseCase,
private val checkIsCurrencyNotAddedUseCase: CheckIsCurrencyNotAddedUseCase, private val checkIsCurrencyNotAddedUseCase: CheckIsCurrencyNotAddedUseCase,
@ -39,26 +39,24 @@ internal class CustomTokenFormUseCasesFacade @AssistedInject constructor(
private val accountsFeatureToggles: AccountsFeatureToggles, private val accountsFeatureToggles: AccountsFeatureToggles,
) { ) {
suspend fun addCryptoCurrenciesUseCase(currency: CryptoCurrency): Either<Throwable, Unit> = when (mode) { suspend fun addCryptoCurrenciesUseCase(currency: CryptoCurrency): Either<Throwable, Unit> {
is AddCustomTokenMode.Account -> either { return if (accountsFeatureToggles.isFeatureEnabled) {
val accountId = getAccountId(currency) either {
val accountId = getAccountId(currency)
manageCryptoCurrenciesUseCase(accountId = accountId, add = currency).bind() manageCryptoCurrenciesUseCase(accountId = accountId, add = currency).bind()
} }
is AddCustomTokenMode.Wallet -> { } else {
addCryptoCurrenciesUseCase.invoke( addCryptoCurrenciesUseCase.invoke(userWalletId = userWalletId, currency = currency)
userWalletId = mode.userWalletId,
currency = currency,
)
} }
} }
suspend fun derivePublicKeysUseCase(currencies: List<CryptoCurrency>): Either<Throwable, Unit> = when (mode) { suspend fun derivePublicKeysUseCase(currencies: List<CryptoCurrency>): Either<Throwable, Unit> {
is AddCustomTokenMode.Account -> Unit.right() return if (accountsFeatureToggles.isFeatureEnabled) {
is AddCustomTokenMode.Wallet -> derivePublicKeysUseCase.invoke( Unit.right()
userWalletId = mode.userWalletId, } else {
currencies = currencies, derivePublicKeysUseCase.invoke(userWalletId = userWalletId, currencies = currencies)
) }
} }
suspend fun checkIsCurrencyNotAddedUseCase( suspend fun checkIsCurrencyNotAddedUseCase(
@ -67,7 +65,7 @@ internal class CustomTokenFormUseCasesFacade @AssistedInject constructor(
contractAddress: String?, contractAddress: String?,
): Either<Throwable, Boolean> = if (accountsFeatureToggles.isFeatureEnabled) { ): Either<Throwable, Boolean> = if (accountsFeatureToggles.isFeatureEnabled) {
getAccountCurrencyStatusUseCase.invokeSync( getAccountCurrencyStatusUseCase.invokeSync(
userWalletId = mode.userWalletId, userWalletId = userWalletId,
networkId = networkId, networkId = networkId,
derivationPath = derivationPath, derivationPath = derivationPath,
contractAddress = contractAddress, contractAddress = contractAddress,
@ -76,7 +74,7 @@ internal class CustomTokenFormUseCasesFacade @AssistedInject constructor(
.right() .right()
} else { } else {
checkIsCurrencyNotAddedUseCase.invoke( checkIsCurrencyNotAddedUseCase.invoke(
userWalletId = mode.userWalletId, userWalletId = userWalletId,
networkId = networkId, networkId = networkId,
derivationPath = derivationPath, derivationPath = derivationPath,
contractAddress = contractAddress, contractAddress = contractAddress,
@ -85,15 +83,15 @@ internal class CustomTokenFormUseCasesFacade @AssistedInject constructor(
private suspend fun Raise<Throwable>.getAccountId(currency: CryptoCurrency): AccountId { private suspend fun Raise<Throwable>.getAccountId(currency: CryptoCurrency): AccountId {
val accountList = singleAccountListSupplier.getSyncOrNull( val accountList = singleAccountListSupplier.getSyncOrNull(
params = SingleAccountListProducer.Params(userWalletId = mode.userWalletId), params = SingleAccountListProducer.Params(userWalletId = userWalletId),
) )
ensureNotNull(accountList) { ensureNotNull(accountList) {
IllegalStateException("Account list not found: ${mode.userWalletId}") IllegalStateException("Account list not found: $userWalletId")
} }
if (accountList.activeAccounts == 1) { if (accountList.activeAccounts == 1) {
return AccountId.forMainCryptoPortfolio(userWalletId = mode.userWalletId) return AccountId.forMainCryptoPortfolio(userWalletId = userWalletId)
} }
val currencyAccountIndex = currency.getAccountIndex().bind() val currencyAccountIndex = currency.getAccountIndex().bind()
@ -104,7 +102,7 @@ internal class CustomTokenFormUseCasesFacade @AssistedInject constructor(
cryptoPortfolioAccount?.derivationIndex?.value == currencyAccountIndex cryptoPortfolioAccount?.derivationIndex?.value == currencyAccountIndex
} }
return account?.accountId ?: AccountId.forMainCryptoPortfolio(userWalletId = mode.userWalletId) return account?.accountId ?: AccountId.forMainCryptoPortfolio(userWalletId = userWalletId)
} }
private fun CryptoCurrency.getAccountIndex(): Either<Throwable, Int> = either { private fun CryptoCurrency.getAccountIndex(): Either<Throwable, Int> = either {
@ -140,6 +138,6 @@ internal class CustomTokenFormUseCasesFacade @AssistedInject constructor(
@AssistedFactory @AssistedFactory
interface Factory { interface Factory {
fun create(mode: AddCustomTokenMode): CustomTokenFormUseCasesFacade fun create(userWalletId: UserWalletId): CustomTokenFormUseCasesFacade
} }
} }