Updated on 2026-08-14
This commit is contained in:
parent
f345835792
commit
d4eb48822a
6 changed files with 58 additions and 13 deletions
|
|
@ -0,0 +1,8 @@
|
|||
package com.tangem.utils.extensions
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
fun Int.isEven(): Boolean = this % 2 == 0
|
||||
|
||||
fun Int.isOdd(): Boolean = !this.isEven()
|
||||
|
|
@ -9,6 +9,7 @@ plugins {
|
|||
|
||||
dependencies {
|
||||
/** Core modules */
|
||||
implementation(project(":common"))
|
||||
implementation(project(":core:featuretoggles"))
|
||||
implementation(project(":core:datasource"))
|
||||
implementation(project(":core:analytics"))
|
||||
|
|
|
|||
|
|
@ -36,10 +36,15 @@ data class AboutState(
|
|||
)
|
||||
|
||||
data class YourSeedPhraseState(
|
||||
val mnemonicComponents: ImmutableList<String> = persistentListOf(),
|
||||
val mnemonicGridItems: ImmutableList<MnemonicGridItem> = persistentListOf(),
|
||||
val buttonContinue: ButtonState,
|
||||
)
|
||||
|
||||
data class MnemonicGridItem(
|
||||
val index: Int,
|
||||
val mnemonic: String,
|
||||
)
|
||||
|
||||
data class CheckSeedPhraseState(
|
||||
val tvSecondPhrase: TextFieldState,
|
||||
val tvSeventhPhrase: TextFieldState,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.tangem.feature.onboarding.presentation.wallet2.model.ButtonState
|
|||
import com.tangem.feature.onboarding.presentation.wallet2.model.CheckSeedPhraseState
|
||||
import com.tangem.feature.onboarding.presentation.wallet2.model.ImportSeedPhraseState
|
||||
import com.tangem.feature.onboarding.presentation.wallet2.model.IntroState
|
||||
import com.tangem.feature.onboarding.presentation.wallet2.model.MnemonicGridItem
|
||||
import com.tangem.feature.onboarding.presentation.wallet2.model.OnboardingSeedPhraseState
|
||||
import com.tangem.feature.onboarding.presentation.wallet2.model.OnboardingSeedPhraseStep
|
||||
import com.tangem.feature.onboarding.presentation.wallet2.model.TextFieldState
|
||||
|
|
@ -111,9 +112,9 @@ class StateBuilder(
|
|||
|
||||
fun mnemonicGenerated(
|
||||
uiState: OnboardingSeedPhraseState,
|
||||
mnemonicComponents: ImmutableList<String>,
|
||||
mnemonicGridItems: ImmutableList<MnemonicGridItem>,
|
||||
): OnboardingSeedPhraseState {
|
||||
return updateMnemonicComponents(uiState, mnemonicComponents)
|
||||
return updateMnemonicComponents(uiState, mnemonicGridItems)
|
||||
.copy(
|
||||
step = OnboardingSeedPhraseStep.YourSeedPhrase,
|
||||
aboutState = uiState.aboutState.copy(
|
||||
|
|
@ -129,10 +130,10 @@ class StateBuilder(
|
|||
|
||||
fun updateMnemonicComponents(
|
||||
uiState: OnboardingSeedPhraseState,
|
||||
phraseList: ImmutableList<String>,
|
||||
mnemonicGridItems: ImmutableList<MnemonicGridItem>,
|
||||
): OnboardingSeedPhraseState = uiState.copy(
|
||||
yourSeedPhraseState = uiState.yourSeedPhraseState.copy(
|
||||
mnemonicComponents = phraseList,
|
||||
mnemonicGridItems = mnemonicGridItems,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ import com.tangem.core.ui.components.PrimaryButton
|
|||
import com.tangem.core.ui.components.SpacerW32
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.feature.onboarding.R
|
||||
import com.tangem.feature.onboarding.presentation.wallet2.model.MnemonicGridItem
|
||||
import com.tangem.feature.onboarding.presentation.wallet2.model.YourSeedPhraseState
|
||||
import com.tangem.feature.onboarding.presentation.wallet2.ui.components.Description
|
||||
import com.tangem.feature.onboarding.presentation.wallet2.ui.components.OnboardingActionBlock
|
||||
|
|
@ -50,7 +51,7 @@ fun YourSeedPhraseScreen(
|
|||
Box(
|
||||
modifier = Modifier.weight(1f),
|
||||
) {
|
||||
PhraseGreedBlock(state.mnemonicComponents)
|
||||
PhraseGreedBlock(state.mnemonicGridItems)
|
||||
}
|
||||
|
||||
Box {
|
||||
|
|
@ -69,26 +70,27 @@ fun YourSeedPhraseScreen(
|
|||
}
|
||||
|
||||
@Composable
|
||||
private fun PhraseGreedBlock(phraseList: ImmutableList<String>) {
|
||||
private fun PhraseGreedBlock(mnemonicGridItems: ImmutableList<MnemonicGridItem>) {
|
||||
LazyVerticalGrid(
|
||||
columns = GridCells.Fixed(2),
|
||||
) {
|
||||
this.items(
|
||||
count = phraseList.size,
|
||||
count = mnemonicGridItems.size,
|
||||
) { index ->
|
||||
Row(
|
||||
modifier = Modifier.padding(all = TangemTheme.dimens.size8),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
val item = mnemonicGridItems[index]
|
||||
SpacerW32()
|
||||
Text(
|
||||
modifier = Modifier.width(TangemTheme.dimens.size40),
|
||||
text = "${index + 1}.",
|
||||
text = "${item.index}.",
|
||||
style = TangemTheme.typography.body2,
|
||||
color = TangemTheme.colors.text.secondary,
|
||||
)
|
||||
Text(
|
||||
text = phraseList[index],
|
||||
text = item.mnemonic,
|
||||
style = TangemTheme.typography.button,
|
||||
color = TangemTheme.colors.text.primary1,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.tangem.feature.onboarding.presentation.wallet2.model.AboutUiAction
|
|||
import com.tangem.feature.onboarding.presentation.wallet2.model.CheckSeedPhraseUiAction
|
||||
import com.tangem.feature.onboarding.presentation.wallet2.model.ImportSeedPhraseUiAction
|
||||
import com.tangem.feature.onboarding.presentation.wallet2.model.IntroUiAction
|
||||
import com.tangem.feature.onboarding.presentation.wallet2.model.MnemonicGridItem
|
||||
import com.tangem.feature.onboarding.presentation.wallet2.model.OnboardingSeedPhraseState
|
||||
import com.tangem.feature.onboarding.presentation.wallet2.model.OnboardingSeedPhraseStep
|
||||
import com.tangem.feature.onboarding.presentation.wallet2.model.SeedPhraseField
|
||||
|
|
@ -21,7 +22,10 @@ import com.tangem.feature.onboarding.presentation.wallet2.model.YourSeedPhraseUi
|
|||
import com.tangem.feature.onboarding.presentation.wallet2.ui.StateBuilder
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import com.tangem.utils.coroutines.Debouncer
|
||||
import com.tangem.utils.extensions.isEven
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -123,7 +127,6 @@ class SeedPhraseViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
private fun buttonCreateWalletWithSeedPhraseClick() {
|
||||
buttonGenerateSeedPhraseClick()
|
||||
}
|
||||
|
||||
private fun buttonOtherOptionsClick() {
|
||||
|
|
@ -141,14 +144,39 @@ class SeedPhraseViewModel @Inject constructor(
|
|||
updateUi { uiBuilder.generateMnemonicComponents(uiState) }
|
||||
interactor.generateMnemonic()
|
||||
.onSuccess { mnemonic ->
|
||||
updateUi { uiBuilder.mnemonicGenerated(uiState, mnemonic.mnemonicComponents) }
|
||||
val mnemonicGridItems = generateMnemonicGridList(mnemonic.mnemonicComponents)
|
||||
updateUi { uiBuilder.mnemonicGenerated(uiState, mnemonicGridItems.toImmutableList()) }
|
||||
}
|
||||
.onFailure {
|
||||
// show error
|
||||
// TODO: show error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun generateMnemonicGridList(mnemonicComponents: List<String>): ImmutableList<MnemonicGridItem> {
|
||||
val size = mnemonicComponents.size
|
||||
val splitIndex = if (size.isEven()) size / 2 else size / 2 + 1
|
||||
val leftColumn = mnemonicComponents.subList(0, splitIndex)
|
||||
val rightColumn = mnemonicComponents.subList(splitIndex, size)
|
||||
|
||||
val mnemonicGridItems = mutableListOf<MnemonicGridItem>()
|
||||
for (index in 0 until splitIndex) {
|
||||
if (index <= leftColumn.size) mnemonicGridItems.add(
|
||||
MnemonicGridItem(
|
||||
index = index + 1,
|
||||
mnemonic = leftColumn[index],
|
||||
),
|
||||
)
|
||||
if (index < rightColumn.size) mnemonicGridItems.add(
|
||||
MnemonicGridItem(
|
||||
index = index + splitIndex + 1,
|
||||
mnemonic = rightColumn[index],
|
||||
),
|
||||
)
|
||||
}
|
||||
return mnemonicGridItems.toImmutableList()
|
||||
}
|
||||
|
||||
private fun buttonImportSeedPhraseClick() {
|
||||
viewModelScope.launchSingle {
|
||||
updateUi { uiBuilder.changeStep(uiState, OnboardingSeedPhraseStep.ImportSeedPhrase) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue