Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-01 16:44:47 +03:00
parent 614df6d9e4
commit 186f8f77c4
5 changed files with 23 additions and 6 deletions

View file

@ -32,6 +32,7 @@ dependencies {
implementation(deps.arrow.core)
implementation(deps.jodatime)
implementation(deps.timber)
implementation(deps.tangem.card.core)
/** DI */
implementation(deps.hilt.android)

View file

@ -1,10 +1,12 @@
package com.tangem.feature.referral.domain
import arrow.core.getOrElse
import com.tangem.common.core.TangemSdkError
import com.tangem.domain.card.DerivePublicKeysUseCase
import com.tangem.domain.tokens.AddCryptoCurrenciesUseCase
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
import com.tangem.feature.referral.domain.errors.ReferralError
import com.tangem.feature.referral.domain.models.ReferralData
import com.tangem.feature.referral.domain.models.TokenData
import com.tangem.lib.crypto.UserWalletManager
@ -42,7 +44,7 @@ internal class ReferralInteractorImpl(
val cryptoCurrency = repository.getCryptoCurrency(userWalletId = userWallet.walletId, tokenData = tokenData)
derivePublicKeysUseCase(userWallet.walletId, listOfNotNull(cryptoCurrency)).getOrElse {
Timber.e("Failed to derive public keys: $it")
throw it
throw it.mapToDomainError()
}
addCryptoCurrenciesUseCase(
@ -67,4 +69,13 @@ internal class ReferralInteractorImpl(
tokensForReferral.clear()
tokensForReferral.addAll(tokens)
}
private fun Throwable.mapToDomainError(): ReferralError {
if (this !is TangemSdkError) return ReferralError.DataError(this)
return if (this is TangemSdkError.UserCancelled) {
ReferralError.UserCancelledException
} else {
ReferralError.SdkError
}
}
}

View file

@ -0,0 +1,8 @@
package com.tangem.feature.referral.domain.errors
sealed class ReferralError : Exception() {
data object UserCancelledException : ReferralError()
data object SdkError : ReferralError()
data class DataError(val throwable: Throwable) : ReferralError()
}

View file

@ -13,6 +13,7 @@ import com.tangem.core.analytics.api.AnalyticsEventHandler
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.feature.referral.analytics.ReferralEvents
import com.tangem.feature.referral.domain.ReferralInteractor
import com.tangem.feature.referral.domain.errors.ReferralError
import com.tangem.feature.referral.domain.models.DiscountType
import com.tangem.feature.referral.domain.models.ReferralData
import com.tangem.feature.referral.domain.models.ReferralInfo
@ -21,7 +22,6 @@ import com.tangem.feature.referral.models.ReferralStateHolder
import com.tangem.feature.referral.models.ReferralStateHolder.ErrorSnackbar
import com.tangem.feature.referral.models.ReferralStateHolder.ReferralInfoState
import com.tangem.feature.referral.router.ReferralRouter
import com.tangem.lib.crypto.models.errors.UserCancelledException
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import com.tangem.utils.coroutines.runCatching
import dagger.hilt.android.lifecycle.HiltViewModel
@ -95,7 +95,7 @@ internal class ReferralViewModel @Inject constructor(
runCatching(dispatchers.io) { referralInteractor.startReferral(userWalletId) }
.onSuccess(::showContent)
.onFailure { throwable ->
if (throwable is UserCancelledException) {
if (throwable is ReferralError.UserCancelledException) {
lastReferralData?.let { referralData ->
showContent(referralData)
}

View file

@ -1,3 +0,0 @@
package com.tangem.lib.crypto.models.errors
class UserCancelledException : Exception()