Updated on 2026-08-14
This commit is contained in:
parent
48f8d2aaaa
commit
d2f28313e9
1 changed files with 23 additions and 16 deletions
|
|
@ -7,6 +7,7 @@ import arrow.core.raise.ensureNotNull
|
||||||
import arrow.core.right
|
import arrow.core.right
|
||||||
import com.tangem.blockchain.common.Blockchain
|
import com.tangem.blockchain.common.Blockchain
|
||||||
import com.tangem.blockchainsdk.utils.fromNetworkId
|
import com.tangem.blockchainsdk.utils.fromNetworkId
|
||||||
|
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
|
||||||
import com.tangem.domain.account.producer.SingleAccountListProducer
|
import com.tangem.domain.account.producer.SingleAccountListProducer
|
||||||
import com.tangem.domain.account.status.usecase.GetAccountCurrencyStatusUseCase
|
import com.tangem.domain.account.status.usecase.GetAccountCurrencyStatusUseCase
|
||||||
import com.tangem.domain.account.status.usecase.ManageCryptoCurrenciesUseCase
|
import com.tangem.domain.account.status.usecase.ManageCryptoCurrenciesUseCase
|
||||||
|
|
@ -14,6 +15,7 @@ import com.tangem.domain.account.supplier.SingleAccountListSupplier
|
||||||
import com.tangem.domain.managetokens.CheckIsCurrencyNotAddedUseCase
|
import com.tangem.domain.managetokens.CheckIsCurrencyNotAddedUseCase
|
||||||
import com.tangem.domain.models.account.Account
|
import com.tangem.domain.models.account.Account
|
||||||
import com.tangem.domain.models.account.AccountId
|
import com.tangem.domain.models.account.AccountId
|
||||||
|
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.tokens.AddCryptoCurrenciesUseCase
|
import com.tangem.domain.tokens.AddCryptoCurrenciesUseCase
|
||||||
|
|
@ -34,6 +36,7 @@ internal class CustomTokenFormUseCasesFacade @AssistedInject constructor(
|
||||||
private val manageCryptoCurrenciesUseCase: ManageCryptoCurrenciesUseCase,
|
private val manageCryptoCurrenciesUseCase: ManageCryptoCurrenciesUseCase,
|
||||||
private val singleAccountListSupplier: SingleAccountListSupplier,
|
private val singleAccountListSupplier: SingleAccountListSupplier,
|
||||||
private val getAccountCurrencyStatusUseCase: GetAccountCurrencyStatusUseCase,
|
private val getAccountCurrencyStatusUseCase: GetAccountCurrencyStatusUseCase,
|
||||||
|
private val accountsFeatureToggles: AccountsFeatureToggles,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun addCryptoCurrenciesUseCase(currency: CryptoCurrency): Either<Throwable, Unit> = when (mode) {
|
suspend fun addCryptoCurrenciesUseCase(currency: CryptoCurrency): Either<Throwable, Unit> = when (mode) {
|
||||||
|
|
@ -62,18 +65,17 @@ internal class CustomTokenFormUseCasesFacade @AssistedInject constructor(
|
||||||
networkId: Network.ID,
|
networkId: Network.ID,
|
||||||
derivationPath: Network.DerivationPath,
|
derivationPath: Network.DerivationPath,
|
||||||
contractAddress: String?,
|
contractAddress: String?,
|
||||||
): Either<Throwable, Boolean> = when (mode) {
|
): Either<Throwable, Boolean> = if (accountsFeatureToggles.isFeatureEnabled) {
|
||||||
is AddCustomTokenMode.Account -> {
|
getAccountCurrencyStatusUseCase.invokeSync(
|
||||||
getAccountCurrencyStatusUseCase.invokeSync(
|
userWalletId = mode.userWalletId,
|
||||||
userWalletId = mode.accountId.userWalletId,
|
networkId = networkId,
|
||||||
networkId = networkId,
|
derivationPath = derivationPath,
|
||||||
derivationPath = derivationPath,
|
contractAddress = contractAddress,
|
||||||
contractAddress = contractAddress,
|
)
|
||||||
)
|
.fold(ifEmpty = { true }, ifSome = { false })
|
||||||
.fold(ifEmpty = { true }, ifSome = { false })
|
.right()
|
||||||
.right()
|
} else {
|
||||||
}
|
checkIsCurrencyNotAddedUseCase.invoke(
|
||||||
is AddCustomTokenMode.Wallet -> checkIsCurrencyNotAddedUseCase.invoke(
|
|
||||||
userWalletId = mode.userWalletId,
|
userWalletId = mode.userWalletId,
|
||||||
networkId = networkId,
|
networkId = networkId,
|
||||||
derivationPath = derivationPath,
|
derivationPath = derivationPath,
|
||||||
|
|
@ -124,10 +126,15 @@ internal class CustomTokenFormUseCasesFacade @AssistedInject constructor(
|
||||||
val accountNodeRecognizer = AccountNodeRecognizer(blockchain)
|
val accountNodeRecognizer = AccountNodeRecognizer(blockchain)
|
||||||
val index = accountNodeRecognizer.recognize(derivationPathValue)?.toInt()
|
val index = accountNodeRecognizer.recognize(derivationPathValue)?.toInt()
|
||||||
|
|
||||||
ensureNotNull(index) {
|
if (index == null) {
|
||||||
val exception = IllegalStateException("Token has unrecognized derivation path: ${currency.id}")
|
Timber.e(
|
||||||
Timber.e(exception)
|
"%s%s",
|
||||||
exception
|
"Unable to determine account index for derivation path: $derivationPathValue. ",
|
||||||
|
"Use main account index instead.",
|
||||||
|
)
|
||||||
|
DerivationIndex.Main.value
|
||||||
|
} else {
|
||||||
|
index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue