From 640dab9c7e2760701f21f3da3cdc777774e499b0 Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 29 Apr 2025 15:20:34 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../referral/data/ReferralRepositoryImpl.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/features/referral/data/src/main/java/com/tangem/feature/referral/data/ReferralRepositoryImpl.kt b/features/referral/data/src/main/java/com/tangem/feature/referral/data/ReferralRepositoryImpl.kt index 463325b671..279d0632bf 100644 --- a/features/referral/data/src/main/java/com/tangem/feature/referral/data/ReferralRepositoryImpl.kt +++ b/features/referral/data/src/main/java/com/tangem/feature/referral/data/ReferralRepositoryImpl.kt @@ -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 = mutableMapOf() + private val referralStatus: ConcurrentHashMap = 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 } }