ui: hero wallet card and node card, and the status copy behind them (plan P4)

The wallet tab was nine equal boxes: a balance card, a daemon card, and then
four outlined twins (Invoice/Tip, Create/Import) pushed below the fold under a
wall of grey helper text. This rebuilds it as two cards.

Hero card. While no wallet file is open the card says "No Wallet Active" with
the plan's subtitle and puts Create Wallet (primary) / Import Wallet
(secondary) first, with Saved wallets in the card header. Once a wallet is
open the balance is the headline at 28sp bold with a sync-state pill, then the
gated receive address and its QR, then Receive / Invoice and Send / Tip, and a
destructive Lock Wallet. Creating and importing a further wallet stay reachable
in both states, and so does invoicing in the no-wallet state: the core resolves
a payee address from the profile, so hiding the action there would drop a path
that works ("no receive address - set profile xmr or ONIONWIRE_WALLET_RPC" is
the both-missing case). A tip really does need the wallet, so it appears only
when one is open.

Node card. The raw "connecting . in-process mainnet pruned . node starting .
sync 485253/3794383" line is replaced by a status sentence, a percentage, a 6dp
progress track and "Block 485,253 of 3,794,383" with the free disk on the
right; the full line is still the header's contentDescription, so a screen
reader loses nothing. The three stacked mode buttons become one segmented
control, Remote vs On-Device is a second one, and the lifecycle is a single
context-aware control (Start Node and Wallet, or Stop Node while it runs)
instead of a permanently disabled twin. Every raw paragraph (no binary, no
wallet open, start blocked, core error) is now an AlertBanner.

Fail-closed rules are unchanged and now tested: target_height == 0 prints no
percentage (it is "no target reported", never "caught up", which is what
Cuprate reports at the tip), a height past the target clamps at 100.0%, and an
unrecognised state is never green. The wallet off / err sentinels still come
back from the core untouched; only their display changed, to "No Wallet Loaded"
and "Balance unavailable".

Deliberate, and named in the handoff: WalletScreen drops its onBack parameter
because Wallet is a top-level tab now (MainActivity updated; Chats and Settings
already have no back affordance), and OwSegmentedControl gains an optional
testTags list - additive, defaulting to empty, so no existing call site
changes.
This commit is contained in:
agent 2026-10-29 01:01:39 -04:00
commit 1d7cbd8503
No known key found for this signature in database
5 changed files with 1162 additions and 732 deletions

View file

@ -192,9 +192,11 @@ private fun ReadyGraph(vm: WireViewModel, ready: Phase.Ready, keepAliveNote: Str
}
composable(Routes.Wallet) {
// A top-level tab, so no back chevron — same shape as the
// Chats and Node & Settings destinations. The catalogue
// sub-screen still gets one from its own top bar.
WalletScreen(
vm = vm,
onBack = { nav.popBackStack() },
onOpenWallets = { nav.navigate(Routes.Wallets) },
)
}

View file

