Updated on 2026-08-14
This commit is contained in:
parent
494aa88d35
commit
aa059666ba
10 changed files with 96 additions and 51 deletions
|
|
@ -6,6 +6,8 @@ import com.tangem.datasource.local.preferences.AppPreferencesStore
|
|||
import com.tangem.datasource.local.preferences.PreferencesKeys
|
||||
import com.tangem.datasource.local.preferences.utils.getObjectList
|
||||
import com.tangem.datasource.local.preferences.utils.getObjectListSync
|
||||
import com.tangem.datasource.local.preferences.utils.getSyncOrDefault
|
||||
import com.tangem.datasource.local.preferences.utils.store
|
||||
import com.tangem.domain.card.repository.CardRepository
|
||||
import com.tangem.utils.extensions.addOrReplace
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
|
@ -64,6 +66,28 @@ internal class DefaultCardRepository(
|
|||
return card.isActivationStarted && !card.isActivationFinished
|
||||
}
|
||||
|
||||
override suspend fun isTangemTOSAccepted(): Boolean {
|
||||
return appPreferencesStore.getSyncOrDefault(key = PreferencesKeys.IS_TANGEM_TOS_ACCEPTED_KEY, default = false)
|
||||
}
|
||||
|
||||
override suspend fun isStart2CoinTOSAccepted(cardId: String): Boolean {
|
||||
return appPreferencesStore.getSyncOrDefault(
|
||||
key = PreferencesKeys.getStart2CoinTOSAcceptedKey(region = getRegion(cardId)),
|
||||
default = false,
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun acceptTangemTOS() {
|
||||
return appPreferencesStore.store(key = PreferencesKeys.IS_TANGEM_TOS_ACCEPTED_KEY, true)
|
||||
}
|
||||
|
||||
override suspend fun acceptStart2CoinTOS(cardId: String) {
|
||||
appPreferencesStore.store(
|
||||
key = PreferencesKeys.getStart2CoinTOSAcceptedKey(region = getRegion(cardId)),
|
||||
value = true,
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun AppPreferencesStore.editUsedCards(cardId: String, update: (UsedCardInfo) -> UsedCardInfo) {
|
||||
editData { mutablePreferences ->
|
||||
val usedCards = mutablePreferences.getUsedCards()
|
||||
|
|
@ -92,4 +116,15 @@ internal class DefaultCardRepository(
|
|||
return appPreferencesStore.getObjectListSync<UsedCardInfo>(PreferencesKeys.USED_CARDS_INFO_KEY)
|
||||
.firstOrNull { it.cardId == cardId }
|
||||
}
|
||||
|
||||
private fun getRegion(cardId: String): String? {
|
||||
if (cardId.isEmpty()) return null
|
||||
|
||||
return when (cardId[1]) {
|
||||
'0' -> "fr"
|
||||
'1' -> "ch"
|
||||
'2' -> "at"
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@ package com.tangem.data.source.preferences
|
|||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import com.tangem.data.source.preferences.storage.DisclaimerPrefStorage
|
||||
import javax.inject.Inject
|
||||
|
||||
// 🔥FIXME: Only logic to work with preferences must be here, must be separated to repositories
|
||||
|
|
@ -11,14 +10,11 @@ import javax.inject.Inject
|
|||
@Deprecated("Create repository instead")
|
||||
class PreferencesDataSource @Inject internal constructor(applicationContext: Context) {
|
||||
|
||||
val disclaimerPrefStorage: DisclaimerPrefStorage
|
||||
|
||||
private val preferences: SharedPreferences =
|
||||
applicationContext.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE)
|
||||
|
||||
init {
|
||||
incrementLaunchCounter()
|
||||
disclaimerPrefStorage = DisclaimerPrefStorage(preferences)
|
||||
}
|
||||
|
||||
var shouldShowSaveUserWalletScreen: Boolean
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
package com.tangem.data.source.preferences.storage
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
@Deprecated("Create repository instead")
|
||||
class DisclaimerPrefStorage internal constructor(
|
||||
private val preferences: SharedPreferences,
|
||||
) {
|
||||
|
||||
fun accept(disclaimerKey: String) {
|
||||
preferences.edit { putBoolean(disclaimerKey, true) }
|
||||
}
|
||||
|
||||
fun isAccepted(disclaimerKey: String): Boolean {
|
||||
return preferences.getBoolean(disclaimerKey, false)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue