fix(android): tapping a Cuprate mode starts the node #126
3 changed files with 106 additions and 18 deletions
fix(android): tapping a Cuprate mode starts the node
All checks were successful
android-ci / android (pull_request) Successful in 12m50s
All checks were successful
android-ci / android (pull_request) Successful in 12m50s
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.
commit
3868452a4a
|
|
@ -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).
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue