From 3868452a4a0fb26fdbdedbf1c97e8d6e4c610cb4 Mon Sep 17 00:00:00 2001 From: agent Date: Sat, 19 Sep 2026 14:33:20 -0400 Subject: [PATCH] fix(android): tapping a Cuprate mode starts the node Selecting mainnet pruned only persisted ChainConfig, so the screen updated the storage line and nothing else. Store, then Start when the storage floor allows. Filled button is the stored choice. --- .../onionwire/ui/WalletChildStatusText.kt | 24 ++++++ .../siriusdevops/onionwire/ui/WalletScreen.kt | 74 ++++++++++++++----- .../onionwire/ui/WalletChildStatusTextTest.kt | 26 +++++++ 3 files changed, 106 insertions(+), 18 deletions(-) diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletChildStatusText.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletChildStatusText.kt index 57ee94b..ebbbd5d 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletChildStatusText.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletChildStatusText.kt @@ -394,6 +394,30 @@ fun chainStorageBlockedReason( } } +enum class CuprateMode { + MainnetPruned, + MainnetFull, + Testnet, +} + +fun selectedCuprateMode(inProcess: Boolean, mainnet: Boolean, prune: Boolean): CuprateMode? = + when { + !inProcess -> null + !mainnet -> CuprateMode.Testnet + prune -> CuprateMode.MainnetPruned + else -> CuprateMode.MainnetFull + } + +/** + * Tapping a mode used to only persist `ChainConfig`, which looked like a no-op + * besides the storage line. Start when the storage floor would allow Start and + * a launch is not already in flight. + */ +fun shouldStartAfterSelectingChain( + storageBlocked: String?, + starting: Boolean, +): Boolean = storageBlocked == null && !starting + /** * Bytes as a screen-sized string. Binary units (a "GB" that is really a GiB is how * a store that needs 3 GiB ends up on a device with 2.8). diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletScreen.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletScreen.kt index e29576c..a67d8de 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletScreen.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletScreen.kt @@ -258,6 +258,23 @@ fun WalletScreen( scope.launch { vm.setInProcessCuprate(bins, mainnet, prune) .onFailure { daemonError = it.message ?: it.toString() } + .onSuccess { + // The mode buttons used to only persist the choice, + // which read as a no-op besides the storage line. + // Start is still the core launch; tapping a mode + // fires it when the storage gate would allow Start. + if (shouldStartAfterSelectingChain( + chainStorageBlockedReason( + vm.chainFreeBytes(), + mainnet = mainnet, + prune = prune, + ), + starting = starting, + ) + ) { + vm.startWalletChild() + } + } } }, starting = starting, @@ -734,30 +751,34 @@ private fun WalletChildCard( ) { Text("Receive-only") } } - // The third chain source. Never a default: selecting it is what stores - // `ChainChoice.InProcessCuprate`, and the warning below is what the user - // reads before Start. + // Tapping a mode stores it and, when the storage floor allows, + // starts the node. Filled = the stored choice. Spacer(Modifier.height(8.dp)) - OutlinedButton( + val mode = selectedCuprateMode( + inProcess = inProcess, + mainnet = chain?.mainnet == true, + prune = chain?.prune == true, + ) + CuprateModeButton( + label = "Mainnet pruned", + selected = mode == CuprateMode.MainnetPruned, + testTag = "wallet-chain-mainnet-pruned", onClick = { onInProcessNode(true, true) }, - modifier = Modifier - .fillMaxWidth() - .testTag("wallet-chain-mainnet-pruned"), - ) { Text("Mainnet pruned") } + ) Spacer(Modifier.height(4.dp)) - OutlinedButton( + CuprateModeButton( + label = "Mainnet full", + selected = mode == CuprateMode.MainnetFull, + testTag = "wallet-chain-mainnet-full", onClick = { onInProcessNode(true, false) }, - modifier = Modifier - .fillMaxWidth() - .testTag("wallet-chain-mainnet-full"), - ) { Text("Mainnet full") } + ) Spacer(Modifier.height(4.dp)) - OutlinedButton( + CuprateModeButton( + label = "Testnet (experimental)", + selected = mode == CuprateMode.Testnet, + testTag = "wallet-chain-in-process", onClick = { onInProcessNode(false, false) }, - modifier = Modifier - .fillMaxWidth() - .testTag("wallet-chain-in-process"), - ) { Text("Testnet (experimental)") } + ) if (inProcess) { Spacer(Modifier.height(8.dp)) @@ -836,6 +857,23 @@ private fun WalletChildCard( } } +@Composable +private fun CuprateModeButton( + label: String, + selected: Boolean, + testTag: String, + onClick: () -> Unit, +) { + val modifier = Modifier + .fillMaxWidth() + .testTag(testTag) + if (selected) { + Button(onClick = onClick, modifier = modifier) { Text(label) } + } else { + OutlinedButton(onClick = onClick, modifier = modifier) { Text(label) } + } +} + /** * The SDK record as the pure model `WalletChildStatusText.kt` renders. Field for * field, nothing inferred. diff --git a/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletChildStatusTextTest.kt b/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletChildStatusTextTest.kt index f6cec47..7627175 100644 --- a/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletChildStatusTextTest.kt +++ b/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletChildStatusTextTest.kt @@ -391,6 +391,32 @@ class WalletChildStatusTextTest { assertTrue(why!!, why.contains("280.0 GiB")) } + @Test + fun selecting_pruned_highlights_that_mode() { + assertEquals( + CuprateMode.MainnetPruned, + selectedCuprateMode(inProcess = true, mainnet = true, prune = true), + ) + assertEquals( + CuprateMode.MainnetFull, + selectedCuprateMode(inProcess = true, mainnet = true, prune = false), + ) + assertEquals( + CuprateMode.Testnet, + selectedCuprateMode(inProcess = true, mainnet = false, prune = false), + ) + assertNull(selectedCuprateMode(inProcess = false, mainnet = true, prune = true)) + } + + @Test + fun selecting_a_mode_starts_unless_storage_or_an_in_flight_start_blocks_it() { + assertTrue(shouldStartAfterSelectingChain(storageBlocked = null, starting = false)) + assertFalse( + shouldStartAfterSelectingChain(storageBlocked = "Not enough space", starting = false), + ) + assertFalse(shouldStartAfterSelectingChain(storageBlocked = null, starting = true)) + } + @Test fun the_storage_line_reports_the_measured_number() { val line = chainStorageLine(41L * 1024 * 1024 * 1024)