Updated on 2026-08-14
This commit is contained in:
parent
2925390cb3
commit
37054e453d
13 changed files with 249 additions and 2 deletions
|
|
@ -9,15 +9,15 @@ import org.joda.time.DateTime
|
|||
*/
|
||||
data class ReferralResponse(
|
||||
@Json(name = "conditions") val conditions: Conditions,
|
||||
@Json(name = "referral") val referral: Referral?,
|
||||
)
|
||||
|
||||
data class Conditions(
|
||||
@Json(name = "conditions") val award: Int,
|
||||
@Json(name = "award") val award: Int,
|
||||
@Json(name = "discount") val discount: Int,
|
||||
@Json(name = "discountType") val discountType: DiscountType,
|
||||
@Json(name = "tosLink") val tosLink: String,
|
||||
@Json(name = "tokens") val tokens: List<Token>,
|
||||
@Json(name = "referral") val referral: Referral,
|
||||
)
|
||||
|
||||
data class Token(
|
||||
|
|
|
|||
1
core/utils/.gitignore
vendored
Normal file
1
core/utils/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/build
|
||||
35
core/utils/build.gradle.kts
Normal file
35
core/utils/build.gradle.kts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
plugins {
|
||||
id("com.android.library")
|
||||
kotlin("android")
|
||||
kotlin("kapt")
|
||||
id("com.google.dagger.hilt.android")
|
||||
}
|
||||
|
||||
android {
|
||||
|
||||
defaultConfig {
|
||||
compileSdk = AppConfig.compileSdkVersion
|
||||
minSdk = AppConfig.minSdkVersion
|
||||
targetSdk = AppConfig.targetSdkVersion
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
isCoreLibraryDesugaringEnabled = false
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
/** DI */
|
||||
implementation(Library.hilt)
|
||||
kapt(Library.hiltKapt)
|
||||
|
||||
/** Coroutines */
|
||||
implementation(Library.coroutine)
|
||||
}
|
||||
2
core/utils/src/main/AndroidManifest.xml
Normal file
2
core/utils/src/main/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest package="com.tangem.utils" />
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.tangem.utils.converter
|
||||
|
||||
interface Converter<I, O> {
|
||||
fun convert(value: I): O
|
||||
fun convertList(input: List<I>): List<O> {
|
||||
return input.map { convert(it) }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.tangem.utils.coroutines
|
||||
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import javax.inject.Inject
|
||||
|
||||
interface CoroutineDispatcherProvider {
|
||||
val main: CoroutineDispatcher
|
||||
val io: CoroutineDispatcher
|
||||
}
|
||||
|
||||
class AppCoroutineDispatcherProvider @Inject constructor() : CoroutineDispatcherProvider {
|
||||
override val main: CoroutineDispatcher = Dispatchers.Main
|
||||
override val io: CoroutineDispatcher = Dispatchers.IO
|
||||
}
|
||||
|
||||
class TestingCoroutineDispatcherProvider(
|
||||
override val main: CoroutineDispatcher = Dispatchers.Unconfined,
|
||||
override val io: CoroutineDispatcher = Dispatchers.Unconfined,
|
||||
) : CoroutineDispatcherProvider
|
||||
|
|
@ -26,6 +26,14 @@ android {
|
|||
|
||||
dependencies {
|
||||
|
||||
/** Project*/
|
||||
implementation(project(":core:datasource"))
|
||||
implementation(project(":core:utils"))
|
||||
implementation(project(":features:referral:domain"))
|
||||
|
||||
/** Time */
|
||||
implementation(Library.jodatime)
|
||||
|
||||
/** DI */
|
||||
implementation(Library.hilt)
|
||||
kapt(Library.hiltKapt)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
package com.tangem.feature.referral.converters
|
||||
|
||||
import com.tangem.datasource.api.referral.models.ReferralResponse
|
||||
import com.tangem.datasource.api.referral.models.Token
|
||||
import com.tangem.feature.referral.domain.models.DiscountType
|
||||
import com.tangem.feature.referral.domain.models.ReferralData
|
||||
import com.tangem.feature.referral.domain.models.ReferralInfo
|
||||
import com.tangem.feature.referral.domain.models.TokenData
|
||||
import com.tangem.utils.converter.Converter
|
||||
import javax.inject.Inject
|
||||
|
||||
class ReferralConverter @Inject constructor() : Converter<ReferralResponse, ReferralData> {
|
||||
|
||||
override fun convert(value: ReferralResponse): ReferralData {
|
||||
val conditions = value.conditions
|
||||
val referral = value.referral
|
||||
val tokenConverter = TokenConverter()
|
||||
return if (referral != null) {
|
||||
ReferralData.ParticipantData(
|
||||
award = conditions.award,
|
||||
discount = conditions.discount,
|
||||
discountType = DiscountType.valueOf(conditions.discountType.name),
|
||||
tosLink = conditions.tosLink,
|
||||
tokens = tokenConverter.convertList(conditions.tokens),
|
||||
referral = ReferralInfo(
|
||||
shareLink = referral.shareLink,
|
||||
address = referral.address,
|
||||
promocode = referral.promocode,
|
||||
walletsPurchased = referral.walletsPurchased,
|
||||
termsAcceptedAt = referral.termsAcceptedAt,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
ReferralData.NonParticipantData(
|
||||
award = conditions.award,
|
||||
discount = conditions.discount,
|
||||
discountType = DiscountType.valueOf(conditions.discountType.name),
|
||||
tosLink = conditions.tosLink,
|
||||
tokens = tokenConverter.convertList(conditions.tokens),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class TokenConverter : Converter<Token, TokenData> {
|
||||
|
||||
override fun convert(value: Token): TokenData {
|
||||
return TokenData(
|
||||
id = value.id,
|
||||
name = value.name,
|
||||
symbol = value.symbol,
|
||||
networkId = value.networkId,
|
||||
contractAddress = value.contractAddress,
|
||||
decimalCount = value.decimalCount,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.tangem.feature.referral.data
|
||||
|
||||
import com.tangem.datasource.api.referral.ReferralApi
|
||||
import com.tangem.datasource.api.referral.models.StartReferralBody
|
||||
import com.tangem.feature.referral.converters.ReferralConverter
|
||||
import com.tangem.feature.referral.domain.ReferralRepository
|
||||
import com.tangem.feature.referral.domain.models.ReferralData
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.withContext
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class ReferralRepositoryImpl @Inject constructor(
|
||||
private val referralApi: ReferralApi,
|
||||
private val referralConverter: ReferralConverter,
|
||||
private val coroutineDispatcher: CoroutineDispatcherProvider,
|
||||
) : ReferralRepository {
|
||||
|
||||
override suspend fun getReferralStatus(walletId: String): ReferralData {
|
||||
return withContext(coroutineDispatcher.io) {
|
||||
referralConverter.convert(referralApi.getReferralStatus(walletId))
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun startReferral(
|
||||
walletId: String,
|
||||
networkId: String,
|
||||
tokenId: String,
|
||||
address: String,
|
||||
): ReferralData {
|
||||
return withContext(coroutineDispatcher.io) {
|
||||
referralConverter.convert(
|
||||
referralApi.startReferral(
|
||||
StartReferralBody(
|
||||
walletId = walletId,
|
||||
networkId = networkId,
|
||||
tokenId = tokenId,
|
||||
address = address,
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,9 @@ android {
|
|||
|
||||
dependencies {
|
||||
|
||||
/** Time */
|
||||
implementation(Library.jodatime)
|
||||
|
||||
/** DI */
|
||||
implementation(Library.hilt)
|
||||
kapt(Library.hiltKapt)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package com.tangem.feature.referral.domain
|
||||
|
||||
import com.tangem.feature.referral.domain.models.ReferralData
|
||||
|
||||
interface ReferralRepository {
|
||||
|
||||
/** Returns data object of [ReferralData] depends on user program status */
|
||||
suspend fun getReferralStatus(walletId: String): ReferralData
|
||||
|
||||
/** Starts user referral program */
|
||||
suspend fun startReferral(
|
||||
walletId: String,
|
||||
networkId: String,
|
||||
tokenId: String,
|
||||
address: String,
|
||||
): ReferralData
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package com.tangem.feature.referral.domain.models
|
||||
|
||||
import org.joda.time.DateTime
|
||||
|
||||
sealed interface ReferralData {
|
||||
|
||||
val award: Int
|
||||
val discount: Int
|
||||
val discountType: DiscountType
|
||||
val tosLink: String
|
||||
val tokens: List<TokenData>
|
||||
|
||||
/** Data class that used if user is participant of program */
|
||||
data class ParticipantData(
|
||||
override val award: Int,
|
||||
override val discount: Int,
|
||||
override val discountType: DiscountType,
|
||||
override val tosLink: String,
|
||||
override val tokens: List<TokenData>,
|
||||
val referral: ReferralInfo,
|
||||
) : ReferralData
|
||||
|
||||
/** Data class that used if user is not participant of program */
|
||||
data class NonParticipantData(
|
||||
override val award: Int,
|
||||
override val discount: Int,
|
||||
override val discountType: DiscountType,
|
||||
override val tosLink: String,
|
||||
override val tokens: List<TokenData>,
|
||||
) : ReferralData
|
||||
}
|
||||
|
||||
data class TokenData(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val symbol: String,
|
||||
val networkId: String?,
|
||||
val contractAddress: String?,
|
||||
val decimalCount: Int,
|
||||
)
|
||||
|
||||
data class ReferralInfo(
|
||||
val shareLink: String,
|
||||
val address: String,
|
||||
val promocode: String,
|
||||
val walletsPurchased: Int,
|
||||
val termsAcceptedAt: DateTime?,
|
||||
)
|
||||
|
||||
enum class DiscountType {
|
||||
PERCENTAGE, VALUE
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ include(":domain")
|
|||
include(":network")
|
||||
include(":common")
|
||||
include(":core:datasource")
|
||||
include(":core:utils")
|
||||
include(":features:referral:data")
|
||||
include(":features:referral:domain")
|
||||
include(":features:referral:presentation")
|
||||
Loading…
Add table
Add a link
Reference in a new issue