Updated on 2026-08-14

This commit is contained in:
Tangem 2024-10-08 18:22:04 +05:00
parent cf48db1c45
commit 3d590dfba6
8 changed files with 78 additions and 16 deletions

View file

@ -10,6 +10,7 @@ import com.tangem.tap.common.redux.DebugErrorAction
import com.tangem.tap.common.redux.ErrorAction
import com.tangem.tap.common.redux.NotificationAction
import com.tangem.tap.domain.TapError
import com.tangem.tap.features.onboarding.products.wallet.redux.BackupStartedSource
import org.rekotlin.Action
sealed class GlobalAction : Action {
@ -29,7 +30,11 @@ sealed class GlobalAction : Action {
* For resuming unfinished backup of standard Wallet see
* BackupAction.CheckForUnfinishedBackup, GlobalAction.Onboarding.StartForUnfinishedBackup
*/
data class Start(val scanResponse: ScanResponse, val canSkipBackup: Boolean = true) : Onboarding()
data class Start(
val scanResponse: ScanResponse,
val source: BackupStartedSource,
val canSkipBackup: Boolean = true,
) : Onboarding()
/**
* Initiate resuming of unfinished backup for standard Wallet.

View file

@ -6,6 +6,7 @@ import com.tangem.tap.common.extensions.inject
import com.tangem.tap.common.redux.AppState
import com.tangem.tap.common.redux.global.GlobalAction
import com.tangem.tap.features.details.redux.DetailsAction
import com.tangem.tap.features.onboarding.products.wallet.redux.BackupStartedSource
import com.tangem.tap.proxy.redux.DaggerGraphState
import com.tangem.tap.scope
import com.tangem.tap.store
@ -29,6 +30,7 @@ internal object LegacyMiddleware {
store.dispatch(
GlobalAction.Onboarding.Start(
scanResponse = action.scanResponse,
source = BackupStartedSource.CreateBackup,
canSkipBackup = action.canSkipBackup,
),
)

View file

@ -20,6 +20,7 @@ import com.tangem.tap.features.disclaimer.createDisclaimer
import com.tangem.tap.features.onboarding.OnboardingHelper
import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsAction
import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsStep
import com.tangem.tap.features.onboarding.products.wallet.redux.BackupStartedSource
import com.tangem.tap.proxy.redux.DaggerGraphState
import com.tangem.tap.scope
import com.tangem.tap.store
@ -141,6 +142,7 @@ internal object LegacyScanProcessor {
store.dispatchOnMain(
GlobalAction.Onboarding.Start(
scanResponse = scanResponse,
source = BackupStartedSource.Onboarding,
canSkipBackup = scanResponse.card.canSkipBackup,
),
)

View file

@ -19,6 +19,7 @@ import com.tangem.tap.common.redux.global.GlobalAction
import com.tangem.tap.features.onboarding.OnboardingHelper
import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsAction
import com.tangem.tap.features.onboarding.products.twins.redux.TwinCardsStep
import com.tangem.tap.features.onboarding.products.wallet.redux.BackupStartedSource
import com.tangem.tap.proxy.redux.DaggerGraphState
import com.tangem.utils.extensions.DELAY_SDK_DIALOG_CLOSE
import kotlinx.coroutines.delay
@ -48,6 +49,7 @@ class CheckForOnboardingChain(
store.dispatchOnMain(
GlobalAction.Onboarding.Start(
scanResponse = previousChainResult,
source = BackupStartedSource.Onboarding,
canSkipBackup = previousChainResult.card.canSkipBackup,
),
)

View file

@ -17,6 +17,7 @@ import com.tangem.domain.common.util.cardTypesResolver
import com.tangem.domain.models.scan.CardDTO
import com.tangem.domain.models.scan.ScanResponse
import com.tangem.domain.wallets.builder.UserWalletBuilder
import com.tangem.domain.wallets.legacy.UserWalletsListManager
import com.tangem.domain.wallets.models.Artwork
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.feature.onboarding.data.model.CreateWalletResponse
@ -599,18 +600,19 @@ private fun handleBackupAction(appState: () -> AppState?, action: BackupAction)
)
val userWalletsListManager = store.inject(DaggerGraphState::generalUserWalletsListManager)
userWalletsListManager.save(
userWallet = userWallet.copy(
scanResponse = updateScanResponseAfterBackup(
scanResponse = requireNotNull(
value = scanResponse,
lazyMessage = { "ScanResponse is null" },
),
backupState = backupState,
),
),
canOverride = true,
)
when (backupState.startedSource) {
BackupStartedSource.Onboarding -> saveWallet(
userWalletsListManager = userWalletsListManager,
userWallet = userWallet,
scanResponse = scanResponse,
backupState = backupState,
)
BackupStartedSource.CreateBackup -> updateWallet(
userWalletsListManager = userWalletsListManager,
userWallet = userWallet,
backupState = backupState,
)
}
} else {
readCard { newScanResponse ->
scanResponse = newScanResponse
@ -650,6 +652,44 @@ private fun handleBackupAction(appState: () -> AppState?, action: BackupAction)
}
}
private suspend fun saveWallet(
userWalletsListManager: UserWalletsListManager,
userWallet: UserWallet,
scanResponse: ScanResponse?,
backupState: BackupState,
) {
userWalletsListManager.save(
userWallet = userWallet.copy(
scanResponse = updateScanResponseAfterBackup(
scanResponse = requireNotNull(
value = scanResponse,
lazyMessage = { "ScanResponse is null" },
),
backupState = backupState,
),
),
canOverride = true,
)
}
private suspend fun updateWallet(
userWalletsListManager: UserWalletsListManager,
userWallet: UserWallet,
backupState: BackupState,
) {
userWalletsListManager.update(
userWalletId = userWallet.walletId,
update = { wallet ->
wallet.copy(
scanResponse = updateScanResponseAfterBackup(
scanResponse = wallet.scanResponse,
backupState = backupState,
),
)
},
)
}
private suspend fun createUserWallet(scanResponse: ScanResponse, backupState: BackupState): UserWallet {
val walletNameGenerateUseCase = store.inject(DaggerGraphState::generateWalletNameUseCase)
return requireNotNull(

View file

@ -14,12 +14,13 @@ object OnboardingWalletReducer {
@Suppress("CyclomaticComplexMethod")
private fun internalReduce(action: Action, appState: AppState): OnboardingWalletState {
val state = appState.onboardingWalletState
val backupState = state.backupState
return when (action) {
is GlobalAction.Onboarding -> ReducerForGlobalAction.reduce(action, state)
is BackupAction.BackupFinished -> {
state.copy(
step = if (action.userWalletId != null) {
step = if (action.userWalletId != null && backupState.startedSource == BackupStartedSource.Onboarding) {
OnboardingWalletStep.ManageTokens
} else {
OnboardingWalletStep.Done
@ -50,7 +51,10 @@ private fun internalReduce(action: Action, appState: AppState): OnboardingWallet
}
is OnboardingManageTokensAction.CurrenciesSaved -> state.copy(step = OnboardingWalletStep.Done)
is OnboardingWalletAction.WalletSaved -> state.copy(
step = OnboardingWalletStep.ManageTokens,
step = when (backupState.startedSource) {
BackupStartedSource.Onboarding -> OnboardingWalletStep.ManageTokens
BackupStartedSource.CreateBackup -> OnboardingWalletStep.Done
},
userWalletId = action.userWalletId,
)
is OnboardingWalletAction.Done -> state.copy(step = OnboardingWalletStep.Done)
@ -69,6 +73,7 @@ private object ReducerForGlobalAction {
backupState = state.backupState.copy(
maxBackupCards = MAX_BACKUP_CARDS,
canSkipBackup = action.canSkipBackup,
startedSource = action.source,
),
isRingOnboarding = action.scanResponse.cardTypesResolver.isRing(),
)
@ -106,6 +111,7 @@ private object BackupReducer {
backupStep = BackupStep.InitBackup,
maxBackupCards = 2,
canSkipBackup = state.canSkipBackup,
startedSource = state.startedSource,
)
BackupAction.StartAddingPrimaryCard -> state.copy(backupStep = BackupStep.ScanOriginCard)
BackupAction.StartAddingBackupCards -> state.copy(backupStep = BackupStep.AddBackupCards)

View file

@ -79,8 +79,13 @@ data class BackupState(
val isInterruptedBackup: Boolean = false,
val showBtnLoading: Boolean = false,
val hasBackupError: Boolean = false,
val startedSource: BackupStartedSource = BackupStartedSource.Onboarding,
)
enum class BackupStartedSource {
Onboarding, CreateBackup
}
enum class AccessCodeError {
CodeTooShort, CodesDoNotMatch
}

View file

@ -207,8 +207,8 @@ class OnboardingWalletFragment :
}
override fun newState(state: OnboardingWalletState) {
if (activity == null || view == null) return
Handler(Looper.getMainLooper()).post {
if (activity == null || view == null) return@post
animator.updateBackupState(state.backupState)
requireActivity().invalidateOptionsMenu()