@ -5,7 +5,7 @@ import com.siriusdevops.onionwire.wallet.WalletChildBinaryPaths
import java.util.Locale
/**
* One snapshot of the app-owned wallet child, as the wallet screen sees it.
* One snapshot of the app-owned wallet process, as the wallet screen sees it.
*
* A plain mirror of the fields `WalletChildStatus` carries over UniFFI
* (`state`, `running`, `configured`, `chain_source`, `last_error`) — the same
@ -97,7 +97,7 @@ sealed interface WalletChildPhase {
data object Unread : WalletChildPhase {
override val testTag: String = "child-unread"
override val label: String = "reading…"
override val contentDescription: String = "Reading the wallet child status"
override val contentDescription: String = "Reading the wallet status"
override val live: Boolean = false
override val dead: Boolean = false
}
@ -106,7 +106,7 @@ sealed interface WalletChildPhase {
data object Off : WalletChildPhase {
override val testTag: String = "child-off"
override val label: String = "off"
override val contentDescription: String = "The wallet child is off"
override val contentDescription: String = "The wallet is off"
override val live: Boolean = false
override val dead: Boolean = false
}
@ -116,7 +116,7 @@ sealed interface WalletChildPhase {
override val testTag: String = "child-connecting"
override val label: String = "connecting"
override val contentDescription: String =
"The wallet child is up; its wallet RPC has not answered yet"
"The wallet is starting; its RPC has not answered yet"
override val live: Boolean = true
override val dead: Boolean = false
}
@ -135,7 +135,7 @@ sealed interface WalletChildPhase {
data object Ready : WalletChildPhase {
override val testTag: String = "child-ready"
override val label: String = "ready"
override val contentDescription: String = "The wallet child is ready"
override val contentDescription: String = "The wallet is ready"
override val live: Boolean = true
override val dead: Boolean = false
}
@ -144,7 +144,7 @@ sealed interface WalletChildPhase {
data class Exited(val reason: String?) : WalletChildPhase {
override val testTag: String = "child-exited"
override val label: String = "exited"
override val contentDescription: String = "The wallet child exited"
override val contentDescription: String = "The wallet process exited"
override val live: Boolean = false
override val dead: Boolean = true
}
@ -158,7 +158,7 @@ sealed interface WalletChildPhase {
override val testTag: String = "child-unrecognised"
override val label: String = "unknown (${shortSendReason(raw, UNRECOGNISED_BUDGET)})"
override val contentDescription: String =
"The wallet child reported a state this build does not know"
"The wallet reported a state this build does not know"
override val live: Boolean = false
override val dead: Boolean = false
}
@ -336,25 +336,26 @@ const val ONION_NEEDS_ARTI_NOTICE: String =
"A .onion daemon needs the arti SOCKS child, which this build does not bundle."
/** Shown while the first `wallet_status()` read is still in flight. */
const val READING_CHILD_NOTICE: String = "Reading the wallet child status…"
const val READING_CHILD_NOTICE: String = "Reading the wallet status…"
const val STARTING_CHILD_NOTICE: String =
"Start is running. Status stays off until the on-device node answers — that can take a minute, and is not a dead button."
/**
* The caveat the on-device node is offered with, **before** Start.
* The alert banner the on-device node is offered with, **before** Start.
*
* Cuprate's own user book says *"do NOT use cuprated for any serious purposes"*,
* its `monerod` RPC parity is incomplete (Cuprate issue #278, and the four gaps
* measured in this repo are in `docs/cuprate-launch-spike.md`), and the daemon
* this app launches is pinned to **testnet** (`src/cuprate.rs`). One sentence, not
* a glyph: the choice is opt-in and never a default, and a user who reads only
* this line still knows what they picked.
* measured in this repo are in `docs/cuprate-launch-spike.md`), and mainnet is
* unvalidated. The title is the banner's; the two sentences are the body — one
* copy of the caveat, never a second one elsewhere on the screen, so the two
* can never drift apart.
*/
const val CUPRATE_PREPRODUCTION_WARNING: String =
"On-device node is Cuprate, which is pre-production: its own user book says do NOT use " +
"cuprated for any serious purposes, mainnet is unvalidated, and its monerod RPC parity " +
"is incomplete (Cuprate issue #278). Try the in-process path; do not hold funds on it."
const val CUPRATE_ON_DEVICE_TITLE: String = "Experimental On-Device Node (Cuprate)"
const val CUPRATE_ON_DEVICE_BODY: String =
"Pre-production software with incomplete RPC parity (#278). Do not use for significant " +
"funds. Mainnet is unvalidated, and Cuprate's own user book says do NOT use cuprated " +
"for any serious purposes."
/**
* This build was compiled without the `cuprate-daemon` feature, so the stored
@ -463,6 +464,131 @@ fun formatBytes(bytes: Long): String = when {
else -> "$bytes B"
}
/**
* A block height with thousands separators: `3794383` → `3,794,383`.
*
* Hand-grouped rather than `String.format("%,d")` on purpose: the grouped
* format is locale-dependent (some locales use a period or a non-breaking
* space), and a block height is a number in a monospace column, not prose. The
* screen and its test must print the same string everywhere.
*/
fun formatBlockCount(blocks: ULong): String {
val digits = blocks.toString()
val out = StringBuilder(digits.length + digits.length / 3)
digits.forEachIndexed { i, c ->
if (i > 0 && (digits.length - i) % 3 == 0) out.append(',')
out.append(c)
}
return out.toString()
}
/**
* What the node card's progress header renders for one height / target pair.
*
* [percentText] and [blockText] are null when there is nothing honest to say —
* and `target == 0` is exactly that: the daemon reporting **no target** is not
* evidence of being caught up (`src/wallet.rs` returns `0` for a height it does
* not have, and Cuprate omits the target even at the tip). A percentage invented
* from a zero target would read as progress; an unknown target is said in words.
*/
data class SyncProgress(
/** 0f..1f of the track to fill. `0f` whenever the target is unknown. */
val fraction: Float,
/** `12.8%`, or null when the daemon reported no target. */
val percentText: String?,
/** `Block 485,253 of 3,794,383`, or null when neither number is known. */
val blockText: String?,
)
fun syncProgress(height: ULong, target: ULong): SyncProgress {
if (height == 0uL && target == 0uL) return SyncProgress(0f, null, null)
if (target == 0uL) {
return SyncProgress(
fraction = 0f,
percentText = null,
blockText = "Block ${formatBlockCount(height)} of an unknown target",
)
}
val fraction = (height.toDouble() / target.toDouble()).coerceIn(0.0, 1.0)
return SyncProgress(
fraction = fraction.toFloat(),
percentText = String.format(Locale.US, "%.1f%%", fraction * 100.0),
blockText = "Block ${formatBlockCount(height)} of ${formatBlockCount(target)}",
)
}
/**
* The balance line, with the core's two sentinels translated into words.
*
* `walletBalance()` does not throw: it answers `off` (no chain source is
* configured at all) or `err` (configured, but the read failed — no wallet file
* open, or the process is down) and a formatted amount otherwise. Printing
* either sentinel raw is what put the string `wallet off` on the wallet screen;
* printing the same word for both is worse, because they are fixed in different
* places. The sentinels themselves are the core's contract and are not touched
* here — this is the display only.
*/
fun noWalletBalanceHeadline(balance: String?): String = when (balance) {
null -> "…"
"off" -> "No Wallet Loaded"
"err" -> "Balance unavailable"
else -> balance
}
/** `Mainnet Pruned` / `Mainnet Full` / `Testnet` — the three stored modes, as words. */
fun chainModeLabel(mainnet: Boolean, prune: Boolean): String = when {
!mainnet -> "Testnet"
prune -> "Mainnet Pruned"
else -> "Mainnet Full"
}
/**
* How the node card's header reads. [tone] is the status dot's colour class, not
* a decoration: it is the caller's statement about the core's own word.
*/
enum class NodeStatusTone {
/** Nothing is running, and nothing is wrong. */
Idle,
/** Up, or on its way up. */
Busy,
/** Answered and at the tip. */
Good,
/** A state the app cannot read, or a process that is gone. */
Bad,
}
data class NodeStatusHead(val title: String, val tone: NodeStatusTone)
/**
* The header sentence for the node card, from the core's `state` alone.
*
* Fail-closed exactly as [walletChildPhase] is: an unrecognised state gets
* [NodeStatusTone.Bad] and never reads as ready. A running child that has not
* answered is `Connecting…`, not `Ready` — the RPC has not spoken yet.
*/
fun nodeStatusHead(
input: WalletChildInput?,
inProcess: Boolean = false,
mainnet: Boolean = false,
prune: Boolean = false,
): NodeStatusHead {
val mode = if (inProcess) " (${chainModeLabel(mainnet, prune)})" else ""
return when (walletChildPhase(input)) {
WalletChildPhase.Unread -> NodeStatusHead("Reading wallet status", NodeStatusTone.Idle)
WalletChildPhase.Off ->
NodeStatusHead(if (inProcess) "Node Idle$mode" else "Wallet Offline", NodeStatusTone.Idle)
WalletChildPhase.Connecting -> NodeStatusHead("Connecting…", NodeStatusTone.Busy)
WalletChildPhase.Syncing ->
NodeStatusHead(if (inProcess) "Syncing Node$mode" else "Syncing Wallet", NodeStatusTone.Busy)
WalletChildPhase.Ready -> NodeStatusHead("Wallet Ready", NodeStatusTone.Good)
is WalletChildPhase.Exited -> NodeStatusHead("Wallet Stopped", NodeStatusTone.Bad)
is WalletChildPhase.Unrecognised -> NodeStatusHead("Unknown wallet state", NodeStatusTone.Bad)
}
}
/**
* Why **Start** is not actionable, or `null` when it is.
*
@ -479,8 +605,11 @@ fun startBlockedReason(
bins.walletRpc == null -> NO_WALLET_RPC_MESSAGE
starting -> STARTING_CHILD_NOTICE
input == null -> READING_CHILD_NOTICE
input.running -> "The wallet child is already running."
!input.configured -> "No chain source yet: a wallet child needs a daemon to dial."
// Unreachable from the wallet screen: while the wallet runs the lifecycle
// control *is* Stop, so Start is never offered. Kept as a pure predicate so
// a stale status read cannot turn the one control into a no-op tap.
input.running -> "The wallet is already running."
!input.configured -> "No chain source yet: the wallet needs a daemon to dial."
// The stored source is the app's own node but this build has no daemon: the
// option is readable and unstoppable, so say it before the user presses Start.
input.chainInProcess && !input.nodeAvailable -> CUPRATE_NOT_IN_BUILD_NOTICE
@ -494,7 +623,7 @@ fun startBlockedReason(
*/
fun stopBlockedReason(input: WalletChildInput?): String? = when {
input == null -> READING_CHILD_NOTICE
!input.running -> "No wallet child is running."
!input.running -> "No wallet is running."
else -> null
}

