android: show the chain daemon's sync height on the wallet status line
All checks were successful
android-ci / android (pull_request) Successful in 12m45s
All checks were successful
android-ci / android (pull_request) Successful in 12m45s
The SDK surface from the rust-dev parent (#129) carries `WalletChildStatus.height` and `target_height` (Rust `u64` → generated Kotlin `ULong`), so the wallet status line can say how far the chain daemon has got instead of only naming it. * `WalletChildInput` mirrors both fields as `ULong` — checked against the generated `uniffi.onionwire_sdk.WalletChildStatus`, not assumed. Defaults stay `0uL` so every existing fixture is unchanged. * `walletChildLine` appends ` · sync h/t` after the source and the `node` segment, before the error em-dash, and only when either value is non-zero: `0/0` is unknown (probe failed, daemon not up), not `0%`, and a zero target still prints as `/0`. No percent, no progress bar, no ETA. * `WalletScreen.toInput()` copies both fields field-for-field; the status row's screen-reader sentence moved into `walletChildStatusDescription`, which carries the same `sync h/t` the eye reads. One line, still no second widget. * Tests cover the three sync cases plus the spoken row; the old exact-line assertions (`off · receive-only`, `connecting · local node`, `ready · remote onion daemon`) are untouched. `:app:testDebugUnitTest`: 114 tests, 0 failures. * `android/CUPRATE_DAEMON.md` no longer claims the record has no height field.
This commit is contained in:
parent
d203594294
commit
e697045515
4 changed files with 134 additions and 5 deletions
|
|
@ -45,6 +45,20 @@ data class WalletChildInput(
|
|||
* empty for an in-process source that has not been read yet.
|
||||
*/
|
||||
val nodeState: String = "",
|
||||
/**
|
||||
* Blocks the chain daemon had at the last probe — the core's `height`, from
|
||||
* the wallet RPC or, when that RPC is refused, from the in-process daemon
|
||||
* over loopback. `0` means unknown: never probed, the child is off/exited, or
|
||||
* the probe failed. It is **not** caught up, and it is never a wallet-scan
|
||||
* height.
|
||||
*
|
||||
* `ULong` because that is what UniFFI generates for the Rust `u64` (checked
|
||||
* against `uniffi.onionwire_sdk.WalletChildStatus`, not assumed) — this model
|
||||
* mirrors that record field for field.
|
||||
*/
|
||||
val height: ULong = 0uL,
|
||||
/** Blocks the daemon was syncing towards — the core's `target_height`. `0` means none reported (also not caught up). */
|
||||
val targetHeight: ULong = 0uL,
|
||||
val lastError: String? = null,
|
||||
)
|
||||
|
||||
|
|
@ -274,6 +288,8 @@ fun walletChildLine(input: WalletChildInput?): String {
|
|||
val phase = walletChildPhase(input)
|
||||
val source = input?.chainSource?.takeIf { it.isNotBlank() } ?: "no chain source"
|
||||
val node = nodePhase(input)
|
||||
val height = input?.height ?: 0uL
|
||||
val target = input?.targetHeight ?: 0uL
|
||||
val why = input?.lastError?.takeIf { it.isNotBlank() }
|
||||
return buildString {
|
||||
append(phase.label)
|
||||
|
|
@ -285,6 +301,16 @@ fun walletChildLine(input: WalletChildInput?): String {
|
|||
append(" · node ")
|
||||
append(node.label)
|
||||
}
|
||||
// The daemon's own height, when it reported one: `sync h/t`, the segment
|
||||
// the core's own line uses. No percent, no progress bar, no ETA — `0/0`
|
||||
// is unknown (the probe failed, or the daemon is not up), not "0%", and
|
||||
// when both are zero the segment is absent rather than printed as `0/0`.
|
||||
if (height > 0uL || target > 0uL) {
|
||||
append(" · sync ")
|
||||
append(height.toString())
|
||||
append('/')
|
||||
append(target.toString())
|
||||
}
|
||||
when {
|
||||
why != null -> append(" — ").append(shortSendReason(why))
|
||||
phase is WalletChildPhase.Exited -> append(" — the child process is gone")
|
||||
|
|
@ -292,6 +318,15 @@ fun walletChildLine(input: WalletChildInput?): String {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The whole status row as one screen-reader sentence: the phase's own sentence,
|
||||
* then the same line the eye reads — including the daemon's `sync h/t` when the
|
||||
* core reported one. A screen reader is never told less than the sighted user,
|
||||
* and it is a sentence either way.
|
||||
*/
|
||||
fun walletChildStatusDescription(input: WalletChildInput?): String =
|
||||
"${walletChildPhase(input).contentDescription}. ${walletChildLine(input)}"
|
||||
|
||||
/**
|
||||
* A `.onion` daemon is only reachable through the `arti` SOCKS child, and this
|
||||
* build does not ship one — say that before the user presses Start rather than
|
||||
|
|
|
|||
|
|
@ -681,7 +681,7 @@ private fun WalletChildCard(
|
|||
.fillMaxWidth()
|
||||
.testTag(phase.testTag)
|
||||
.semantics(mergeDescendants = true) {
|
||||
contentDescription = "${phase.contentDescription}. ${walletChildLine(input)}"
|
||||
contentDescription = walletChildStatusDescription(input)
|
||||
},
|
||||
)
|
||||
|
||||
|
|
@ -886,6 +886,8 @@ internal fun WalletChildStatus.toInput(): WalletChildInput = WalletChildInput(
|
|||
chainInProcess = chainInProcess,
|
||||
nodeAvailable = nodeAvailable,
|
||||
nodeState = nodeState,
|
||||
height = height,
|
||||
targetHeight = targetHeight,
|
||||
lastError = lastError,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ class WalletChildStatusTextTest {
|
|||
chainInProcess: Boolean = false,
|
||||
nodeAvailable: Boolean = true,
|
||||
nodeState: String = "",
|
||||
height: ULong = 0uL,
|
||||
targetHeight: ULong = 0uL,
|
||||
lastError: String? = null,
|
||||
) = WalletChildInput(
|
||||
state = state,
|
||||
|
|
@ -38,6 +40,8 @@ class WalletChildStatusTextTest {
|
|||
chainInProcess = chainInProcess,
|
||||
nodeAvailable = nodeAvailable,
|
||||
nodeState = nodeState,
|
||||
height = height,
|
||||
targetHeight = targetHeight,
|
||||
lastError = lastError,
|
||||
)
|
||||
|
||||
|
|
@ -263,6 +267,8 @@ class WalletChildStatusTextTest {
|
|||
nodeState: String,
|
||||
nodeAvailable: Boolean = true,
|
||||
running: Boolean = true,
|
||||
height: ULong = 0uL,
|
||||
targetHeight: ULong = 0uL,
|
||||
) = input(
|
||||
state = state,
|
||||
running = running,
|
||||
|
|
@ -270,6 +276,8 @@ class WalletChildStatusTextTest {
|
|||
chainInProcess = true,
|
||||
nodeAvailable = nodeAvailable,
|
||||
nodeState = nodeState,
|
||||
height = height,
|
||||
targetHeight = targetHeight,
|
||||
)
|
||||
|
||||
@Test
|
||||
|
|
@ -316,6 +324,82 @@ class WalletChildStatusTextTest {
|
|||
assertFalse(walletChildLine(input("off", chainSource = "receive-only")).contains("node "))
|
||||
}
|
||||
|
||||
// --- the daemon's sync height on the line --------------------------------
|
||||
|
||||
@Test
|
||||
fun no_sync_segment_when_the_daemon_reported_nothing() {
|
||||
// `0/0` is unknown — the probe failed or the daemon is not up — so the
|
||||
// line says nothing rather than printing a number it does not have.
|
||||
val line = walletChildLine(input("off", chainSource = "receive-only"))
|
||||
assertEquals("off · receive-only", line)
|
||||
// The `sync` *segment*, not the substring: `syncing` is a phase word.
|
||||
assertFalse("no height is not a height of zero", line.contains(" · sync "))
|
||||
assertFalse(
|
||||
walletChildLine(node(nodeState = "starting")).contains(" · sync "),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun the_line_carries_the_daemons_height_and_target() {
|
||||
assertEquals(
|
||||
"connecting · in-process mainnet pruned · node starting · sync 1160/3090939",
|
||||
walletChildLine(
|
||||
node(
|
||||
state = "connecting",
|
||||
chainSource = "in-process mainnet pruned",
|
||||
nodeState = "starting",
|
||||
height = 1160uL,
|
||||
targetHeight = 3_090_939uL,
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun a_zero_target_still_prints_as_zero_and_never_as_a_percent() {
|
||||
val line = walletChildLine(
|
||||
node(
|
||||
state = "syncing",
|
||||
chainSource = "in-process mainnet pruned",
|
||||
nodeState = "syncing",
|
||||
height = 4549uL,
|
||||
targetHeight = 0uL,
|
||||
),
|
||||
)
|
||||
assertEquals(
|
||||
"syncing · in-process mainnet pruned · node syncing · sync 4549/0",
|
||||
line,
|
||||
)
|
||||
assertFalse("no percent is invented", line.contains("%"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun the_height_sits_before_the_failure_text() {
|
||||
val line = walletChildLine(
|
||||
input("off", height = 7uL, lastError = "spawn monero-wallet-rpc: Permission denied"),
|
||||
)
|
||||
assertTrue(line, line.startsWith("off · remote daemon · sync 7/0 — "))
|
||||
assertTrue(line, line.contains("Permission denied"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun the_spoken_row_says_the_same_height_the_eye_reads() {
|
||||
val input = node(
|
||||
state = "connecting",
|
||||
chainSource = "in-process mainnet pruned",
|
||||
nodeState = "starting",
|
||||
height = 1160uL,
|
||||
targetHeight = 3_090_939uL,
|
||||
)
|
||||
val spoken = walletChildStatusDescription(input)
|
||||
assertTrue(spoken, spoken.contains("sync 1160/3090939"))
|
||||
assertTrue(
|
||||
"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"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun start_is_blocked_when_the_build_has_no_in_process_daemon() {
|
||||
val why = startBlockedReason(
|
||||
|
|
|
|||
Loading…
Reference in a new issue