Updated on 2026-08-14

This commit is contained in:
Tangem 2026-07-02 10:37:01 +05:00
parent adb8c50ae2
commit dd95bf238a
7 changed files with 189 additions and 0 deletions

View file

@ -0,0 +1,37 @@
package com.tangem.domain.managetokens
import arrow.core.Either
import arrow.core.left
import arrow.core.right
import com.tangem.domain.managetokens.repository.CustomTokensRepository
import com.tangem.domain.models.network.Network
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.utils.coroutines.runSuspendCatching
/**
* Checks whether the elliptic curve used by [networkId] for the [userWalletId] wallet supports the selected
* [derivationPath]. Used before adding a custom token to prevent adding a token with a derivation path that the
* network's curve cannot derive (e.g. an Algorand token with an EVM derivation path).
*
* Returns [Either.Right] with `true` when the derivation is supported, `false` otherwise. [Either.Left] is returned
* when the check itself fails unexpectedly.
*/
class CheckDerivationPathSupportedUseCase(
private val customTokensRepository: CustomTokensRepository,
) {
suspend operator fun invoke(
userWalletId: UserWalletId,
networkId: Network.ID,
derivationPath: Network.DerivationPath,
): Either<Throwable, Boolean> = runSuspendCatching {
customTokensRepository.isDerivationPathSupported(
userWalletId = userWalletId,
networkId = networkId,
derivationPath = derivationPath,
)
}.fold(
onSuccess = { it.right() },
onFailure = { it.left() },
)
}

View file

@ -43,5 +43,11 @@ interface CustomTokensRepository {
suspend fun getSupportedNetworks(userWalletId: UserWalletId): List<Network>
suspend fun isDerivationPathSupported(
userWalletId: UserWalletId,
networkId: Network.ID,
derivationPath: Network.DerivationPath,
): Boolean
fun createDerivationPath(rawPath: String): Network.DerivationPath
}