NTP-906 | optimisation for upi scratch card (#11794)
This commit is contained in:
@@ -16,4 +16,6 @@ interface ScratchCardNudgeHelper {
|
||||
suspend fun getNudgeDetails(product: String, objective: String): RewardNudgeApiStatus
|
||||
|
||||
fun getGratification(requestId: String, screenName: String): Flow<GratificationStatus>
|
||||
|
||||
suspend fun getGratificationV2(key: String, requestId: String, screenName: String)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
package com.navi.rr.scratchcard.helper
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.navi.base.cache.model.NaviCacheEntity
|
||||
import com.navi.base.cache.repository.NaviCacheRepository
|
||||
import com.navi.base.sharedpref.CommonPrefConstants
|
||||
import com.navi.base.sharedpref.PreferenceManager
|
||||
import com.navi.base.utils.FirestoreDataProviderImpl
|
||||
@@ -36,14 +38,20 @@ import javax.inject.Inject
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
import kotlinx.coroutines.Deferred
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import org.json.JSONObject
|
||||
|
||||
class ScratchCardNudgeHelperImpl @Inject constructor(private val scratchCardRepo: ScratchCardRepo) :
|
||||
ScratchCardNudgeHelper {
|
||||
class ScratchCardNudgeHelperImpl
|
||||
@Inject
|
||||
constructor(
|
||||
private val scratchCardRepo: ScratchCardRepo,
|
||||
private val naviCacheRepository: NaviCacheRepository
|
||||
) : ScratchCardNudgeHelper {
|
||||
|
||||
private val eventTracker by lazy { NaviRRAnalytics.naviRRAnalytics.Rewards() }
|
||||
|
||||
@@ -82,6 +90,30 @@ class ScratchCardNudgeHelperImpl @Inject constructor(private val scratchCardRepo
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getGratificationV2(
|
||||
key: String,
|
||||
requestId: String,
|
||||
screenName: String,
|
||||
) {
|
||||
coroutineScope {
|
||||
getGratification(requestId = requestId, screenName = screenName).collect {
|
||||
response: GratificationStatus ->
|
||||
when (response) {
|
||||
is GratificationStatus.Success -> {
|
||||
response.data.scratchCardResponse?.requestId = requestId
|
||||
}
|
||||
is GratificationStatus.Timeout -> {
|
||||
response.requestId = requestId
|
||||
}
|
||||
}
|
||||
naviCacheRepository.save(
|
||||
NaviCacheEntity(key = key, value = response.toJson(), version = 1)
|
||||
)
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getGratification(
|
||||
requestId: String,
|
||||
screenName: String,
|
||||
@@ -138,7 +170,7 @@ class ScratchCardNudgeHelperImpl @Inject constructor(private val scratchCardRepo
|
||||
.startPolling(
|
||||
onTimeout = {
|
||||
if (responseProcessed.compareAndSet(false, true)) {
|
||||
send(GratificationStatus.Timeout)
|
||||
send(GratificationStatus.Timeout())
|
||||
}
|
||||
}
|
||||
) {
|
||||
|
||||
@@ -15,7 +15,8 @@ data class GratificationResponse(
|
||||
)
|
||||
|
||||
sealed interface GratificationStatus {
|
||||
data object Timeout : GratificationStatus
|
||||
|
||||
data class Timeout(var requestId: String? = null) : GratificationStatus
|
||||
|
||||
data class Success(val data: GratificationResponse) : GratificationStatus
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ data class ScratchCardBackData(
|
||||
|
||||
data class ScratchCardResponse(
|
||||
val rewardRefId: String? = null,
|
||||
var requestId: String? = null,
|
||||
val amount: Int? = null,
|
||||
val rewardType: String? = null,
|
||||
val rewardForm: String? = null,
|
||||
|
||||
Reference in New Issue
Block a user