Updated on 2026-08-14
This commit is contained in:
parent
ffbd445677
commit
640dab9c7e
1 changed files with 8 additions and 7 deletions
|
|
@ -16,6 +16,7 @@ import com.tangem.feature.referral.domain.models.ReferralData
|
|||
import com.tangem.feature.referral.domain.models.TokenData
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import javax.inject.Inject
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
|
|
@ -30,7 +31,7 @@ internal class ReferralRepositoryImpl @Inject constructor(
|
|||
private val cryptoCurrencyFactory = CryptoCurrencyFactory(excludedBlockchains)
|
||||
|
||||
// todo this quick fix of multiple api requests, make proper cache store
|
||||
private val referralStatus: MutableMap<String, Boolean> = mutableMapOf()
|
||||
private val referralStatus: ConcurrentHashMap<String, ReferralData> = ConcurrentHashMap()
|
||||
|
||||
override suspend fun getReferralData(walletId: String): ReferralData {
|
||||
return withContext(coroutineDispatcher.io) {
|
||||
|
|
@ -40,15 +41,14 @@ internal class ReferralRepositoryImpl @Inject constructor(
|
|||
),
|
||||
)
|
||||
|
||||
referralStatus[walletId] = referralData is ReferralData.ParticipantData
|
||||
referralStatus[walletId] = referralData
|
||||
referralData
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun isReferralParticipant(userWalletId: UserWalletId): Boolean {
|
||||
val isReferralParticipant = referralStatus[userWalletId.stringValue]
|
||||
|
||||
return isReferralParticipant ?: getReferralData(userWalletId.stringValue) is ReferralData.ParticipantData
|
||||
val storedReferralData = referralStatus[userWalletId.stringValue] ?: getReferralData(userWalletId.stringValue)
|
||||
return storedReferralData is ReferralData.ParticipantData
|
||||
}
|
||||
|
||||
override suspend fun startReferral(
|
||||
|
|
@ -58,8 +58,7 @@ internal class ReferralRepositoryImpl @Inject constructor(
|
|||
address: String,
|
||||
): ReferralData {
|
||||
return withContext(coroutineDispatcher.io) {
|
||||
referralStatus[walletId] = true
|
||||
referralConverter.convert(
|
||||
val referralData = referralConverter.convert(
|
||||
referralApi.startReferral(
|
||||
startReferralBody = StartReferralBody(
|
||||
walletId = walletId,
|
||||
|
|
@ -69,6 +68,8 @@ internal class ReferralRepositoryImpl @Inject constructor(
|
|||
),
|
||||
),
|
||||
)
|
||||
referralStatus[walletId] = referralData
|
||||
referralData
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue