Updated on 2026-08-14
This commit is contained in:
parent
15ee3075f2
commit
7b71962131
6 changed files with 55 additions and 28 deletions
|
|
@ -6,13 +6,17 @@ import com.squareup.moshi.Json
|
|||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
data class PromotionInfoResponse(
|
||||
@Json(name = "status") val status: Status?,
|
||||
@Json(name = "awardForNewCard") val awardForNewCard: Double?,
|
||||
@Json(name = "awardForOldCard") val awardForOldCard: Double?,
|
||||
@Json(name = "newCard") val newCard: Data?,
|
||||
@Json(name = "oldCard") val oldCard: Data?,
|
||||
@Json(name = "awardPaymentToken") val awardPaymentToken: TokenData?,
|
||||
@Json(name = "error") override val error: Error? = null,
|
||||
) : AbstractPromotionResponse() {
|
||||
|
||||
data class Data(
|
||||
@Json(name = "status") val status: Status,
|
||||
@Json(name = "award") val award: Double,
|
||||
)
|
||||
|
||||
enum class Status(val value: String) {
|
||||
@Json(name = "pending")
|
||||
PENDING("pending"),
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.tangem.datasource.api.promotion.models.*
|
|||
import com.tangem.feature.learn2earn.data.api.Learn2earnPreferenceStorage
|
||||
import com.tangem.feature.learn2earn.data.api.Learn2earnRepository
|
||||
import com.tangem.feature.learn2earn.data.models.PromoUserData
|
||||
import com.tangem.feature.learn2earn.data.models.getData
|
||||
import com.tangem.utils.coroutines.AppCoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
|
|
@ -40,9 +41,10 @@ internal class DefaultLearn2earnRepository(
|
|||
|
||||
override suspend fun getPromotionInfo(): Result<PromotionInfoResponse> {
|
||||
return withContext(dispatchers.io) {
|
||||
val info = restorePromotionInfo()
|
||||
if (info?.status == PromotionInfoResponse.Status.FINISHED) {
|
||||
Result.success(info)
|
||||
val promotionInfo = restorePromotionInfo()
|
||||
val data = promotionInfo?.getData(userData.promoCode)
|
||||
if (data?.status == PromotionInfoResponse.Status.FINISHED) {
|
||||
Result.success(promotionInfo)
|
||||
} else {
|
||||
runCatching { api.getPromotionInfo(getProgramName()) }
|
||||
.fold(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package com.tangem.feature.learn2earn.data.models
|
||||
|
||||
import com.tangem.datasource.api.promotion.models.PromotionInfoResponse
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
internal fun PromotionInfoResponse.getData(promoCode: String?): PromotionInfoResponse.Data? {
|
||||
return if (promoCode == null) {
|
||||
newCard
|
||||
} else {
|
||||
oldCard
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ import com.tangem.feature.learn2earn.data.models.PromoUserData
|
|||
import com.tangem.feature.learn2earn.domain.api.*
|
||||
import com.tangem.feature.learn2earn.domain.models.Promotion
|
||||
import com.tangem.feature.learn2earn.domain.models.PromotionError
|
||||
import com.tangem.feature.learn2earn.domain.models.getData
|
||||
import com.tangem.feature.learn2earn.domain.models.toDomainError
|
||||
import com.tangem.lib.crypto.DerivationManager
|
||||
import com.tangem.lib.crypto.UserWalletManager
|
||||
|
|
@ -57,14 +58,10 @@ class DefaultLearn2earnInteractor(
|
|||
}
|
||||
|
||||
override fun getAwardAmount(): Int {
|
||||
val userInfo = repository.getUserData()
|
||||
val promotionInfo = promotion.getPromotionInfo()
|
||||
val promoCode = repository.getUserData().promoCode
|
||||
val awardAmount = promotion.getPromotionInfo().getData(promoCode).award.toInt()
|
||||
|
||||
return if (userInfo.promoCode == null) {
|
||||
promotionInfo.awardForOldCard
|
||||
} else {
|
||||
promotionInfo.awardForNewCard
|
||||
}.toInt()
|
||||
return awardAmount
|
||||
}
|
||||
|
||||
@Throws(IllegalArgumentException::class)
|
||||
|
|
@ -194,10 +191,14 @@ class DefaultLearn2earnInteractor(
|
|||
}
|
||||
|
||||
private fun promotionIsActive(): Boolean {
|
||||
val userData = repository.getUserData()
|
||||
val isActive = when {
|
||||
repository.getUserData().isAlreadyReceivedAward -> false
|
||||
userData.isAlreadyReceivedAward -> false
|
||||
promotion.isError() -> false
|
||||
else -> promotion.getPromotionInfo().status == PromotionInfoResponse.Status.ACTIVE
|
||||
else -> {
|
||||
val data = promotion.getPromotionInfo().getData(userData.promoCode)
|
||||
data.status == PromotionInfoResponse.Status.ACTIVE
|
||||
}
|
||||
}
|
||||
|
||||
return isActive
|
||||
|
|
@ -211,9 +212,8 @@ class DefaultLearn2earnInteractor(
|
|||
if (responseError == null) {
|
||||
Promotion(
|
||||
info = Promotion.PromotionInfo(
|
||||
status = response.status!!,
|
||||
awardForNewCard = response.awardForNewCard!!,
|
||||
awardForOldCard = response.awardForOldCard!!,
|
||||
newCard = response.newCard!!,
|
||||
oldCard = response.oldCard!!,
|
||||
awardPaymentToken = response.awardPaymentToken!!,
|
||||
),
|
||||
error = null,
|
||||
|
|
|
|||
|
|
@ -15,16 +15,9 @@ data class Promotion(
|
|||
|
||||
fun isError(): Boolean = error != null
|
||||
|
||||
fun isUnreachable(): Boolean = error == PromotionError.NetworkUnreachable
|
||||
|
||||
data class PromotionInfo(
|
||||
val status: PromotionInfoResponse.Status,
|
||||
val awardForNewCard: Double,
|
||||
val awardForOldCard: Double,
|
||||
val newCard: PromotionInfoResponse.Data,
|
||||
val oldCard: PromotionInfoResponse.Data,
|
||||
val awardPaymentToken: PromotionInfoResponse.TokenData,
|
||||
) {
|
||||
companion object
|
||||
}
|
||||
|
||||
companion object
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.tangem.feature.learn2earn.domain.models
|
||||
|
||||
import com.tangem.datasource.api.promotion.models.PromotionInfoResponse
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
internal fun Promotion.PromotionInfo.getData(promoCode: String?): PromotionInfoResponse.Data {
|
||||
return if (promoCode == null) {
|
||||
newCard
|
||||
} else {
|
||||
oldCard
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue