diff --git a/domain/account/status/src/main/java/com/tangem/domain/account/status/usecase/ManageCryptoCurrenciesUseCase.kt b/domain/account/status/src/main/java/com/tangem/domain/account/status/usecase/ManageCryptoCurrenciesUseCase.kt index d41defe9be..2bef64e9b1 100644 --- a/domain/account/status/src/main/java/com/tangem/domain/account/status/usecase/ManageCryptoCurrenciesUseCase.kt +++ b/domain/account/status/src/main/java/com/tangem/domain/account/status/usecase/ManageCryptoCurrenciesUseCase.kt @@ -59,14 +59,21 @@ class ManageCryptoCurrenciesUseCase( accountId: AccountId, add: CryptoCurrency? = null, remove: CryptoCurrency? = null, + skipDerivationErrors: Boolean = true, ): Either { - return invoke(accountId = accountId, add = listOfNotNull(add), remove = listOfNotNull(remove)) + return invoke( + accountId = accountId, + add = listOfNotNull(add), + remove = listOfNotNull(remove), + skipDerivationErrors = skipDerivationErrors, + ) } suspend operator fun invoke( accountId: AccountId, add: List = emptyList(), remove: List = emptyList(), + skipDerivationErrors: Boolean = true, ): Either = eitherOn(dispatchers.default) { if (add.isEmpty() && remove.isEmpty()) { Timber.d("No currencies to add or remove, skipping") @@ -89,7 +96,7 @@ class ManageCryptoCurrenciesUseCase( account = accountStatus.account.copy(cryptoCurrencies = modifiedCurrencyList.total), ) - derivePublicKeys(userWalletId = userWalletId, currencies = modifiedCurrencyList.added) + val result = derivePublicKeys(userWalletId = userWalletId, currencies = modifiedCurrencyList.added) parallelUpdatingScope.launch { syncTokens(userWalletId, modifiedCurrencyList) @@ -98,6 +105,10 @@ class ManageCryptoCurrenciesUseCase( refreshExpress(userWalletId = userWalletId, currencies = modifiedCurrencyList.total) clearMetadata(userWalletId = userWalletId, currencies = modifiedCurrencyList.removed) } + + if (!skipDerivationErrors) { + result.bind() + } } } diff --git a/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/ReferralInteractorImpl.kt b/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/ReferralInteractorImpl.kt index cfbdeea741..930418c920 100644 --- a/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/ReferralInteractorImpl.kt +++ b/features/referral/domain/src/main/java/com/tangem/feature/referral/domain/ReferralInteractorImpl.kt @@ -73,7 +73,17 @@ internal class ReferralInteractorImpl( when (portfolioId) { is PortfolioId.Account -> { - manageCryptoCurrenciesUseCase(accountId = portfolioId.accountId, add = cryptoCurrency) + manageCryptoCurrenciesUseCase( + accountId = portfolioId.accountId, + add = cryptoCurrency, + skipDerivationErrors = false, + ).mapLeft { + it.mapToDomainError() + }.onLeft { error -> + if (error is ReferralError.UserCancelledException) { + throw error + } + } } is PortfolioId.Wallet -> { derivePublicKeysUseCase(userWallet.walletId, listOf(cryptoCurrency)).getOrElse { throwable ->