Merge pull request 'android: show chain sync height on the wallet status line (onto main)' (#131) from onionwire/android-sync-height-on-main into main
Some checks failed
android-ci / android (push) Has been cancelled
Some checks failed
android-ci / android (push) Has been cancelled
Reviewed-on: #131
This commit is contained in:
commit
69a7b106ee
4 changed files with 134 additions and 5 deletions
|
|
@ -133,10 +133,18 @@ above is the other half of the proof — request and artifact, separately checka
|
|||
* The status line renders the core's words verbatim and grows a `node <word>`
|
||||
segment from `WalletChildStatus.node_state` for this source only. An unrecognised
|
||||
word is never rendered as ready.
|
||||
* **No sync height.** `WalletChildStatus` has no height field — the core keeps a
|
||||
`chain_height()` internally (`src/cuprate.rs`) but does not expose it over
|
||||
UniFFI, so the screen does not show a number it cannot get. A height on the
|
||||
status line is a follow-up on the SDK surface, not something the UI can invent.
|
||||
* **The daemon's sync height is on the line.** `WalletChildStatus.height` /
|
||||
`target_height` (Rust `u64` → UniFFI/Kotlin `ULong`) carry the blocks the chain
|
||||
daemon had at the last probe — read from the wallet RPC, or, when that RPC is
|
||||
refused (the 111 case) and the source is local/in-process, from the daemon over
|
||||
loopback. The status line appends ` · sync h/t` after the source (and after the
|
||||
`node` segment) whenever either is non-zero: `0/0` means the last probe failed
|
||||
or the daemon is not up, so it is *unknown*, not `0%` — there is no percent, no
|
||||
progress bar and no ETA anywhere in the UI, and a zero target still prints as
|
||||
`/0`. This is the **daemon's** chain height, not the wallet's scan height. The
|
||||
same string is what the status row's screen-reader `contentDescription` carries
|
||||
(`walletChildStatusDescription`), so the spoken row is never shorter than the
|
||||
visible one. Cross-compiled and unit-tested on the JVM; still not device-proven.
|
||||
* **Storage honesty.** The card shows the free space on the filesystem the fjall
|
||||
store grows into (`StatFs` on the app's data dir) and refuses Start below a
|
||||
3 GiB floor, or when that filesystem cannot be read at all. The floor is a
|
||||
|
|
|
|||
|
|
@ -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