Updated on 2026-08-14
This commit is contained in:
commit
900532095b
6 changed files with 75 additions and 54 deletions
|
|
@ -18,7 +18,6 @@ import com.tangem.tap.common.DialogManager
|
|||
import com.tangem.tap.common.IntentHandler
|
||||
import com.tangem.tap.common.OnActivityResultCallback
|
||||
import com.tangem.tap.common.SnackbarHandler
|
||||
import com.tangem.tap.common.extensions.copyToClipboard
|
||||
import com.tangem.tap.common.redux.NotificationsHandler
|
||||
import com.tangem.tap.common.redux.global.AndroidResources
|
||||
import com.tangem.tap.common.redux.global.GlobalAction
|
||||
|
|
@ -61,7 +60,6 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
internalActivity = this
|
||||
setContentView(R.layout.activity_main)
|
||||
systemActions()
|
||||
store.dispatch(NavigationAction.ActivityCreated(WeakReference(this)))
|
||||
|
|
@ -176,10 +174,4 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac
|
|||
override fun removeOnActivityResultCallback(callback: OnActivityResultCallback) {
|
||||
onActivityResultCallbacks.remove(callback)
|
||||
}
|
||||
}
|
||||
|
||||
lateinit var internalActivity: AppCompatActivity
|
||||
//TODO: delete
|
||||
fun copyToClipboard(text: String) {
|
||||
internalActivity.copyToClipboard(text)
|
||||
}
|
||||
|
|
@ -162,9 +162,9 @@ private class ScanWalletProcessor(
|
|||
session: CardSession,
|
||||
callback: (result: CompletionResult<ScanResponse>) -> Unit,
|
||||
) {
|
||||
val activationIsFinished = preferencesStorage.usedCardsPrefStorage.isActivationFinished(card.cardId)
|
||||
val activationInProgress = preferencesStorage.usedCardsPrefStorage.isActivationInProgress(card.cardId)
|
||||
|
||||
if (card.backupStatus == Card.BackupStatus.NoBackup && !activationIsFinished && card.wallets.isNotEmpty()) {
|
||||
if (card.backupStatus == Card.BackupStatus.NoBackup && activationInProgress && card.wallets.isNotEmpty()) {
|
||||
StartPrimaryCardLinkingTask().run(session) { linkingResult ->
|
||||
when (linkingResult) {
|
||||
is CompletionResult.Success -> {
|
||||
|
|
|
|||
|
|
@ -14,15 +14,16 @@ class OnboardingHelper {
|
|||
|
||||
fun isOnboardingCase(response: ScanResponse): Boolean {
|
||||
val cardInfoStorage = preferencesStorage.usedCardsPrefStorage
|
||||
val cardId = response.card.cardId
|
||||
return when {
|
||||
response.isTangemTwins() -> {
|
||||
if (!response.twinsIsTwinned()) {
|
||||
true
|
||||
} else {
|
||||
cardInfoStorage.isActivationStarted(response.card.cardId)
|
||||
cardInfoStorage.isActivationInProgress(cardId)
|
||||
}
|
||||
}
|
||||
response.card.hasWallets() -> cardInfoStorage.isActivationStarted(response.card.cardId)
|
||||
response.card.hasWallets() -> cardInfoStorage.isActivationInProgress(cardId)
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,13 +4,10 @@ import com.tangem.blockchain.common.Amount
|
|||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.WalletManagerFactory
|
||||
import com.tangem.common.extensions.guard
|
||||
import com.tangem.common.extensions.toHexString
|
||||
import com.tangem.common.json.MoshiJsonConverter
|
||||
import com.tangem.domain.common.SaltPayWorkaround
|
||||
import com.tangem.domain.common.ScanResponse
|
||||
import com.tangem.network.api.paymentology.PaymentologyApiService
|
||||
import com.tangem.tap.common.toggleWidget.WidgetState
|
||||
import com.tangem.tap.copyToClipboard
|
||||
import com.tangem.tap.domain.extensions.makeSaltPayWalletManager
|
||||
import com.tangem.tap.features.onboarding.products.wallet.saltPay.GnosisRegistrator
|
||||
import com.tangem.tap.features.onboarding.products.wallet.saltPay.KYCProvider
|
||||
|
|
@ -60,22 +57,9 @@ data class OnboardingSaltPayState(
|
|||
paymentologyService = store.state.domainNetworks.paymentologyService,
|
||||
kycProvider = saltPayConfig.kycProvider,
|
||||
)
|
||||
test(scanResponse, gnosisRegistrator)
|
||||
return registrationManager to saltPayConfig
|
||||
}
|
||||
|
||||
//TODO: delete
|
||||
private fun test(scanResponse: ScanResponse, gnosisRegistrator: GnosisRegistrator) {
|
||||
val map = mapOf(
|
||||
"CID" to scanResponse.card.cardId,
|
||||
"cardPublicKey" to scanResponse.card.cardPublicKey.toHexString(),
|
||||
"walletPublicKey" to gnosisRegistrator.walletManager.wallet.publicKey.blockchainKey.toHexString(),
|
||||
"walletAddress" to gnosisRegistrator.walletManager.wallet.address,
|
||||
)
|
||||
val json = MoshiJsonConverter.INSTANCE.prettyPrint(map)
|
||||
copyToClipboard(json)
|
||||
}
|
||||
|
||||
fun makeSaltPayRegistrationManager(
|
||||
scanResponse: ScanResponse,
|
||||
gnosisRegistrator: GnosisRegistrator,
|
||||
|
|
|
|||
|
|
@ -33,11 +33,6 @@ class PreferencesStorage(applicationContext: Application) {
|
|||
|
||||
fun getCountOfLaunches(): Int = preferences.getInt(APP_LAUNCH_COUNT_KEY, 1)
|
||||
|
||||
@Deprecated("Use UsedCardsPrefStorage instead")
|
||||
fun wasCardScannedBefore(cardId: String): Boolean {
|
||||
return usedCardsPrefStorage.wasScanned(cardId)
|
||||
}
|
||||
|
||||
fun saveTwinsOnboardingShown() {
|
||||
preferences.edit { putBoolean(TWINS_ONBOARDING_SHOWN_KEY, true) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,13 +14,13 @@ class UsedCardsPrefStorage(
|
|||
private val jsonConverter: MoshiJsonConverter,
|
||||
) {
|
||||
|
||||
internal fun migrate() {
|
||||
val scannedIds = preferences.getString(SCANNED_CARDS_IDS_KEY, null) ?: return
|
||||
private val migrationList = mutableListOf(
|
||||
UserCardInfoToV2(this),
|
||||
)
|
||||
|
||||
val usedCardsInfo = scannedIds.split(",").map { UsedCardInfo(it.trim(), true) }
|
||||
if (save(usedCardsInfo.toMutableList())) {
|
||||
preferences.edit { this.remove(SCANNED_CARDS_IDS_KEY) }
|
||||
}
|
||||
internal fun migrate() {
|
||||
migrationList.forEach { it.migrate() }
|
||||
migrationList.clear()
|
||||
}
|
||||
|
||||
fun scanned(cardId: String) {
|
||||
|
|
@ -45,20 +45,28 @@ class UsedCardsPrefStorage(
|
|||
|
||||
fun activationFinished(cardId: String) {
|
||||
val restoredList = restore()
|
||||
val foundItem = findCardInfo(cardId, restoredList)?.copy(isActivationStarted = false)
|
||||
?: UsedCardInfo(cardId, isActivationStarted = false)
|
||||
var foundItem = findCardInfo(cardId, restoredList) ?: UsedCardInfo(cardId)
|
||||
foundItem = foundItem.copy(
|
||||
isActivationStarted = true,
|
||||
isActivationFinished = true,
|
||||
)
|
||||
|
||||
save(foundItem, restoredList)
|
||||
}
|
||||
|
||||
fun isActivationFinished(cardId: String): Boolean {
|
||||
return !(findCardInfo(cardId)?.isActivationStarted ?: true)
|
||||
}
|
||||
|
||||
fun isActivationStarted(cardId: String): Boolean {
|
||||
return findCardInfo(cardId)?.isActivationStarted ?: false
|
||||
}
|
||||
|
||||
fun isActivationFinished(cardId: String): Boolean {
|
||||
return findCardInfo(cardId)?.isActivationFinished ?: false
|
||||
}
|
||||
|
||||
fun isActivationInProgress(cardId: String): Boolean {
|
||||
val cardInfo = findCardInfo(cardId) ?: return false
|
||||
return cardInfo.isActivationStarted && !cardInfo.isActivationFinished
|
||||
}
|
||||
|
||||
private fun findCardInfo(cardId: String, list: MutableList<UsedCardInfo>? = null): UsedCardInfo? {
|
||||
val findInList = list ?: restore()
|
||||
return findInList.firstOrNull { it.cardId == cardId }
|
||||
|
|
@ -74,7 +82,7 @@ class UsedCardsPrefStorage(
|
|||
private fun save(list: MutableList<UsedCardInfo>): Boolean {
|
||||
return try {
|
||||
val json = jsonConverter.toJson(list)
|
||||
preferences.edit { putString(USED_CARDS_INFO, json) }
|
||||
preferences.edit { putString(USED_CARDS_INFO_V2, json) }
|
||||
true
|
||||
} catch (ex: Exception) {
|
||||
Timber.e(ex)
|
||||
|
|
@ -83,23 +91,64 @@ class UsedCardsPrefStorage(
|
|||
}
|
||||
|
||||
private fun restore(): MutableList<UsedCardInfo> {
|
||||
val json = preferences.getString(USED_CARDS_INFO, null) ?: return mutableListOf()
|
||||
val json = preferences.getString(USED_CARDS_INFO_V2, null) ?: return mutableListOf()
|
||||
return try {
|
||||
jsonConverter.fromJson(json, jsonConverter.typedList(UsedCardInfo::class.java))!!
|
||||
} catch (ex: Exception) {
|
||||
preferences.edit(true) { remove(USED_CARDS_INFO) }
|
||||
preferences.edit(true) { remove(USED_CARDS_INFO_V2) }
|
||||
mutableListOf()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val USED_CARDS_INFO_V2 = "usedCardsInfo_v2"
|
||||
private const val USED_CARDS_INFO = "usedCardsInfo"
|
||||
private const val SCANNED_CARDS_IDS_KEY = "scannedCardIds"
|
||||
}
|
||||
|
||||
private class UserCardInfoToV2(
|
||||
private val storage: UsedCardsPrefStorage,
|
||||
) : Migration {
|
||||
override fun migrate() {
|
||||
val restoredCardsInfo = restore()
|
||||
if (restoredCardsInfo.isEmpty()) return
|
||||
|
||||
val newCardsInfo = restoredCardsInfo.map { cardInfo ->
|
||||
UsedCardInfo(
|
||||
cardId = cardInfo.cardId,
|
||||
isScanned = cardInfo.isScanned,
|
||||
isActivationStarted = true,
|
||||
isActivationFinished = !cardInfo.isActivationStarted,
|
||||
)
|
||||
}.toMutableList()
|
||||
storage.save(newCardsInfo)
|
||||
}
|
||||
|
||||
private fun restore(): MutableList<UsedCardInfoOld> {
|
||||
val json = storage.preferences.getString(USED_CARDS_INFO, null) ?: return mutableListOf()
|
||||
return try {
|
||||
storage.jsonConverter.fromJson(json, storage.jsonConverter.typedList(UsedCardInfoOld::class.java))!!
|
||||
} catch (ex: Exception) {
|
||||
mutableListOf()
|
||||
} finally {
|
||||
storage.preferences.edit(true) { remove(USED_CARDS_INFO) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private data class UsedCardInfo(
|
||||
val cardId: String,
|
||||
val isScanned: Boolean = false,
|
||||
val isActivationStarted: Boolean = false,
|
||||
val isActivationFinished: Boolean = false,
|
||||
)
|
||||
|
||||
private data class UsedCardInfoOld(
|
||||
val cardId: String,
|
||||
val isScanned: Boolean = false,
|
||||
val isActivationStarted: Boolean = false,
|
||||
)
|
||||
}
|
||||
|
||||
private data class UsedCardInfo(
|
||||
val cardId: String,
|
||||
val isScanned: Boolean = false,
|
||||
val isActivationStarted: Boolean = false,
|
||||
)
|
||||
private interface Migration {
|
||||
fun migrate()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue