Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/src/main/java/com/brainwallet/ui/BrainwalletActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.brainwallet.ui.screens.inputwords.InputWordsViewModel.Companion.LEGAC
import com.brainwallet.ui.screens.inputwords.InputWordsViewModel.Companion.LEGACY_DIALOG_WIPE_ALERT
import com.brainwallet.ui.screens.inputwords.InputWordsViewModel.Companion.LEGACY_EFFECT_RESET_PIN
import com.brainwallet.ui.screens.yourseedproveit.YourSeedProveItViewModel.Companion.LEGACY_EFFECT_ON_PAPERKEY_PROVED
import com.brainwallet.ui.screens.yourseedwords.YourSeedWordsViewModel.Companion.LEGACY_EFFECT_ON_SAVED_PAPERKEY
import com.brainwallet.ui.theme.BrainwalletAppTheme
import com.brainwallet.util.EventBus
import com.brainwallet.wallet.BRWalletManager
Expand Down Expand Up @@ -114,10 +113,6 @@ class BrainwalletActivity : BRActivity() {
}
}

LEGACY_EFFECT_ON_SAVED_PAPERKEY -> {
PostAuth.getInstance().onPhraseProveAuth(this, false)
}

LEGACY_EFFECT_ON_PAPERKEY_PROVED -> {
BRSharedPrefs.putPhraseWroteDown(this@BrainwalletActivity, true)
LegacyNavigation.startBreadActivity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ sealed class YourSeedProveItEvent {
) : YourSeedProveItEvent()

data class OnDropSeedWordItem(
val index: Int,
val expectedWord: String,
val actualWord: String
) : YourSeedProveItEvent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fun YourSeedProveItScreen(
verticalArrangement = Arrangement.spacedBy(horizontalVerticalSpacing.dp),
maxItemsInEachRow = maxItemsPerRow
) {
state.correctSeedWords.entries.forEachIndexed { index, (expectedWord, actualWord) ->
state.correctSeedWords.values.forEachIndexed { index, (expectedWord, actualWord) ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!
@andhikayuana to be clear, the 12 seed words do not have to be unique....there can be duplicates.


val label = if (expectedWord != actualWord && actualWord.isEmpty()) {
"${index + 1}"
Expand All @@ -173,6 +173,7 @@ fun YourSeedProveItScreen(

viewModel.onEvent(
YourSeedProveItEvent.OnDropSeedWordItem(
index = index,
expectedWord = expectedWord,
actualWord = text.toString()
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.brainwallet.ui.screens.yourseedproveit

data class YourSeedProveItState(
val correctSeedWords: Map<String, String> = mapOf(),
val correctSeedWords: Map<Int, SeedWordItem> = emptyMap(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this allow dupes @andhikayuana ? There can be duplicates in a seed phrase

val shuffledSeedWords: List<String> = emptyList(),
val orderCorrected: Boolean = false,
)

data class SeedWordItem(
val expected: String,
val actual: String = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,31 @@ class YourSeedProveItViewModel : BrainwalletViewModel<YourSeedProveItEvent>() {
when (event) {
is YourSeedProveItEvent.OnLoad -> _state.update {
it.copy(
correctSeedWords = event.seedWords.associateWith { "" },
correctSeedWords = event.seedWords.mapIndexed { index, word ->
index to SeedWordItem(expected = word)
}.toMap(),
shuffledSeedWords = event.seedWords.shuffled()
)
}

is YourSeedProveItEvent.OnDropSeedWordItem -> _state.update {
val correctSeedWords = it.correctSeedWords.toMutableMap().apply {
this[event.expectedWord] = event.actualWord
}
val correctSeedWords = it.correctSeedWords.map { (index, seedWordItem) ->
if (index == event.index && seedWordItem.expected == event.expectedWord) {
index to seedWordItem.copy(actual = event.actualWord)
} else {
index to seedWordItem
}
}.toMap()

it.copy(
correctSeedWords = correctSeedWords,
orderCorrected = correctSeedWords.all { (expectedWord, actualWord) -> expectedWord == actualWord }
orderCorrected = correctSeedWords.all { (_, seedWordItem) -> seedWordItem.expected == seedWordItem.actual }
)
}

YourSeedProveItEvent.OnClear -> _state.update {
it.copy(
correctSeedWords = it.correctSeedWords.mapValues { "" }
correctSeedWords = it.correctSeedWords.mapValues { SeedWordItem(expected = it.value.expected) }
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.brainwallet.ui.screens.yourseedwords

sealed class YourSeedWordsEvent {
object OnSavedItClick : YourSeedWordsEvent()
data class OnSavedItClick(val seedWords: List<String>) : YourSeedWordsEvent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand Down Expand Up @@ -51,6 +52,15 @@ fun YourSeedWordsScreen(
val leadingCopyPadding = 16
val detailLineHeight = 28

LaunchedEffect(Unit) {
viewModel.uiEffect.collect { effect ->
when (effect) {
is UiEffect.Navigate -> onNavigate.invoke(effect)
else -> Unit
}
}
}

BrainwalletScaffold(
topBar = {
BrainwalletTopAppBar(
Expand Down Expand Up @@ -122,7 +132,7 @@ fun YourSeedWordsScreen(

LargeButton(
onClick = {
viewModel.onEvent(YourSeedWordsEvent.OnSavedItClick)
viewModel.onEvent(YourSeedWordsEvent.OnSavedItClick(seedWords))
},
) {
Text(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package com.brainwallet.ui.screens.yourseedwords

import androidx.lifecycle.viewModelScope
import com.brainwallet.navigation.Route
import com.brainwallet.navigation.UiEffect
import com.brainwallet.ui.BrainwalletViewModel
import com.brainwallet.util.EventBus
import kotlinx.coroutines.launch

class YourSeedWordsViewModel : BrainwalletViewModel<YourSeedWordsEvent>() {

override fun onEvent(event: YourSeedWordsEvent) {
when (event) {
YourSeedWordsEvent.OnSavedItClick -> viewModelScope.launch {
EventBus.emit(EventBus.Event.Message(LEGACY_EFFECT_ON_SAVED_PAPERKEY))
is YourSeedWordsEvent.OnSavedItClick -> viewModelScope.launch {
sendUiEffect(UiEffect.Navigate(destinationRoute = Route.YourSeedProveIt(event.seedWords)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andhikayuana thanks for the quick turn around but all of these changes are in the screens before the error occurs (YourSeedProveIt). Can you explain how this fixes the problem?

}
}
}

companion object {
const val LEGACY_EFFECT_ON_SAVED_PAPERKEY = "onSavedPaperKey"
}
}