Updated on 2026-08-14
This commit is contained in:
parent
6391ced12b
commit
f234915b63
6 changed files with 48 additions and 48 deletions
|
|
@ -109,7 +109,10 @@ internal class CardSettingsViewModel @Inject constructor(
|
|||
|
||||
if (isResetCardAllowed) {
|
||||
CardInfo.ResetToFactorySettings(
|
||||
description = getResetToFactoryDescription(card.backupStatus, cardTypesResolver),
|
||||
description = getResetToFactoryDescription(
|
||||
isActiveBackupStatus = card.backupStatus?.isActive == true,
|
||||
typesResolver = cardTypesResolver,
|
||||
),
|
||||
).let(::add)
|
||||
}
|
||||
}
|
||||
|
|
@ -135,10 +138,15 @@ internal class CardSettingsViewModel @Inject constructor(
|
|||
push(
|
||||
route = AppRoute.ResetToFactory(
|
||||
userWalletId = userWalletId,
|
||||
cardSpecificInfo = AppRoute.ResetToFactory.CardSpecificInfo(
|
||||
cardId = card.cardId,
|
||||
backupStatus = card.backupStatus,
|
||||
),
|
||||
cardId = card.cardId,
|
||||
isActiveBackupStatus = card.backupStatus?.isActive == true,
|
||||
backupCardsCount = when (val status = card.backupStatus) {
|
||||
is CardDTO.BackupStatus.Active -> status.cardCount
|
||||
is CardDTO.BackupStatus.CardLinked,
|
||||
CardDTO.BackupStatus.NoBackup,
|
||||
null,
|
||||
-> 0
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
package com.tangem.tap.features.details.ui.common.utils
|
||||
|
||||
import com.tangem.domain.common.CardTypesResolver
|
||||
import com.tangem.domain.models.scan.CardDTO
|
||||
import com.tangem.tap.features.details.ui.cardsettings.TextReference
|
||||
import com.tangem.wallet.R
|
||||
|
||||
internal fun getResetToFactoryDescription(
|
||||
backupStatus: CardDTO.BackupStatus?,
|
||||
isActiveBackupStatus: Boolean,
|
||||
typesResolver: CardTypesResolver,
|
||||
): TextReference {
|
||||
return if (backupStatus?.isActive != true || typesResolver.isTangemTwins()) {
|
||||
return if (!isActiveBackupStatus || typesResolver.isTangemTwins()) {
|
||||
TextReference.Res(R.string.reset_card_without_backup_to_factory_message)
|
||||
} else {
|
||||
TextReference.Res(R.string.reset_card_with_backup_to_factory_message)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import com.tangem.domain.card.DeleteSavedAccessCodesUseCase
|
|||
import com.tangem.domain.card.ResetCardUseCase
|
||||
import com.tangem.domain.card.ResetCardUserCodeParams
|
||||
import com.tangem.domain.common.util.cardTypesResolver
|
||||
import com.tangem.domain.models.scan.CardDTO
|
||||
import com.tangem.domain.wallets.legacy.UserWalletsListManager
|
||||
import com.tangem.domain.wallets.legacy.asLockable
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
|
|
@ -65,8 +64,15 @@ internal class ResetCardViewModel @Inject constructor(
|
|||
// endregion
|
||||
|
||||
// region Data of card that was scanned on CardSettings
|
||||
private val primaryCardId: String
|
||||
private val primaryBackupStatus: CardDTO.BackupStatus?
|
||||
private val primaryCardId: String = savedStateHandle.get<String>(AppRoute.ResetToFactory.CARD_ID)
|
||||
?: error("CardId must be provided for ResetCardViewModel")
|
||||
|
||||
private val isActiveBackupPrimaryCard =
|
||||
savedStateHandle.get<Boolean>(AppRoute.ResetToFactory.IS_ACTIVE_BACKUP_STATUS)
|
||||
?: error("IsActiveBackupCard must be provided for ResetCardViewModel")
|
||||
|
||||
private val primaryBackupCardsCount = savedStateHandle.get<Int>(AppRoute.ResetToFactory.BACKUP_CARDS_COUNT)
|
||||
?: error("CardCount must be provided for ResetCardViewModel")
|
||||
// endregion
|
||||
|
||||
// TODO: move logic to separate domain entity
|
||||
|
|
@ -76,15 +82,6 @@ internal class ResetCardViewModel @Inject constructor(
|
|||
value = getInitialState(),
|
||||
)
|
||||
|
||||
init {
|
||||
val cardSpecificInfo = savedStateHandle.get<Bundle>(AppRoute.ResetToFactory.CARD_SPECIFIC_DATA)
|
||||
?.unbundle(AppRoute.ResetToFactory.CardSpecificInfo.serializer())
|
||||
?: error("CardSpecificData must be provided for ResetCardViewModel")
|
||||
|
||||
primaryCardId = cardSpecificInfo.cardId
|
||||
primaryBackupStatus = cardSpecificInfo.backupStatus
|
||||
}
|
||||
|
||||
private fun getInitialState(): ResetCardScreenState {
|
||||
val shouldShowResetPasswordButton = shouldShowResetPasswordButton()
|
||||
val warningsToShow = buildList {
|
||||
|
|
@ -98,7 +95,7 @@ internal class ResetCardViewModel @Inject constructor(
|
|||
return ResetCardScreenState(
|
||||
resetButtonEnabled = false,
|
||||
descriptionText = getResetToFactoryDescription(
|
||||
backupStatus = primaryBackupStatus,
|
||||
isActiveBackupStatus = isActiveBackupPrimaryCard,
|
||||
typesResolver = currentCardTypesResolver,
|
||||
),
|
||||
warningsToShow = warningsToShow,
|
||||
|
|
@ -115,7 +112,7 @@ internal class ResetCardViewModel @Inject constructor(
|
|||
private fun shouldShowResetPasswordButton(): Boolean {
|
||||
val isTangemWallet = currentCardTypesResolver.isTangemWallet() || currentCardTypesResolver.isWallet2()
|
||||
|
||||
return isTangemWallet && primaryBackupStatus is CardDTO.BackupStatus.Active
|
||||
return isTangemWallet && isActiveBackupPrimaryCard
|
||||
}
|
||||
|
||||
private fun toggleFirstCondition(isAccepted: Boolean) {
|
||||
|
|
@ -283,12 +280,6 @@ internal class ResetCardViewModel @Inject constructor(
|
|||
private fun getBackupCardsCount(): Int {
|
||||
if (!currentCardTypesResolver.isMultiwalletAllowed()) return 0
|
||||
|
||||
return when (val status = primaryBackupStatus) {
|
||||
is CardDTO.BackupStatus.Active -> status.cardCount
|
||||
is CardDTO.BackupStatus.CardLinked,
|
||||
is CardDTO.BackupStatus.NoBackup,
|
||||
null,
|
||||
-> 0
|
||||
}
|
||||
return primaryBackupCardsCount
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,6 @@ import com.tangem.common.routing.bundle.RouteBundleParams
|
|||
import com.tangem.common.routing.bundle.bundle
|
||||
import com.tangem.common.routing.entity.SerializableIntent
|
||||
import com.tangem.core.decompose.navigation.Route
|
||||
import com.tangem.domain.models.scan.CardDTO
|
||||
import com.tangem.domain.qrscanning.models.SourceType
|
||||
import com.tangem.domain.staking.model.stakekit.Yield
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
|
|
@ -145,25 +144,35 @@ sealed class AppRoute(val path: String) : Route {
|
|||
data object AppSettings : AppRoute(path = "/app_settings")
|
||||
|
||||
/**
|
||||
* Reset to factory route
|
||||
* Reset to factory
|
||||
*
|
||||
* @property userWalletId user wallet id
|
||||
* @property cardSpecificInfo info about card that was scanned on CardSettings
|
||||
* @property userWalletId user wallet id
|
||||
* @property cardId reset card id
|
||||
* @property isActiveBackupStatus reset backup card status
|
||||
* @property backupCardsCount backup cards count
|
||||
*/
|
||||
@Serializable
|
||||
data class ResetToFactory(
|
||||
val userWalletId: UserWalletId,
|
||||
val cardSpecificInfo: CardSpecificInfo,
|
||||
) : AppRoute(path = "/reset_to_factory/${userWalletId.stringValue}/$cardSpecificInfo"), RouteBundleParams {
|
||||
val cardId: String,
|
||||
val isActiveBackupStatus: Boolean,
|
||||
val backupCardsCount: Int,
|
||||
) : AppRoute(
|
||||
path = "/reset_to_factory" +
|
||||
"/${userWalletId.stringValue}" +
|
||||
"/$cardId" +
|
||||
"/$isActiveBackupStatus" +
|
||||
"/$backupCardsCount",
|
||||
),
|
||||
RouteBundleParams {
|
||||
|
||||
override fun getBundle(): Bundle = bundle(serializer())
|
||||
|
||||
@Serializable
|
||||
data class CardSpecificInfo(val cardId: String, val backupStatus: CardDTO.BackupStatus?)
|
||||
|
||||
companion object {
|
||||
const val USER_WALLET_ID = "userWalletId"
|
||||
const val CARD_SPECIFIC_DATA = "cardSpecificInfo"
|
||||
const val CARD_ID = "cardId"
|
||||
const val IS_ACTIVE_BACKUP_STATUS = "isActiveBackupStatus"
|
||||
const val BACKUP_CARDS_COUNT = "backupCardsCount"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ import com.tangem.common.card.EncryptionMode
|
|||
import com.tangem.crypto.hdWallet.DerivationPath
|
||||
import com.tangem.crypto.hdWallet.bip32.ExtendedPublicKey
|
||||
import com.tangem.operations.attestation.Attestation
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import java.util.Date
|
||||
import com.tangem.common.card.FirmwareVersion as SdkFirmwareVersion
|
||||
|
||||
|
|
@ -300,19 +298,12 @@ data class CardDTO(
|
|||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
sealed class BackupStatus {
|
||||
|
||||
@Serializable
|
||||
@SerialName("card_linked")
|
||||
data class CardLinked(val cardCount: Int) : BackupStatus()
|
||||
|
||||
@Serializable
|
||||
@SerialName("active")
|
||||
data class Active(val cardCount: Int) : BackupStatus()
|
||||
|
||||
@Serializable
|
||||
@SerialName("no_backup")
|
||||
data object NoBackup : BackupStatus()
|
||||
|
||||
val isActive: Boolean
|
||||
|
|
|
|||
|
|
@ -341,6 +341,8 @@ internal class WalletViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
private suspend fun deleteWallet(action: WalletsUpdateActionResolver.Action.DeleteWallet) {
|
||||
walletScreenContentLoader.cancel(action.deletedWalletId)
|
||||
|
||||
walletScreenContentLoader.load(
|
||||
userWallet = action.selectedWallet,
|
||||
clickIntents = clickIntents,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue