NTP-29113 | Fetch vpa from app (#14683)

This commit is contained in:
Ayushman Sharma
2025-01-28 19:18:55 +05:30
committed by GitHub
parent b42e569640
commit 3bdb165c74
4 changed files with 37 additions and 7 deletions

View File

@@ -52,6 +52,7 @@ interface RetrofitService {
suspend fun fetchScreenUiTronConfigs(
@Header("Accept-Encoding") acceptEncoding: String,
@Header("X-Target") target: String,
@Header("vpa") vpa: String? = null,
@Path("screenId") screenId: String,
): Response<GenericResponse<ScreenDefinition>>
@@ -60,6 +61,7 @@ interface RetrofitService {
suspend fun fetchAlchemistScreenUiTronConfigs(
@Header("Accept-Encoding") acceptEncoding: String,
@Header("X-Target") target: String,
@Header("vpa") vpa: String? = null,
@Path("screenId") screenId: String,
): Response<GenericResponse<AlchemistScreenDefinition>>

View File

@@ -47,6 +47,7 @@ constructor(
suspend fun fetchCoinHomeScreenUiTronConfigs(
screenName: String,
shouldRefresh: Boolean? = null,
vpa: String? = null,
): Flow<RepoResult<ScreenDefinition>> {
val cacheKeyForResponse = DBCacheConstants.COIN_HOME_SCREEN_CACHE_KEY
val isCacheAvailable = cacheHandlerProxy.isCacheAvailable(key = cacheKeyForResponse)
@@ -67,6 +68,7 @@ constructor(
acceptEncoding = GZIP,
target = ModuleNameV2.FORGE.name,
screenId = COINS_SCREEN_SCREEN_NAME,
vpa = vpa,
),
)
},
@@ -76,6 +78,7 @@ constructor(
suspend fun fetchCoinHomeScreenV2(
screenName: String,
shouldRefresh: Boolean? = null,
vpa: String? = null,
): Flow<RepoResult<AlchemistScreenDefinition>> {
val cacheKeyForResponse = DBCacheConstants.COIN_HOME_SCREEN_V2_CACHE_KEY
@@ -98,6 +101,7 @@ constructor(
acceptEncoding = GZIP,
target = ModuleNameV2.ALCHEMIST.name,
screenId = COINS_SCREEN_SCREEN_V2_NAME,
vpa = vpa,
),
)
},

View File

@@ -7,6 +7,7 @@
package com.navi.coin.vm
import com.navi.base.cache.datastore.DataStoreHelper
import com.navi.base.utils.orFalse
import com.navi.coin.models.model.RedemptionRequest
import com.navi.coin.models.model.RedemptionResponse
@@ -70,20 +71,26 @@ import com.navi.uitron.model.data.UiTronActionData
import com.navi.uitron.utils.orVal
import com.navi.uitron.utils.transformations.moneyFormat
import com.ramcosta.composedestinations.spec.Direction
import dagger.Lazy
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.update
import org.json.JSONObject
@HiltViewModel
open class CoinHomeViewModelV1
@Inject
constructor(private val coinHomeScreenRepo: CoinHomeScreenRepo) : CoinBaseVM() {
constructor(
private val coinHomeScreenRepo: CoinHomeScreenRepo,
private val dataStoreHelper: Lazy<DataStoreHelper>,
) : CoinBaseVM() {
private val eventPublisher: NaviCoinsAnalytics.BasicEvent =
NaviCoinsAnalytics.naviCoinsAnalytics.BasicEvent()
@@ -116,6 +123,8 @@ constructor(private val coinHomeScreenRepo: CoinHomeScreenRepo) : CoinBaseVM() {
private var hasAutoRedeemTriggered = false
var vpa: String? = null
init {
launch { getActionCallback().collect { action -> handleCoinHomeScreenActions(action) } }
}
@@ -132,10 +141,7 @@ constructor(private val coinHomeScreenRepo: CoinHomeScreenRepo) : CoinBaseVM() {
)
}
is RedeemCoinAction -> {
redeemCoin(
upiId = handle.get<String?>(apiAction.upiHandleKey.orEmpty()).orEmpty(),
apiAction = apiAction,
)
redeemCoin(upiId = vpa.orEmpty(), apiAction = apiAction)
}
}
}
@@ -149,10 +155,14 @@ constructor(private val coinHomeScreenRepo: CoinHomeScreenRepo) : CoinBaseVM() {
if (shouldRefresh.orFalse()) {
_coinHomeScreenData.update { CoinHomeScreenState.Loading }
}
vpa = getVpaOfPrimaryAccount().firstOrNull()
coinHomeScreenRepo
.fetchCoinHomeScreenUiTronConfigs(
screenName = screenName,
shouldRefresh = shouldRefresh.orFalse(),
vpa = vpa,
)
.collect { result ->
val response = result.data
@@ -541,6 +551,10 @@ constructor(private val coinHomeScreenRepo: CoinHomeScreenRepo) : CoinBaseVM() {
coinHomeScreenRepo.updateNotificationsPermission(notificationSettings)
}
suspend fun getVpaOfPrimaryAccount(): Flow<String> {
return dataStoreHelper.get().get(key = KEY_UPI_PRIMARY_ACCOUNT_VPA, defaultValue = "")
}
private companion object {
val SHAREABILITY_URLS =
listOf(
@@ -566,5 +580,6 @@ constructor(private val coinHomeScreenRepo: CoinHomeScreenRepo) : CoinBaseVM() {
)
const val AUTO_REDEEM_LAYOUT_ID = "auto_redeem_layout"
const val INVISIBLE = "invisible"
const val KEY_UPI_PRIMARY_ACCOUNT_VPA = "upiPrimaryAccountVpa"
}
}

View File

@@ -7,6 +7,7 @@
package com.navi.coin.vm
import com.navi.base.cache.datastore.DataStoreHelper
import com.navi.base.utils.orFalse
import com.navi.coin.models.states.CoinHomeScreenV2State
import com.navi.coin.repo.repository.CoinHomeScreenRepo
@@ -17,17 +18,23 @@ import com.navi.common.network.ApiConstants
import com.navi.common.utils.isValidResponse
import com.navi.rr.common.constants.COIN_HOME_SCREEN_V2
import com.navi.rr.common.models.RRErrorData
import dagger.Lazy
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.update
@HiltViewModel
class CoinHomeViewModelV2 @Inject constructor(private val coinHomeScreenRepo: CoinHomeScreenRepo) :
CoinHomeViewModelV1(coinHomeScreenRepo) {
class CoinHomeViewModelV2
@Inject
constructor(
private val coinHomeScreenRepo: CoinHomeScreenRepo,
private val dataStoreHelper: Lazy<DataStoreHelper>,
) : CoinHomeViewModelV1(coinHomeScreenRepo, dataStoreHelper) {
private val _screenData = MutableStateFlow<CoinHomeScreenV2State>(CoinHomeScreenV2State.Loading)
val screenState = _screenData.asStateFlow()
@@ -65,10 +72,12 @@ class CoinHomeViewModelV2 @Inject constructor(private val coinHomeScreenRepo: Co
if (shouldRefresh.orFalse()) {
_screenData.update { CoinHomeScreenV2State.Loading }
}
vpa = getVpaOfPrimaryAccount().firstOrNull()
coinHomeScreenRepo
.fetchCoinHomeScreenV2(
screenName = screenName,
shouldRefresh = shouldRefresh.orFalse(),
vpa = vpa,
)
.collect { result ->
val response = result.data