From 0aefa6a227b2672dcb167a5d427a3692c6795ecf Mon Sep 17 00:00:00 2001 From: Nikita Samoylov Date: Mon, 9 Dec 2024 13:53:07 +0300 Subject: [PATCH 1/9] AND-9375 Onboarding UI: texts on the trimming screen are cut off --- .../v2/done/impl/ui/OnboardingDone.kt | 2 + .../impl/child/backup/ui/MultiWalletBackup.kt | 5 +- .../chooseoption/ui/Wallet1ChooseOption.kt | 5 +- .../MultiWalletCreateWalletComponent.kt | 19 +++-- .../ui/MultiWalletCreateWallet.kt | 5 +- .../child/finalize/ui/MultiWalletFinalize.kt | 5 +- .../ui/MultiWalletSeedPhraseImport.kt | 77 ++++++++++--------- .../ui/MultiWalletSeedPhraseWords.kt | 33 ++++---- .../ui/MultiWalletSeedPhraseWordsCheck.kt | 75 +++++++++--------- .../impl/ui/OnboardingMultiWallet.kt | 2 +- 10 files changed, 127 insertions(+), 101 deletions(-) diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/done/impl/ui/OnboardingDone.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/done/impl/ui/OnboardingDone.kt index 94393823fd..76069b61d4 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/done/impl/ui/OnboardingDone.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/done/impl/ui/OnboardingDone.kt @@ -10,6 +10,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.vectorResource +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.airbnb.lottie.compose.LottieAnimation @@ -59,6 +60,7 @@ internal fun OnboardingDone(onContinueClick: () -> Unit, modifier: Modifier = Mo text = stringResource(R.string.onboarding_subtitle_success_tangem_wallet_onboarding), style = TangemTheme.typography.body1, color = TangemTheme.colors.text.secondary, + textAlign = TextAlign.Center, ) SpacerH(72.dp) } diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/ui/MultiWalletBackup.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/ui/MultiWalletBackup.kt index 94e30e4752..04b7d75fdb 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/ui/MultiWalletBackup.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/ui/MultiWalletBackup.kt @@ -1,6 +1,8 @@ package com.tangem.features.onboarding.v2.multiwallet.impl.child.backup.ui import androidx.compose.foundation.layout.* +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment @@ -55,7 +57,8 @@ private fun ColumnScope.Content(state: MultiWalletBackupUM) { Column( Modifier .fillMaxWidth() - .padding(start = 32.dp, end = 32.dp, bottom = 74.dp) + .verticalScroll(rememberScrollState()) + .padding(start = 32.dp, end = 32.dp, bottom = 16.dp) .weight(1f), horizontalAlignment = Alignment.CenterHorizontally, ) { diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt index 5ca46f53f9..88d7b413d8 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt @@ -1,6 +1,8 @@ package com.tangem.features.onboarding.v2.multiwallet.impl.child.chooseoption.ui import androidx.compose.foundation.layout.* +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment @@ -26,7 +28,8 @@ fun Wallet1ChooseOption(onSkipClick: () -> Unit, onBackupClick: () -> Unit, modi Column( Modifier .fillMaxWidth() - .padding(start = 32.dp, end = 32.dp, bottom = 24.dp) + .verticalScroll(rememberScrollState()) + .padding(start = 32.dp, end = 32.dp, bottom = 16.dp) .weight(1f), horizontalAlignment = Alignment.CenterHorizontally, ) { diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/createwallet/MultiWalletCreateWalletComponent.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/createwallet/MultiWalletCreateWalletComponent.kt index 95b2c975db..99d24d2ab2 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/createwallet/MultiWalletCreateWalletComponent.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/createwallet/MultiWalletCreateWalletComponent.kt @@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.arkivanov.essenty.lifecycle.doOnStart import com.tangem.core.decompose.context.AppComponentContext import com.tangem.core.decompose.model.getOrCreateModel import com.tangem.core.ui.extensions.resourceReference @@ -25,17 +26,19 @@ internal class MultiWalletCreateWalletComponent( private val model: MultiWalletCreateWalletModel = getOrCreateModel(params) init { - params.innerNavigation.update { - it.copy( - stackSize = 2, - stackMaxSize = 8, + lifecycle.doOnStart { + params.innerNavigation.update { + it.copy( + stackSize = 2, + stackMaxSize = 8, + ) + } + + params.parentParams.titleProvider.changeTitle( + text = resourceReference(R.string.onboarding_create_wallet_header), ) } - params.parentParams.titleProvider.changeTitle( - text = resourceReference(R.string.onboarding_create_wallet_header), - ) - componentScope.launch { model.onDone.collect(onNextStep) } diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/createwallet/ui/MultiWalletCreateWallet.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/createwallet/ui/MultiWalletCreateWallet.kt index 6f02115fb9..b12194c47b 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/createwallet/ui/MultiWalletCreateWallet.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/createwallet/ui/MultiWalletCreateWallet.kt @@ -1,6 +1,8 @@ package com.tangem.features.onboarding.v2.multiwallet.impl.child.createwallet.ui import androidx.compose.foundation.layout.* +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment @@ -48,7 +50,8 @@ internal fun MultiWalletCreateWallet(state: MultiWalletCreateWalletUM, modifier: Column( Modifier .fillMaxWidth() - .padding(start = 32.dp, end = 32.dp, bottom = 24.dp) + .verticalScroll(rememberScrollState()) + .padding(start = 32.dp, end = 32.dp, bottom = 16.dp) .weight(1f), horizontalAlignment = Alignment.CenterHorizontally, ) { diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/finalize/ui/MultiWalletFinalize.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/finalize/ui/MultiWalletFinalize.kt index cfb3c07e2f..598e25862d 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/finalize/ui/MultiWalletFinalize.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/finalize/ui/MultiWalletFinalize.kt @@ -1,6 +1,8 @@ package com.tangem.features.onboarding.v2.multiwallet.impl.child.finalize.ui import androidx.compose.foundation.layout.* +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment @@ -27,7 +29,8 @@ internal fun MultiWalletFinalize(state: MultiWalletFinalizeUM, modifier: Modifie Column( Modifier .fillMaxWidth() - .padding(start = 32.dp, end = 32.dp, bottom = 74.dp) + .padding(start = 32.dp, end = 32.dp, bottom = 16.dp) + .verticalScroll(rememberScrollState()) .weight(1f), horizontalAlignment = Alignment.CenterHorizontally, ) { diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/seedphrase/ui/MultiWalletSeedPhraseImport.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/seedphrase/ui/MultiWalletSeedPhraseImport.kt index 62bcec98e5..540dd21625 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/seedphrase/ui/MultiWalletSeedPhraseImport.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/seedphrase/ui/MultiWalletSeedPhraseImport.kt @@ -55,49 +55,52 @@ internal fun MultiWalletSeedPhraseImport(state: MultiWalletSeedPhraseUM.Import, Column( modifier = Modifier .fillMaxSize() - .verticalScroll(rememberScrollState()), + .imePadding(), ) { - Text( - text = stringResource(id = R.string.onboarding_seed_import_message), - style = TangemTheme.typography.body1, - color = TangemTheme.colors.text.secondary, - textAlign = TextAlign.Center, - modifier = Modifier - .padding(start = 36.dp, end = 36.dp, top = 24.dp, bottom = 16.dp) - .fillMaxWidth(), - ) - - PhraseBlock( - state = state, - modifier = Modifier.padding(horizontal = 16.dp), - ) + Column( + Modifier + .verticalScroll(rememberScrollState()) + .weight(1f), + ) { + Text( + text = stringResource(id = R.string.onboarding_seed_import_message), + style = TangemTheme.typography.body1, + color = TangemTheme.colors.text.secondary, + textAlign = TextAlign.Center, + modifier = Modifier + .padding(start = 36.dp, end = 36.dp, top = 24.dp, bottom = 16.dp) + .fillMaxWidth(), + ) - OutlineTextFieldWithIcon( - modifier = modifier - .padding(horizontal = 16.dp) - .fillMaxWidth(), - value = state.passPhrase, - onValueChange = state.passPhraseChange, - iconResId = R.drawable.ic_information_24, - iconColor = TangemTheme.colors.icon.informative, - label = stringResource(id = R.string.common_passphrase), - placeholder = stringResource(id = R.string.send_optional_field), - onIconClick = state.onPassphraseInfoClick, - ) + PhraseBlock( + state = state, + modifier = Modifier.padding(horizontal = 16.dp), + ) - Box(Modifier.weight(1f)) { - PrimaryButtonIconEnd( - modifier = Modifier - .align(Alignment.BottomStart) - .padding(16.dp) + OutlineTextFieldWithIcon( + modifier = modifier + .padding(horizontal = 16.dp) .fillMaxWidth(), - text = stringResource(id = R.string.common_import), - iconResId = R.drawable.ic_tangem_24, - enabled = state.createWalletEnabled, - showProgress = state.createWalletProgress, - onClick = state.createWalletClick, + value = state.passPhrase, + onValueChange = state.passPhraseChange, + iconResId = R.drawable.ic_information_24, + iconColor = TangemTheme.colors.icon.informative, + label = stringResource(id = R.string.common_passphrase), + placeholder = stringResource(id = R.string.send_optional_field), + onIconClick = state.onPassphraseInfoClick, ) } + + PrimaryButtonIconEnd( + modifier = Modifier + .padding(16.dp) + .fillMaxWidth(), + text = stringResource(id = R.string.common_import), + iconResId = R.drawable.ic_tangem_24, + enabled = state.createWalletEnabled, + showProgress = state.createWalletProgress, + onClick = state.createWalletClick, + ) } val keyboard by keyboardAsState() diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/seedphrase/ui/MultiWalletSeedPhraseWords.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/seedphrase/ui/MultiWalletSeedPhraseWords.kt index 8e0ca4e7fc..fc055bc025 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/seedphrase/ui/MultiWalletSeedPhraseWords.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/seedphrase/ui/MultiWalletSeedPhraseWords.kt @@ -31,20 +31,26 @@ internal fun MultiWalletSeedPhraseWords( modifier: Modifier = Modifier, ) { Column(modifier.fillMaxSize()) { - SegmentSeedBlock( - modifier = Modifier.padding(vertical = 20.dp), - state = state, - ) + Column( + modifier = Modifier + .verticalScroll(rememberScrollState()) + .imePadding() + .weight(1f), + ) { + SegmentSeedBlock( + modifier = Modifier.padding(vertical = 20.dp), + state = state, + ) - TitleBlock(state) + TitleBlock(state) - SeedPhraseGridBlock( - mnemonicGridItems = state.words, - modifier = Modifier - .weight(1f) - .fillMaxWidth() - .padding(top = 20.dp, bottom = 32.dp), - ) + SeedPhraseGridBlock( + mnemonicGridItems = state.words, + modifier = Modifier + .fillMaxWidth() + .padding(top = 20.dp, bottom = 32.dp), + ) + } PrimaryButton( modifier = Modifier @@ -118,8 +124,7 @@ private fun TitleBlock(state: MultiWalletSeedPhraseUM.GenerateSeedPhrase, modifi @Composable private fun SeedPhraseGridBlock(mnemonicGridItems: ImmutableList, modifier: Modifier = Modifier) { VerticalGrid( - modifier = modifier - .verticalScroll(rememberScrollState()), + modifier = modifier, items = mnemonicGridItems, ) { item -> Row( diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/seedphrase/ui/MultiWalletSeedPhraseWordsCheck.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/seedphrase/ui/MultiWalletSeedPhraseWordsCheck.kt index f2743923be..3033c5cccf 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/seedphrase/ui/MultiWalletSeedPhraseWordsCheck.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/seedphrase/ui/MultiWalletSeedPhraseWordsCheck.kt @@ -5,7 +5,6 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.TextFieldValue @@ -48,48 +47,50 @@ internal fun MultiWalletSeedPhraseWordsCheck( Column( modifier = modifier .fillMaxSize() - .verticalScroll(rememberScrollState()), + .imePadding(), ) { - Text( - text = stringResource(R.string.onboarding_seed_user_validation_title), - style = TangemTheme.typography.h2, - color = TangemTheme.colors.text.primary1, - textAlign = TextAlign.Center, - modifier = Modifier - .padding(top = 48.dp, start = 36.dp, end = 36.dp, bottom = 16.dp) - .fillMaxWidth(), - ) - Text( - text = stringResource(R.string.onboarding_seed_user_validation_message), - style = TangemTheme.typography.body1, - color = TangemTheme.colors.text.secondary, - textAlign = TextAlign.Center, - modifier = Modifier - .padding(horizontal = 36.dp) - .fillMaxWidth(), - ) - - Fields( - state = state, - modifier = Modifier - .padding(vertical = 30.dp, horizontal = 16.dp), - ) - - Box( - Modifier.weight(1f), + Column( + Modifier + .verticalScroll(rememberScrollState()) + .weight(1f), ) { - PrimaryButtonIconEnd( + Text( + text = stringResource(R.string.onboarding_seed_user_validation_title), + style = TangemTheme.typography.h2, + color = TangemTheme.colors.text.primary1, + textAlign = TextAlign.Center, modifier = Modifier - .align(Alignment.BottomStart) - .padding(16.dp) + .padding(top = 48.dp, start = 36.dp, end = 36.dp, bottom = 16.dp) .fillMaxWidth(), - text = stringResource(id = R.string.onboarding_create_wallet_button_create_wallet), - iconResId = R.drawable.ic_tangem_24, - enabled = state.createWalletButtonEnabled, - showProgress = state.createWalletButtonProgress, - onClick = state.onCreateWalletButtonClick, + ) + Text( + text = stringResource(R.string.onboarding_seed_user_validation_message), + style = TangemTheme.typography.body1, + color = TangemTheme.colors.text.secondary, + textAlign = TextAlign.Center, + modifier = Modifier + .padding(horizontal = 36.dp) + .fillMaxWidth(), + ) + + Fields( + state = state, + modifier = Modifier + .padding(vertical = 30.dp, horizontal = 16.dp), ) } + + PrimaryButtonIconEnd( + modifier = Modifier + .padding(16.dp) + .imePadding() + .fillMaxWidth(), + text = stringResource(id = R.string.onboarding_create_wallet_button_create_wallet), + iconResId = R.drawable.ic_tangem_24, + enabled = state.createWalletButtonEnabled, + showProgress = state.createWalletButtonProgress, + onClick = state.onCreateWalletButtonClick, + ) } } diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/ui/OnboardingMultiWallet.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/ui/OnboardingMultiWallet.kt index 5f5b6b3cee..4eb0565862 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/ui/OnboardingMultiWallet.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/ui/OnboardingMultiWallet.kt @@ -49,9 +49,9 @@ internal fun OnboardingMultiWallet( url2 = state.artwork2Url, url3 = state.artwork3Url, modifier = Modifier - .weight(.56f) .padding(horizontal = 34.dp) .padding(top = 20.dp) + .weight(.36f) .fillMaxWidth(), state = artworksState, ) From 026c5bd284d56412008f0174d9e876d321e47873 Mon Sep 17 00:00:00 2001 From: Nikita Samoylov Date: Mon, 9 Dec 2024 14:43:43 +0300 Subject: [PATCH 2/9] AND-9373 Onboarding: You can abort the backup --- .../impl/DefaultOnboardingMultiWalletComponent.kt | 9 ++++++++- .../child/backup/MultiWalletBackupComponent.kt | 15 ++++++++++++++- .../child/backup/model/MultiWalletBackupModel.kt | 7 +++++++ .../finalize/MultiWalletFinalizeComponent.kt | 13 +++++++++++++ .../finalize/model/MultiWalletFinalizeModel.kt | 7 +++++++ 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/DefaultOnboardingMultiWalletComponent.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/DefaultOnboardingMultiWalletComponent.kt index bca30cb8dd..ff81575653 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/DefaultOnboardingMultiWalletComponent.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/DefaultOnboardingMultiWalletComponent.kt @@ -93,11 +93,14 @@ internal class DefaultOnboardingMultiWalletComponent @AssistedInject constructor ) val backButtonClickFlow = MutableSharedFlow() + override val innerNavigation: InnerNavigation = object : InnerNavigation { override val state = innerNavigationStateFlow override fun pop(onComplete: (Boolean) -> Unit) { - if (childStack.active.configuration == SeedPhrase) { + val config = childStack.active.configuration + + if (config == SeedPhrase || config == Finalize || config == AddBackupDevice) { componentScope.launch { backButtonClickFlow.emit(Unit) } } else { model.onBack() @@ -155,11 +158,15 @@ internal class DefaultOnboardingMultiWalletComponent @AssistedInject constructor AddBackupDevice -> MultiWalletBackupComponent( context = childContext, params = childParams, + backButtonClickFlow = backButtonClickFlow, + onBack = { model.onBack() }, onEvent = ::handleBackupComponentEvent, ) Finalize -> MultiWalletFinalizeComponent( context = childContext, params = childParams, + backButtonClickFlow = backButtonClickFlow, + onBack = { model.onBack() }, onEvent = ::handleFinalizeComponentEvent, ) Done -> error("Unexpected Done state") diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/MultiWalletBackupComponent.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/MultiWalletBackupComponent.kt index d84f7b7a63..a1cf3bc467 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/MultiWalletBackupComponent.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/MultiWalletBackupComponent.kt @@ -1,5 +1,6 @@ package com.tangem.features.onboarding.v2.multiwallet.impl.child.backup +import androidx.activity.compose.BackHandler import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier @@ -8,10 +9,11 @@ import com.tangem.core.decompose.context.AppComponentContext import com.tangem.core.decompose.model.getOrCreateModel import com.tangem.core.ui.extensions.resourceReference import com.tangem.features.onboarding.v2.impl.R -import com.tangem.features.onboarding.v2.multiwallet.impl.child.MultiWalletChildParams import com.tangem.features.onboarding.v2.multiwallet.impl.child.MultiWalletChildComponent +import com.tangem.features.onboarding.v2.multiwallet.impl.child.MultiWalletChildParams import com.tangem.features.onboarding.v2.multiwallet.impl.child.backup.model.MultiWalletBackupModel import com.tangem.features.onboarding.v2.multiwallet.impl.child.backup.ui.MultiWalletBackup +import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch @@ -19,6 +21,8 @@ import kotlinx.coroutines.launch class MultiWalletBackupComponent( context: AppComponentContext, params: MultiWalletChildParams, + backButtonClickFlow: SharedFlow, + onBack: () -> Unit, onEvent: (event: Event) -> Unit, ) : AppComponentContext by context, MultiWalletChildComponent { @@ -39,11 +43,20 @@ class MultiWalletBackupComponent( componentScope.launch { model.eventFlow.collect(onEvent) } + + componentScope.launch { + backButtonClickFlow.collect { model.onBack() } + } + + componentScope.launch { + model.onBackFlow.collect { onBack() } + } } @Composable override fun Content(modifier: Modifier) { val state by model.uiState.collectAsStateWithLifecycle() + BackHandler { model.onBack() } MultiWalletBackup( modifier = modifier, diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/model/MultiWalletBackupModel.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/model/MultiWalletBackupModel.kt index 32b36f068b..560240c7c6 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/model/MultiWalletBackupModel.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/model/MultiWalletBackupModel.kt @@ -59,6 +59,7 @@ class MultiWalletBackupModel @Inject constructor( val uiState: StateFlow = _uiState val eventFlow = MutableSharedFlow() + val onBackFlow = MutableSharedFlow() init { // for wallet 1 this event is sent in Wallet1ChooseOptionModel @@ -69,6 +70,12 @@ class MultiWalletBackupModel @Inject constructor( analyticsHandler.send(OnboardingEvent.Backup.Started) } + fun onBack() { + if (state.value.numberOfBackupCards == 0) { + modelScope.launch { onBackFlow.emit(Unit) } + } + } + private fun getInitState(): MultiWalletBackupUM { return MultiWalletBackupUM( title = resourceReference(R.string.onboarding_title_no_backup_cards), diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/finalize/MultiWalletFinalizeComponent.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/finalize/MultiWalletFinalizeComponent.kt index 4f476cebc7..f982a77345 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/finalize/MultiWalletFinalizeComponent.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/finalize/MultiWalletFinalizeComponent.kt @@ -1,5 +1,6 @@ package com.tangem.features.onboarding.v2.multiwallet.impl.child.finalize +import androidx.activity.compose.BackHandler import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier @@ -12,6 +13,7 @@ import com.tangem.features.onboarding.v2.multiwallet.impl.child.MultiWalletChild import com.tangem.features.onboarding.v2.multiwallet.impl.child.MultiWalletChildParams import com.tangem.features.onboarding.v2.multiwallet.impl.child.finalize.model.MultiWalletFinalizeModel import com.tangem.features.onboarding.v2.multiwallet.impl.child.finalize.ui.MultiWalletFinalize +import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch @@ -19,6 +21,8 @@ import kotlinx.coroutines.launch internal class MultiWalletFinalizeComponent( context: AppComponentContext, params: MultiWalletChildParams, + backButtonClickFlow: SharedFlow, + onBack: () -> Unit, onEvent: (Event) -> Unit, ) : AppComponentContext by context, MultiWalletChildComponent { @@ -40,12 +44,21 @@ internal class MultiWalletFinalizeComponent( onEvent(it) } } + + componentScope.launch { + backButtonClickFlow.collect { model.onBack() } + } + componentScope.launch { + model.onBackFlow.collect { onBack() } + } } @Composable override fun Content(modifier: Modifier) { val state by model.uiState.collectAsStateWithLifecycle() + BackHandler { model.onBack() } + MultiWalletFinalize( state = state, modifier = modifier, diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/finalize/model/MultiWalletFinalizeModel.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/finalize/model/MultiWalletFinalizeModel.kt index a355484963..fb1c7ccf59 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/finalize/model/MultiWalletFinalizeModel.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/finalize/model/MultiWalletFinalizeModel.kt @@ -59,6 +59,7 @@ internal class MultiWalletFinalizeModel @Inject constructor( private var walletHasBackupError = false val uiState = _uiState.asStateFlow() + val onBackFlow = MutableSharedFlow() val onEvent = MutableSharedFlow() @@ -72,6 +73,12 @@ internal class MultiWalletFinalizeModel @Inject constructor( } } + fun onBack() { + if (uiState.value.scanPrimary) { + modelScope.launch { onBackFlow.emit(Unit) } + } + } + private fun getInitialState(): MultiWalletFinalizeUM { val backupService = backupServiceHolder.backupService.get() ?: return MultiWalletFinalizeUM() val initialStep = getInitialStep() From 6b65f178c69863e1ece8d94a59bcbdf797e3040a Mon Sep 17 00:00:00 2001 From: Nikita Samoylov Date: Mon, 9 Dec 2024 20:44:04 +0300 Subject: [PATCH 3/9] fixed based on tester's comments --- .../impl/child/backup/MultiWalletBackupComponent.kt | 13 ------------- .../child/backup/model/MultiWalletBackupModel.kt | 7 ------- 2 files changed, 20 deletions(-) diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/MultiWalletBackupComponent.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/MultiWalletBackupComponent.kt index a1cf3bc467..91b88a7030 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/MultiWalletBackupComponent.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/MultiWalletBackupComponent.kt @@ -1,6 +1,5 @@ package com.tangem.features.onboarding.v2.multiwallet.impl.child.backup -import androidx.activity.compose.BackHandler import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier @@ -13,7 +12,6 @@ import com.tangem.features.onboarding.v2.multiwallet.impl.child.MultiWalletChild import com.tangem.features.onboarding.v2.multiwallet.impl.child.MultiWalletChildParams import com.tangem.features.onboarding.v2.multiwallet.impl.child.backup.model.MultiWalletBackupModel import com.tangem.features.onboarding.v2.multiwallet.impl.child.backup.ui.MultiWalletBackup -import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch @@ -21,8 +19,6 @@ import kotlinx.coroutines.launch class MultiWalletBackupComponent( context: AppComponentContext, params: MultiWalletChildParams, - backButtonClickFlow: SharedFlow, - onBack: () -> Unit, onEvent: (event: Event) -> Unit, ) : AppComponentContext by context, MultiWalletChildComponent { @@ -43,20 +39,11 @@ class MultiWalletBackupComponent( componentScope.launch { model.eventFlow.collect(onEvent) } - - componentScope.launch { - backButtonClickFlow.collect { model.onBack() } - } - - componentScope.launch { - model.onBackFlow.collect { onBack() } - } } @Composable override fun Content(modifier: Modifier) { val state by model.uiState.collectAsStateWithLifecycle() - BackHandler { model.onBack() } MultiWalletBackup( modifier = modifier, diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/model/MultiWalletBackupModel.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/model/MultiWalletBackupModel.kt index 560240c7c6..32b36f068b 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/model/MultiWalletBackupModel.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/backup/model/MultiWalletBackupModel.kt @@ -59,7 +59,6 @@ class MultiWalletBackupModel @Inject constructor( val uiState: StateFlow = _uiState val eventFlow = MutableSharedFlow() - val onBackFlow = MutableSharedFlow() init { // for wallet 1 this event is sent in Wallet1ChooseOptionModel @@ -70,12 +69,6 @@ class MultiWalletBackupModel @Inject constructor( analyticsHandler.send(OnboardingEvent.Backup.Started) } - fun onBack() { - if (state.value.numberOfBackupCards == 0) { - modelScope.launch { onBackFlow.emit(Unit) } - } - } - private fun getInitState(): MultiWalletBackupUM { return MultiWalletBackupUM( title = resourceReference(R.string.onboarding_title_no_backup_cards), From 649413ada6c63649f16d8713b7feebc18ebe70f4 Mon Sep 17 00:00:00 2001 From: Nikita Samoylov Date: Mon, 9 Dec 2024 20:56:12 +0300 Subject: [PATCH 4/9] fixed based on tester's comments --- .../multiwallet/impl/DefaultOnboardingMultiWalletComponent.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/DefaultOnboardingMultiWalletComponent.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/DefaultOnboardingMultiWalletComponent.kt index ff81575653..9eb3b20cdb 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/DefaultOnboardingMultiWalletComponent.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/DefaultOnboardingMultiWalletComponent.kt @@ -100,7 +100,7 @@ internal class DefaultOnboardingMultiWalletComponent @AssistedInject constructor override fun pop(onComplete: (Boolean) -> Unit) { val config = childStack.active.configuration - if (config == SeedPhrase || config == Finalize || config == AddBackupDevice) { + if (config == SeedPhrase || config == Finalize) { componentScope.launch { backButtonClickFlow.emit(Unit) } } else { model.onBack() @@ -158,8 +158,6 @@ internal class DefaultOnboardingMultiWalletComponent @AssistedInject constructor AddBackupDevice -> MultiWalletBackupComponent( context = childContext, params = childParams, - backButtonClickFlow = backButtonClickFlow, - onBack = { model.onBack() }, onEvent = ::handleBackupComponentEvent, ) Finalize -> MultiWalletFinalizeComponent( From d33d955e7e7b673dcdf57c218659ccb33adfb938 Mon Sep 17 00:00:00 2001 From: Nikita Samoylov Date: Mon, 9 Dec 2024 20:59:19 +0300 Subject: [PATCH 5/9] fixed based on tester's comments 2 --- .../impl/child/chooseoption/Wallet1ChooseOptionComponent.kt | 2 +- .../impl/child/chooseoption/ui/Wallet1ChooseOption.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/Wallet1ChooseOptionComponent.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/Wallet1ChooseOptionComponent.kt index 130af731e3..f9bcc2a8f4 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/Wallet1ChooseOptionComponent.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/Wallet1ChooseOptionComponent.kt @@ -32,7 +32,7 @@ class Wallet1ChooseOptionComponent( } params.parentParams.titleProvider.changeTitle( - text = resourceReference(R.string.onboarding_create_wallet_header), + text = resourceReference(R.string.onboarding_getting_started), ) componentScope.launch { diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt index 88d7b413d8..7c9d3dd375 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt @@ -34,7 +34,7 @@ fun Wallet1ChooseOption(onSkipClick: () -> Unit, onBackupClick: () -> Unit, modi horizontalAlignment = Alignment.CenterHorizontally, ) { Text( - text = stringResource(R.string.onboarding_create_wallet_header), + text = stringResource(R.string.onboarding_wallet_info_title_first), style = TangemTheme.typography.h2, color = TangemTheme.colors.text.primary1, textAlign = TextAlign.Center, @@ -42,7 +42,7 @@ fun Wallet1ChooseOption(onSkipClick: () -> Unit, onBackupClick: () -> Unit, modi ) Text( - text = stringResource(R.string.onboarding_create_wallet_body), + text = stringResource(R.string.onboarding_wallet_info_subtitle_first), style = TangemTheme.typography.body1, color = TangemTheme.colors.text.secondary, textAlign = TextAlign.Center, From 00742d4c12c2022a4457c09300dbad93c6857f14 Mon Sep 17 00:00:00 2001 From: Nikita Samoylov Date: Mon, 9 Dec 2024 21:15:54 +0300 Subject: [PATCH 6/9] fixed based on tester's comments 2 --- .../chooseoption/ui/Wallet1ChooseOption.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt index 7c9d3dd375..eb56d9257e 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt @@ -9,10 +9,13 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import com.tangem.core.ui.components.PrimaryButton import com.tangem.core.ui.components.PrimaryButtonIconEnd import com.tangem.core.ui.components.SecondaryButton import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview import com.tangem.features.onboarding.v2.impl.R @Composable @@ -50,11 +53,10 @@ fun Wallet1ChooseOption(onSkipClick: () -> Unit, onBackupClick: () -> Unit, modi ) } - PrimaryButtonIconEnd( + PrimaryButton( modifier = Modifier .padding(start = 16.dp, end = 16.dp, bottom = 12.dp) .fillMaxWidth(), - iconResId = R.drawable.ic_tangem_24, text = stringResource(R.string.onboarding_button_backup_now), onClick = onBackupClick, ) @@ -68,3 +70,15 @@ fun Wallet1ChooseOption(onSkipClick: () -> Unit, onBackupClick: () -> Unit, modi ) } } + +@Preview(showBackground = true) +@Composable +private fun Preview() { + TangemThemePreview { + Wallet1ChooseOption( + onSkipClick = {}, + onBackupClick = {}, + modifier = Modifier.fillMaxSize(), + ) + } +} \ No newline at end of file From 37e911546a850a43f1ca2b04c125020c01e94bc5 Mon Sep 17 00:00:00 2001 From: Nikita Samoylov Date: Mon, 9 Dec 2024 21:16:02 +0300 Subject: [PATCH 7/9] fixed based on tester's comments 2 --- .../impl/child/chooseoption/ui/Wallet1ChooseOption.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt index eb56d9257e..fa69a2428a 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt @@ -12,7 +12,6 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.tangem.core.ui.components.PrimaryButton -import com.tangem.core.ui.components.PrimaryButtonIconEnd import com.tangem.core.ui.components.SecondaryButton import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview @@ -81,4 +80,4 @@ private fun Preview() { modifier = Modifier.fillMaxSize(), ) } -} \ No newline at end of file +} From f14efc5de8f3c2739f145653be691462da070db0 Mon Sep 17 00:00:00 2001 From: Nikita Samoylov Date: Mon, 9 Dec 2024 21:19:33 +0300 Subject: [PATCH 8/9] AND-9371 Bugfix: Onboarding: on shiba cards you can create a wallet without backup --- .../Wallet1ChooseOptionComponent.kt | 1 + .../model/Wallet1ChooseOptionModel.kt | 3 +++ .../chooseoption/ui/Wallet1ChooseOption.kt | 24 ++++++++++++------- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/Wallet1ChooseOptionComponent.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/Wallet1ChooseOptionComponent.kt index f9bcc2a8f4..30b29f6ea1 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/Wallet1ChooseOptionComponent.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/Wallet1ChooseOptionComponent.kt @@ -45,6 +45,7 @@ class Wallet1ChooseOptionComponent( @Composable override fun Content(modifier: Modifier) { Wallet1ChooseOption( + canSkipBackup = model.canSkipBackup, onBackupClick = { onNextStep(OnboardingMultiWalletState.Step.AddBackupDevice) }, diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/model/Wallet1ChooseOptionModel.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/model/Wallet1ChooseOptionModel.kt index 9444bfc052..de8457912a 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/model/Wallet1ChooseOptionModel.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/model/Wallet1ChooseOptionModel.kt @@ -5,6 +5,7 @@ import com.tangem.core.decompose.di.ComponentScoped import com.tangem.core.decompose.model.Model import com.tangem.core.decompose.model.ParamsContainer import com.tangem.domain.card.repository.CardRepository +import com.tangem.domain.common.TapWorkarounds.canSkipBackup import com.tangem.domain.models.scan.ScanResponse import com.tangem.domain.wallets.builder.UserWalletBuilder import com.tangem.domain.wallets.models.UserWallet @@ -36,6 +37,8 @@ internal class Wallet1ChooseOptionModel @Inject constructor( analyticsHandler.send(OnboardingEvent.Backup.ScreenOpened) } + val canSkipBackup = params.multiWalletState.value.currentScanResponse.card.canSkipBackup + fun onSkipClick() { if (skipClicked) return skipClicked = true diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt index fa69a2428a..6dc5a87058 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/chooseoption/ui/Wallet1ChooseOption.kt @@ -18,7 +18,12 @@ import com.tangem.core.ui.res.TangemThemePreview import com.tangem.features.onboarding.v2.impl.R @Composable -fun Wallet1ChooseOption(onSkipClick: () -> Unit, onBackupClick: () -> Unit, modifier: Modifier = Modifier) { +fun Wallet1ChooseOption( + canSkipBackup: Boolean, + onSkipClick: () -> Unit, + onBackupClick: () -> Unit, + modifier: Modifier = Modifier, +) { Column( modifier = modifier .fillMaxSize() @@ -60,13 +65,15 @@ fun Wallet1ChooseOption(onSkipClick: () -> Unit, onBackupClick: () -> Unit, modi onClick = onBackupClick, ) - SecondaryButton( - modifier = Modifier - .padding(start = 16.dp, end = 16.dp, bottom = 16.dp) - .fillMaxWidth(), - text = stringResource(R.string.onboarding_button_skip_backup), - onClick = onSkipClick, - ) + if (canSkipBackup) { + SecondaryButton( + modifier = Modifier + .padding(start = 16.dp, end = 16.dp, bottom = 16.dp) + .fillMaxWidth(), + text = stringResource(R.string.onboarding_button_skip_backup), + onClick = onSkipClick, + ) + } } } @@ -75,6 +82,7 @@ fun Wallet1ChooseOption(onSkipClick: () -> Unit, onBackupClick: () -> Unit, modi private fun Preview() { TangemThemePreview { Wallet1ChooseOption( + canSkipBackup = true, onSkipClick = {}, onBackupClick = {}, modifier = Modifier.fillMaxSize(), From 0504503354c2fb67f52a4274ec5d76ce2e69ff80 Mon Sep 17 00:00:00 2001 From: Nikita Samoylov Date: Tue, 10 Dec 2024 20:12:51 +0300 Subject: [PATCH 9/9] AND-9372 Onboarding: on old cards you can create a wallet with backup --- .../features/onboarding/OnboardingHelper.kt | 2 +- .../model/MultiWalletCreateWalletModel.kt | 52 +++++++++++++++---- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingHelper.kt b/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingHelper.kt index 6c4dc4fb91..0367c0f829 100644 --- a/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingHelper.kt +++ b/app/src/main/java/com/tangem/tap/features/onboarding/OnboardingHelper.kt @@ -70,7 +70,7 @@ object OnboardingHelper { fun whereToNavigate(scanResponse: ScanResponse): AppRoute { val newOnboardingSupportTypes = scanResponse.productType == ProductType.Wallet2 || scanResponse.productType == ProductType.Ring || - scanResponse.productType == ProductType.Wallet + scanResponse.productType == ProductType.Wallet // AppRoute.OnboardingOther is also supported if (store.inject(DaggerGraphState::onboardingV2FeatureToggles).isOnboardingV2Enabled && newOnboardingSupportTypes ) { diff --git a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/createwallet/model/MultiWalletCreateWalletModel.kt b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/createwallet/model/MultiWalletCreateWalletModel.kt index 0c0ddbfc40..4ebb024b60 100644 --- a/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/createwallet/model/MultiWalletCreateWalletModel.kt +++ b/features/onboarding-v2/impl/src/main/kotlin/com/tangem/features/onboarding/v2/multiwallet/impl/child/createwallet/model/MultiWalletCreateWalletModel.kt @@ -11,12 +11,17 @@ import com.tangem.domain.card.repository.CardRepository import com.tangem.domain.feedback.GetCardInfoUseCase import com.tangem.domain.feedback.SendFeedbackEmailUseCase import com.tangem.domain.feedback.models.FeedbackEmailType +import com.tangem.domain.models.scan.ScanResponse +import com.tangem.domain.wallets.builder.UserWalletBuilder +import com.tangem.domain.wallets.models.UserWallet +import com.tangem.domain.wallets.usecase.GenerateWalletNameUseCase +import com.tangem.domain.wallets.usecase.SaveWalletUseCase import com.tangem.features.onboarding.v2.impl.R import com.tangem.features.onboarding.v2.multiwallet.impl.analytics.OnboardingEvent import com.tangem.features.onboarding.v2.multiwallet.impl.child.MultiWalletChildParams import com.tangem.features.onboarding.v2.multiwallet.impl.child.createwallet.ui.state.MultiWalletCreateWalletUM import com.tangem.features.onboarding.v2.multiwallet.impl.common.ui.resetCardDialog -import com.tangem.features.onboarding.v2.multiwallet.impl.model.OnboardingMultiWalletState +import com.tangem.features.onboarding.v2.multiwallet.impl.model.OnboardingMultiWalletState.Step import com.tangem.sdk.api.TangemSdkManager import com.tangem.utils.coroutines.CoroutineDispatcherProvider import kotlinx.coroutines.flow.MutableSharedFlow @@ -36,6 +41,8 @@ internal class MultiWalletCreateWalletModel @Inject constructor( private val getCardInfoUseCase: GetCardInfoUseCase, private val cardRepository: CardRepository, private val analyticsHandler: AnalyticsEventHandler, + private val generateWalletNameUseCase: GenerateWalletNameUseCase, + private val saveWalletUseCase: SaveWalletUseCase, ) : Model() { private val params = paramsContainer.require() @@ -61,7 +68,7 @@ internal class MultiWalletCreateWalletModel @Inject constructor( showOtherOptionsButton = params.parentParams.withSeedPhraseFlow, onOtherOptionsClick = { modelScope.launch { - onDone.emit(OnboardingMultiWalletState.Step.SeedPhrase) + onDone.emit(Step.SeedPhrase) } }, dialog = null, @@ -69,7 +76,7 @@ internal class MultiWalletCreateWalletModel @Inject constructor( ) val uiState: StateFlow = _uiState - val onDone = MutableSharedFlow() + val onDone = MutableSharedFlow() init { analyticsHandler.send(OnboardingEvent.CreateWallet.ScreenOpened) @@ -96,13 +103,14 @@ internal class MultiWalletCreateWalletModel @Inject constructor( cardRepository.startCardActivation(cardId = result.data.card.cardId) - if (params.parentParams.withSeedPhraseFlow) { - onDone.emit(OnboardingMultiWalletState.Step.AddBackupDevice) - } else { - onDone.emit(OnboardingMultiWalletState.Step.ChooseBackupOption) - } - analyticsHandler.send(OnboardingEvent.CreateWallet.WalletCreatedSuccessfully()) + + val cardDoesNotSupportBackup = result.data.card.settings.isBackupAllowed.not() + when { + cardDoesNotSupportBackup -> createWalletAndNavigateBackWithDone() + params.parentParams.withSeedPhraseFlow -> onDone.emit(Step.AddBackupDevice) + else -> onDone.emit(Step.ChooseBackupOption) + } } is CompletionResult.Failure -> { @@ -115,6 +123,32 @@ internal class MultiWalletCreateWalletModel @Inject constructor( } } + private fun createWalletAndNavigateBackWithDone() { + modelScope.launch { + val scanResponse = params.multiWalletState.value.currentScanResponse + + val userWallet = createUserWallet(scanResponse) + saveWalletUseCase(userWallet, canOverride = true) + .onRight { + cardRepository.finishCardActivation(scanResponse.card.cardId) + + // save user wallet for manage tokens screen + params.multiWalletState.update { + it.copy(resultUserWallet = userWallet) + } + + onDone.emit(Step.Done) + } + } + } + + private suspend fun createUserWallet(scanResponse: ScanResponse): UserWallet { + return requireNotNull( + value = UserWalletBuilder(scanResponse, generateWalletNameUseCase).build(), + lazyMessage = { "User wallet not created" }, + ) + } + private fun handleActivationError() { _uiState.update { state -> state.copy(