Updated on 2026-08-14
This commit is contained in:
parent
72f191694a
commit
00e8689ada
4 changed files with 1 additions and 103 deletions
|
|
@ -15,7 +15,6 @@ class PreferencesStorage(applicationContext: Application) {
|
|||
val appRatingLaunchObserver: AppRatingLaunchObserver
|
||||
val usedCardsPrefStorage: UsedCardsPrefStorage
|
||||
val fiatCurrenciesPrefStorage: FiatCurrenciesPrefStorage
|
||||
val saltPayActivationStorage: SaltPayActivationStorage
|
||||
val disclaimerPrefStorage: DisclaimerPrefStorage
|
||||
|
||||
init {
|
||||
|
|
@ -25,7 +24,6 @@ class PreferencesStorage(applicationContext: Application) {
|
|||
usedCardsPrefStorage.migrate()
|
||||
fiatCurrenciesPrefStorage = FiatCurrenciesPrefStorage(preferences, MoshiJsonConverter.INSTANCE)
|
||||
fiatCurrenciesPrefStorage.migrate()
|
||||
saltPayActivationStorage = SaltPayActivationPrefStorage(applicationContext, MoshiJsonConverter.INSTANCE)
|
||||
disclaimerPrefStorage = DisclaimerPrefStorage(preferences)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,82 +0,0 @@
|
|||
package com.tangem.tap.persistence
|
||||
|
||||
import android.content.Context
|
||||
import androidx.core.content.edit
|
||||
import at.favre.lib.armadillo.ArmadilloSharedPreferences
|
||||
import com.tangem.common.json.MoshiJsonConverter
|
||||
import com.tangem.common.services.secure.SecureStorage
|
||||
import com.tangem.tangem_sdk_new.storage.createEncryptedSharedPreferences
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
interface SaltPayActivationStorage {
|
||||
var data: SaltPayActivationData
|
||||
|
||||
fun reset()
|
||||
|
||||
companion object {
|
||||
fun stub(): SaltPayActivationStorage = object : SaltPayActivationStorage {
|
||||
override var data: SaltPayActivationData = SaltPayActivationData()
|
||||
override fun reset() {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class SaltPayActivationData(
|
||||
val transactionsSent: Boolean = false,
|
||||
)
|
||||
|
||||
class SaltPayActivationPrefStorage(
|
||||
context: Context,
|
||||
private val converter: MoshiJsonConverter,
|
||||
) : SaltPayActivationStorage {
|
||||
|
||||
private val storage: ArmadilloSharedPreferences = SecureStorage.createEncryptedSharedPreferences(
|
||||
context = context,
|
||||
storageName = "saltpay",
|
||||
)
|
||||
|
||||
private var isFetching: Boolean = false
|
||||
|
||||
init {
|
||||
fetch()
|
||||
}
|
||||
|
||||
override var data: SaltPayActivationData = SaltPayActivationData()
|
||||
set(value) {
|
||||
field = value
|
||||
if (!isFetching) save()
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
storage.edit(true) {
|
||||
this.remove(REGISTRATION_DATA_KEY)
|
||||
data = SaltPayActivationData()
|
||||
}
|
||||
}
|
||||
|
||||
private fun save() {
|
||||
storage.edit(true) {
|
||||
putString(REGISTRATION_DATA_KEY, converter.toJson(data))
|
||||
}
|
||||
}
|
||||
|
||||
private fun fetch(): SaltPayActivationData {
|
||||
isFetching = true
|
||||
|
||||
val jsonData = storage.getString(REGISTRATION_DATA_KEY, null)
|
||||
data = if (jsonData == null) {
|
||||
SaltPayActivationData()
|
||||
} else {
|
||||
converter.fromJson<SaltPayActivationData>(jsonData) ?: SaltPayActivationData()
|
||||
}
|
||||
isFetching = false
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val REGISTRATION_DATA_KEY = "saltpay_registration_data"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue