Updated on 2026-08-14
This commit is contained in:
parent
e381fafeb8
commit
7cb4b57fe9
21 changed files with 556 additions and 230 deletions
|
|
@ -25,6 +25,7 @@ dependencies {
|
|||
implementation(projects.domain.models)
|
||||
implementation(projects.domain.tokens.models)
|
||||
implementation(projects.domain.wallets.models)
|
||||
implementation(projects.domain.referral)
|
||||
implementation(projects.features.referral.domain)
|
||||
|
||||
/** Libs */
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" ?>
|
||||
<SmellBaseline>
|
||||
<ManuallySuppressedIssues/>
|
||||
<CurrentIssues>
|
||||
<ID>MultilineLambdaItParameter:ReferralConverter.kt$ExpectedAwardsConverter${ ExpectedAward( paymentDate = it.paymentDate.toDateTimeAtStartOfDay().millis.toDateFormat(), amount = "${it.amount} ${it.currency}", ) }</ID>
|
||||
</CurrentIssues>
|
||||
</SmellBaseline>
|
||||
|
|
@ -70,10 +70,10 @@ private class ExpectedAwardsConverter : Converter<ReferralResponse.ExpectedAward
|
|||
override fun convert(value: ReferralResponse.ExpectedAwards): ExpectedAwards {
|
||||
return ExpectedAwards(
|
||||
numberOfWallets = value.numberOfWallets,
|
||||
expectedAwards = value.list.map {
|
||||
expectedAwards = value.list.map { awardItem ->
|
||||
ExpectedAward(
|
||||
paymentDate = it.paymentDate.toDateTimeAtStartOfDay().millis.toDateFormat(),
|
||||
amount = "${it.amount} ${it.currency}",
|
||||
paymentDate = awardItem.paymentDate.toDateTimeAtStartOfDay().millis.toDateFormat(),
|
||||
amount = "${awardItem.amount} ${awardItem.currency}",
|
||||
)
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.tangem.datasource.local.userwallet.UserWalletsStore
|
|||
import com.tangem.domain.models.account.DerivationIndex
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.referral.ReferralStatus
|
||||
import com.tangem.feature.referral.converters.ReferralConverter
|
||||
import com.tangem.feature.referral.domain.ReferralRepository
|
||||
import com.tangem.feature.referral.domain.models.ReferralData
|
||||
|
|
@ -21,13 +22,15 @@ import kotlinx.coroutines.withContext
|
|||
import java.util.concurrent.ConcurrentHashMap
|
||||
import javax.inject.Inject
|
||||
|
||||
typealias ExternalReferralRepository = com.tangem.domain.referral.ReferralRepository
|
||||
|
||||
internal class ReferralRepositoryImpl @Inject constructor(
|
||||
private val referralApi: TangemTechApi,
|
||||
private val referralConverter: ReferralConverter,
|
||||
private val coroutineDispatcher: CoroutineDispatcherProvider,
|
||||
private val userWalletsStore: UserWalletsStore,
|
||||
excludedBlockchains: ExcludedBlockchains,
|
||||
) : ReferralRepository {
|
||||
) : ReferralRepository, ExternalReferralRepository {
|
||||
|
||||
private val cryptoCurrencyFactory = CryptoCurrencyFactory(excludedBlockchains)
|
||||
|
||||
|
|
@ -47,6 +50,21 @@ internal class ReferralRepositoryImpl @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun getReferralStatus(userWalletId: String): ReferralStatus {
|
||||
val data = getReferralData(userWalletId)
|
||||
|
||||
return ReferralStatus(
|
||||
isActive = data is ReferralData.ParticipantData,
|
||||
token = data.tokens.firstOrNull()?.let { tokenData ->
|
||||
ReferralStatus.Token(
|
||||
networkId = tokenData.networkId,
|
||||
contractAddress = tokenData.contractAddress,
|
||||
)
|
||||
},
|
||||
address = (data as? ReferralData.ParticipantData)?.referral?.address,
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun isReferralParticipant(userWalletId: UserWalletId): Boolean {
|
||||
val storedReferralData = referralStatus[userWalletId.stringValue] ?: getReferralData(userWalletId.stringValue)
|
||||
return storedReferralData is ReferralData.ParticipantData
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.tangem.blockchainsdk.utils.ExcludedBlockchains
|
|||
import com.tangem.datasource.api.tangemTech.TangemTechApi
|
||||
import com.tangem.datasource.local.userwallet.UserWalletsStore
|
||||
import com.tangem.feature.referral.converters.ReferralConverter
|
||||
import com.tangem.feature.referral.data.ExternalReferralRepository
|
||||
import com.tangem.feature.referral.data.ReferralRepositoryImpl
|
||||
import com.tangem.feature.referral.domain.ReferralRepository
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
|
|
@ -34,4 +35,22 @@ class ReferralRepositoryModule {
|
|||
excludedBlockchains = excludedBlockchains,
|
||||
)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideExternalReferralRepository(
|
||||
tangemTechApi: TangemTechApi,
|
||||
referralConverter: ReferralConverter,
|
||||
coroutineDispatcherProvider: CoroutineDispatcherProvider,
|
||||
userWalletsStore: UserWalletsStore,
|
||||
excludedBlockchains: ExcludedBlockchains,
|
||||
): ExternalReferralRepository {
|
||||
return ReferralRepositoryImpl(
|
||||
referralApi = tangemTechApi,
|
||||
referralConverter = referralConverter,
|
||||
coroutineDispatcher = coroutineDispatcherProvider,
|
||||
userWalletsStore = userWalletsStore,
|
||||
excludedBlockchains = excludedBlockchains,
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue