[#1020] Re-enable fixture wallets in debug

- The debug with Alice’s and Ben’s fixture wallets from the Zcash SDK is visible only in debug mode. UI tests and production are not impacted.
- It provides a quick way to import an existing wallet for developers while building or testing the app
- Closes #1020
- The debug menu with fixture wallet was partially hidden by PR #1004
This commit is contained in:
Honza Rychnovský 2023-10-23 15:18:02 +02:00 committed by GitHub
parent 95da1b8e86
commit ab7117e458
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 122 additions and 57 deletions

View File

@ -27,9 +27,11 @@ class ShortOnboardingTestSetup(
fun DefaultContent() {
ZcashTheme {
ShortOnboarding(
showWelcomeAnim = false, // It's fine to test the screen UI after the welcome animation
isDebugMenuEnabled = false, // Debug only UI state does not need to be tested
onImportWallet = { onImportWalletCallbackCount.incrementAndGet() },
onCreateWallet = { onCreateWalletCallbackCount.incrementAndGet() },
showWelcomeAnim = false, // It's fine to test the screen UI after the welcome animation
onFixtureWallet = {}
)
}
}

View File

@ -69,11 +69,11 @@ internal fun WrapOnboarding(
onboardingViewModel.setShowWelcomeAnimation(false)
}
val onFixtureWallet = {
val onFixtureWallet: (String) -> Unit = { seed ->
persistExistingWalletWithSeedPhrase(
activity.applicationContext,
walletViewModel,
SeedPhrase.new(WalletFixture.Alice.seedPhrase),
SeedPhrase.new(seed),
birthday = WalletFixture.Alice.getBirthday(ZcashNetwork.fromResources(activity.applicationContext))
)
}
@ -86,8 +86,10 @@ internal fun WrapOnboarding(
if (ConfigurationEntries.IS_SHORT_ONBOARDING_UX.getValue(RemoteConfig.current)) {
ShortOnboarding(
showWelcomeAnim = showWelcomeAnimation,
isDebugMenuEnabled = versionInfo.isDebuggable,
onImportWallet = onImportWallet,
onCreateWallet = onCreateWallet,
onFixtureWallet = onFixtureWallet
)
} else {
LongOnboarding(

View File

@ -37,6 +37,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import cash.z.ecc.android.sdk.fixture.WalletFixture
import co.electriccoin.zcash.ui.R
import co.electriccoin.zcash.ui.design.component.Body
import co.electriccoin.zcash.ui.design.component.GradientSurface
@ -77,7 +78,7 @@ fun LongOnboarding(
isDebugMenuEnabled: Boolean,
onImportWallet: () -> Unit,
onCreateWallet: () -> Unit,
onFixtureWallet: () -> Unit
onFixtureWallet: (seed: String) -> Unit
) {
val currentStage = onboardingState.current.collectAsStateWithLifecycle().value
Scaffold(
@ -100,7 +101,7 @@ fun LongOnboarding(
private fun OnboardingTopAppBar(
onboardingState: OnboardingState,
isDebugMenuEnabled: Boolean,
onFixtureWallet: () -> Unit
onFixtureWallet: (String) -> Unit
) {
val currentStage = onboardingState.current.collectAsStateWithLifecycle().value
@ -129,7 +130,9 @@ private fun OnboardingTopAppBar(
}
@Composable
private fun DebugMenu(onFixtureWallet: () -> Unit) {
private fun DebugMenu(
onFixtureWallet: (String) -> Unit
) {
Column {
var expanded by rememberSaveable { mutableStateOf(false) }
IconButton(onClick = { expanded = true }) {
@ -141,8 +144,12 @@ private fun DebugMenu(onFixtureWallet: () -> Unit) {
onDismissRequest = { expanded = false }
) {
DropdownMenuItem(
text = { Text("Import wallet with fixture seed phrase") },
onClick = onFixtureWallet
text = { Text("Import Alice's wallet") },
onClick = { onFixtureWallet(WalletFixture.Alice.seedPhrase) }
)
DropdownMenuItem(
text = { Text("Import Ben's wallet") },
onClick = { onFixtureWallet(WalletFixture.Ben.seedPhrase) }
)
}
}

View File

@ -18,11 +18,20 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.ColorPainter
@ -32,11 +41,13 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.zIndex
import cash.z.ecc.android.sdk.fixture.WalletFixture
import co.electriccoin.zcash.ui.R
import co.electriccoin.zcash.ui.design.MINIMAL_WEIGHT
import co.electriccoin.zcash.ui.design.component.GradientSurface
import co.electriccoin.zcash.ui.design.component.PrimaryButton
import co.electriccoin.zcash.ui.design.component.SecondaryButton
import co.electriccoin.zcash.ui.design.component.SmallTopAppBar
import co.electriccoin.zcash.ui.design.component.TitleLarge
import co.electriccoin.zcash.ui.design.theme.ZcashTheme
import co.electriccoin.zcash.ui.design.util.ScreenHeight
@ -49,9 +60,11 @@ private fun ShortOnboardingComposablePreview() {
ZcashTheme(forceDarkMode = false) {
GradientSurface {
ShortOnboarding(
showWelcomeAnim = false,
isDebugMenuEnabled = false,
onImportWallet = {},
onCreateWallet = {},
showWelcomeAnim = false,
onFixtureWallet = {}
)
}
}
@ -71,8 +84,10 @@ private fun ShortOnboardingComposablePreview() {
@Composable
fun ShortOnboarding(
showWelcomeAnim: Boolean,
isDebugMenuEnabled: Boolean,
onImportWallet: () -> Unit,
onCreateWallet: () -> Unit,
onFixtureWallet: (String) -> Unit
) {
Scaffold { paddingValues ->
val screenHeight = screenHeight()
@ -91,8 +106,10 @@ fun ShortOnboarding(
modifier = Modifier.zIndex(1f)
)
OnboardingMainContent(
isDebugMenuEnabled = isDebugMenuEnabled,
onImportWallet = onImportWallet,
onCreateWallet = onCreateWallet,
onFixtureWallet = onFixtureWallet,
modifier = Modifier
.padding(
top = paddingValues.calculateTopPadding() + ZcashTheme.dimens.spacingHuge,
@ -107,62 +124,99 @@ fun ShortOnboarding(
}
}
@Composable
private fun DebugMenu(
onFixtureWallet: (String) -> Unit
) {
Column {
var expanded by rememberSaveable { mutableStateOf(false) }
IconButton(onClick = { expanded = true }) {
Icon(Icons.Default.MoreVert, contentDescription = null)
}
DropdownMenu(
expanded = expanded,
onDismissRequest = { expanded = false }
) {
DropdownMenuItem(
text = { Text("Import Alice's wallet") },
onClick = { onFixtureWallet(WalletFixture.Alice.seedPhrase) }
)
DropdownMenuItem(
text = { Text("Import Ben's wallet") },
onClick = { onFixtureWallet(WalletFixture.Ben.seedPhrase) }
)
}
}
}
@Composable
private fun OnboardingMainContent(
isDebugMenuEnabled: Boolean,
onImportWallet: () -> Unit,
onCreateWallet: () -> Unit,
onFixtureWallet: (String) -> Unit,
modifier: Modifier = Modifier
) {
Column(
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painterResource(id = R.drawable.zashi_logo_without_text),
stringResource(R.string.zcash_logo_onboarding_content_description),
Modifier
.height(ZcashTheme.dimens.inScreenZcashLogoHeight)
.width(ZcashTheme.dimens.inScreenZcashLogoWidth)
Box {
SmallTopAppBar(
regularActions = {
if (isDebugMenuEnabled) {
DebugMenu(onFixtureWallet)
}
}
)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingDefault))
Image(
painterResource(id = R.drawable.zashi_text_logo),
""
)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingLarge))
TitleLarge(text = stringResource(R.string.onboarding_short_header), textAlign = TextAlign.Center)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingDefault))
Spacer(
modifier = Modifier
.fillMaxHeight()
.weight(MINIMAL_WEIGHT)
)
PrimaryButton(
onClick = onCreateWallet,
text = stringResource(R.string.onboarding_short_create_new_wallet),
outerPaddingValues = PaddingValues(
horizontal = ZcashTheme.dimens.spacingNone,
vertical = ZcashTheme.dimens.spacingSmall
),
)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingLarge))
SecondaryButton(
onImportWallet,
stringResource(R.string.onboarding_short_import_existing_wallet),
outerPaddingValues = PaddingValues(
horizontal = ZcashTheme.dimens.spacingNone,
vertical = ZcashTheme.dimens.spacingSmall
Column(
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painterResource(id = R.drawable.zashi_logo_without_text),
stringResource(R.string.zcash_logo_onboarding_content_description),
Modifier
.height(ZcashTheme.dimens.inScreenZcashLogoHeight)
.width(ZcashTheme.dimens.inScreenZcashLogoWidth)
)
)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingDefault))
Image(
painterResource(id = R.drawable.zashi_text_logo),
""
)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingLarge))
TitleLarge(text = stringResource(R.string.onboarding_short_header), textAlign = TextAlign.Center)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingDefault))
Spacer(
modifier = Modifier
.fillMaxHeight()
.weight(MINIMAL_WEIGHT)
)
PrimaryButton(
onClick = onCreateWallet,
text = stringResource(R.string.onboarding_short_create_new_wallet),
outerPaddingValues = PaddingValues(
horizontal = ZcashTheme.dimens.spacingNone,
vertical = ZcashTheme.dimens.spacingSmall
),
)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingLarge))
SecondaryButton(
onImportWallet,
stringResource(R.string.onboarding_short_import_existing_wallet),
outerPaddingValues = PaddingValues(
horizontal = ZcashTheme.dimens.spacingNone,
vertical = ZcashTheme.dimens.spacingSmall
)
)
}
}
}