View file

@ -17,6 +17,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.role
import androidx.compose.ui.semantics.selected
@ -42,6 +43,14 @@ fun OwSegmentedControl(
onSelect: (Int) -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
/**
* Optional per-segment `testTag`s, one per option. Additive: omitted (the
* default) leaves every existing call site byte-identical. It exists because
* a merged "Pruned / Full / Testnet" track has no per-value handle otherwise,
* and the wallet screen's tests address each segment by the tag it had when
* the three options were three stacked buttons.
*/
testTags: List<String?> = emptyList(),
) {
Row(
modifier = modifier
@ -67,12 +76,14 @@ fun OwSegmentedControl(
animationSpec = tween(durationMillis = 160),
label = "segment-text",
)
val tag = testTags.getOrNull(index)
Box(
modifier = Modifier
.weight(1f)
.height(36.dp)
.clip(RoundedCornerShape(9.dp))
.background(container)
.then(if (tag != null) Modifier.testTag(tag) else Modifier)
.clickable(enabled = enabled && !selected) { onSelect(index) }
.semantics {
role = Role.Tab

View file

@ -207,8 +207,8 @@ class WalletChildStatusTextTest {
@Test
fun stop_is_blocked_when_nothing_is_running() {
assertTrue(stopBlockedReason(input("off"))!!.contains("No wallet child"))
assertTrue(stopBlockedReason(input("exited"))!!.contains("No wallet child"))
assertTrue(stopBlockedReason(input("off"))!!.contains("No wallet is running"))
assertTrue(stopBlockedReason(input("exited"))!!.contains("No wallet is running"))
assertEquals(READING_CHILD_NOTICE, stopBlockedReason(null))
}
@ -397,7 +397,7 @@ class WalletChildStatusTextTest {
"a screen reader is told the same as the eye",
spoken.endsWith(walletChildLine(input)),
)
assertTrue("it is still a sentence", spoken.startsWith("The wallet child is up"))
assertTrue("it is still a sentence", spoken.startsWith("The wallet is starting"))
}
@Test
@ -417,14 +417,17 @@ class WalletChildStatusTextTest {
}
@Test
fun the_preproduction_warning_is_a_sentence_a_user_can_act_on() {
val warning = CUPRATE_PREPRODUCTION_WARNING
assertTrue("it names the software", warning.contains("Cuprate"))
assertTrue("it quotes the user book", warning.contains("do NOT use cuprated"))
assertTrue("it names the parity gap", warning.contains("Cuprate issue #278"))
assertTrue("it says mainnet is unvalidated", warning.contains("mainnet is unvalidated"))
assertTrue("it is a sentence, not a glyph", warning.trim().endsWith("."))
assertTrue("it is long enough to be a sentence", warning.length > 80)
fun the_on_device_banner_is_titled_and_says_what_it_costs() {
// The banner's title is the plan's exact string; the body keeps every
// honesty bound the old single-sentence warning carried.
assertEquals("Experimental On-Device Node (Cuprate)", CUPRATE_ON_DEVICE_TITLE)
val body = CUPRATE_ON_DEVICE_BODY
assertTrue("it names the software", body.contains("Cuprate"))
assertTrue("it names the parity gap", body.contains("#278"))
assertTrue("it quotes the user book", body.contains("do NOT use cuprated"))
assertTrue("it says mainnet is unvalidated", body.contains("Mainnet is unvalidated"))
assertTrue("it says not to hold funds", body.contains("Do not use for significant funds"))
assertTrue("it is a sentence, not a glyph", body.trim().endsWith("."))
}
// --- storage honesty ----------------------------------------------------
@ -519,4 +522,103 @@ class WalletChildStatusTextTest {
assertEquals("1.5 GiB", formatBytes(3L * 1024 * 1024 * 1024 / 2))
assertEquals("3.0 GiB", formatBytes(CHAIN_FREE_SPACE_FLOOR_BYTES))
}
// --- the node card's progress header (plan P4.3) -------------------------
@Test
fun block_counts_group_by_three_regardless_of_locale() {
assertEquals("0", formatBlockCount(0uL))
assertEquals("999", formatBlockCount(999uL))
assertEquals("1,000", formatBlockCount(1_000uL))
assertEquals("485,253", formatBlockCount(485_253uL))
assertEquals("3,794,383", formatBlockCount(3_794_383uL))
assertEquals("12,345,678", formatBlockCount(12_345_678uL))
}
@Test
fun the_progress_header_says_percent_and_formatted_blocks() {
val p = syncProgress(485_253uL, 3_794_383uL)
assertEquals("12.8%", p.percentText)
assertEquals("Block 485,253 of 3,794,383", p.blockText)
assertTrue("a fraction of the track", p.fraction > 0.12f && p.fraction < 0.13f)
}
@Test
fun a_caught_up_node_fills_the_track_and_does_not_overflow() {
val atTip = syncProgress(3_794_383uL, 3_794_383uL)
assertEquals("100.0%", atTip.percentText)
assertEquals(1f, atTip.fraction)
// A daemon one block ahead of the target it reported must not render
// 108% — the bar clamps and the text is the clamped number.
val ahead = syncProgress(4_100_000uL, 3_794_383uL)
assertEquals("100.0%", ahead.percentText)
assertEquals(1f, ahead.fraction)
}
@Test
fun an_unknown_target_is_never_a_percentage() {
// `target_height == 0` is "the daemon reported no target" — Cuprate
// omits it even at the tip. Printing 100% there would claim synced.
val p = syncProgress(4_549uL, 0uL)
assertNull("no percent from a zero target", p.percentText)
assertEquals(0f, p.fraction)
assertEquals("Block 4,549 of an unknown target", p.blockText)
assertFalse("no percent string leaks", p.blockText!!.contains("%"))
}
@Test
fun no_numbers_means_no_progress_row() {
val p = syncProgress(0uL, 0uL)
assertNull(p.percentText)
assertNull(p.blockText)
assertEquals(0f, p.fraction)
}
@Test
fun the_three_modes_are_named_the_way_the_stored_choice_reads() {
assertEquals("Mainnet Pruned", chainModeLabel(mainnet = true, prune = true))
assertEquals("Mainnet Full", chainModeLabel(mainnet = true, prune = false))
assertEquals("Testnet", chainModeLabel(mainnet = false, prune = false))
}
@Test
fun the_node_header_never_reads_ready_without_the_cores_word() {
assertEquals("Wallet Offline", nodeStatusHead(input("off", configured = false)).title)
assertEquals("Connecting…", nodeStatusHead(input("connecting", running = true)).title)
assertEquals(NodeStatusTone.Busy, nodeStatusHead(input("connecting", running = true)).tone)
assertTrue(
"a running child that has not answered is not ready",
nodeStatusHead(input("connecting", running = true)).tone != NodeStatusTone.Good,
)
assertEquals(NodeStatusTone.Good, nodeStatusHead(input("ready", running = true)).tone)
assertEquals(NodeStatusTone.Bad, nodeStatusHead(input("mining", running = true)).tone)
assertEquals(
"an unknown state is never green",
NodeStatusTone.Bad,
nodeStatusHead(input("mining", running = true)).tone,
)
assertEquals("Wallet Stopped", nodeStatusHead(input("exited")).title)
assertEquals("Reading wallet status", nodeStatusHead(null).title)
}
@Test
fun the_node_header_names_the_mode_only_for_the_on_device_node() {
assertEquals(
"Syncing Node (Mainnet Pruned)",
nodeStatusHead(
node(state = "syncing", chainSource = "in-process mainnet pruned", nodeState = "syncing"),
inProcess = true,
mainnet = true,
prune = true,
).title,
)
assertEquals(
"Node Idle (Testnet)",
nodeStatusHead(input("off", configured = false), inProcess = true, mainnet = false).title,
)
assertEquals(
"Syncing Wallet",
nodeStatusHead(input("syncing", running = true, chainSource = "remote daemon")).title,
)
}
}