diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletManagerScreen.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletManagerScreen.kt index ac5e5b9..fbbc9fa 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletManagerScreen.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletManagerScreen.kt @@ -201,34 +201,6 @@ internal fun walletFailureText(raw: String?): String? { } } -/** - * `lastError` as the wallet screen should paint it, given the child's `state`. - * - * Defense in depth behind the core's own fix: the 2s probe dials a wallet RPC - * that may not have bound its port yet, and that transient refusal - * (`wallet connect:` / `wallet write:`) is not a fact about the wallet — the - * child is still `connecting` and the next tick usually clears it. Painting it - * red in that window tells the user a start that is going to succeed has - * failed. - * - * Only `connecting` is suppressed, and only for those two prefixes. The same - * string once the child is `exited` / `syncing` / `off` means it accepted a - * connection and then stopped answering, which is exactly what the user needs - * to see. This mirrors the core's `error_is_unreachable` predicate verbatim — - * a bare `Connection refused` from anything else is not matched. - * - * Everything else goes through [walletFailureText], unchanged. - */ -internal fun displayLastError(state: String, raw: String?): String? { - val text = raw?.trim().orEmpty() - if (text.isEmpty()) return null - val connecting = state.trim().equals("connecting", ignoreCase = true) - if (connecting && (text.startsWith("wallet connect:") || text.startsWith("wallet write:"))) { - return null - } - return walletFailureText(text) -} - /** * Whether the manager screen must ask for a wallet-file passphrase. * 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 258b666..84ef946 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 @@ -134,20 +134,6 @@ fun WalletScreen( vm.refreshChainSource() } - // The same reads again, once the child has actually answered. They are - // keyed on `state` alone, never on the whole status record: the 2s poller - // rewrites `height` every tick, and keying on the record would fire this on - // every tick instead of on the one transition that matters. `LaunchedEffect` - // re-runs only when the key changes, so `syncing` → `syncing` does not - // reload. Not while `connecting`: `walletBalance()` answers the string - // `"err"` (it does not throw), and that call is what pins the headline to - // `balance —`. - LaunchedEffect(childInput?.state) { - if (shouldReloadWalletReads(childInput?.state)) { - reload() - } - } - // The wallet child's 2s refresh loop lives in the ViewModel (like the chat // poller); this screen only owns its lifetime, so leaving the wallet and // coming back cannot stack a second loop on the first. @@ -1141,21 +1127,6 @@ private fun CuprateModeButton( } } -/** - * Whether the wallet screen's reads (balance, address, recent transfers) should - * be reloaded for a given child state. - * - * Only the two states in which the wallet RPC has actually answered count. - * `walletBalance()` returns the string `"err"` rather than throwing when it - * cannot read, so a reload during `connecting` / `off` / `exited` is not a - * no-op — it is what writes that `err` into the headline and leaves it stuck on - * `balance —` after the child comes up. - */ -internal fun shouldReloadWalletReads(state: String?): Boolean { - val s = state?.trim()?.lowercase() - return s == "syncing" || s == "ready" -} - /** * The SDK record as the pure model `WalletChildStatusText.kt` renders. Field for * field, nothing inferred. @@ -1164,14 +1135,12 @@ internal fun shouldReloadWalletReads(state: String?): Boolean { * `wallet_status().last_error`, which is the *daemon's* own words on the path * this screen exists for: a live child with no wallet open answers `-13 No * wallet file`, and `parse_json_rpc` strips the envelope and keeps that bare - * sentence. A probe that dialled a port the child had not bound yet can also - * land here (`wallet connect: Connection refused`) — [displayLastError] drops - * that one while the child is still `connecting`. The status line renders this - * field — `walletChildLine`, and through it `walletChildStatusDescription` for - * the screen reader — so the filter belongs here, at the seam where the SDK - * record becomes the Kotlin model, rather than at one of the render sites. - * `walletFailureText` is idempotent on its own replacement texts, so the - * second pass on the sticky error card is stable. + * sentence. The status line renders this field — `walletChildLine`, and through + * it `walletChildStatusDescription` for the screen reader — so the filter + * belongs here, at the seam where the SDK record becomes the Kotlin model, + * rather than at one of the render sites. `walletFailureText` is idempotent on + * its own replacement texts, so the second pass on the sticky error card is + * stable. */ internal fun WalletChildStatus.toInput(): WalletChildInput = WalletChildInput( state = state, @@ -1183,7 +1152,7 @@ internal fun WalletChildStatus.toInput(): WalletChildInput = WalletChildInput( nodeState = nodeState, height = height, targetHeight = targetHeight, - lastError = displayLastError(state, lastError), + lastError = walletFailureText(lastError), ) /** Generate a QR bitmap for the given URI string. Returns null on encode failure. */ diff --git a/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletManagerTest.kt b/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletManagerTest.kt index 7fc60c9..131ab01 100644 --- a/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletManagerTest.kt +++ b/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletManagerTest.kt @@ -311,34 +311,6 @@ class WalletManagerTest { assertNoRawRpc(WALLET_DAEMON_REFUSED_TEXT) } - // --- a connect refusal while the child is coming up ----------------------- - - @Test - fun connecting_connect_refusal_is_not_shown() { - // The Rust half stops storing this string in the first place; this is - // the display seam's own belt: a probe that dialled a port the child - // has not bound yet says nothing about whether the wallet is broken. - val raw = "wallet connect: Connection refused (os error 111)" - assertNull(displayLastError("connecting", raw)) - assertNull(displayLastError(" connecting ", "wallet write: Connection reset")) - } - - @Test - fun a_connect_refusal_after_connecting_is_still_shown() { - // Past `connecting` the same string means the child accepted a - // connection once and then died. Hiding that would hide a real failure. - val raw = "wallet connect: Connection refused (os error 111)" - assertEquals(raw, displayLastError("exited", raw)) - assertEquals(raw, displayLastError("syncing", raw)) - assertEquals(raw, displayLastError("off", raw)) - } - - @Test - fun display_last_error_still_rewrites_no_wallet_file() { - assertEquals(WALLET_NOT_OPEN_TEXT, displayLastError("connecting", "No wallet file")) - assertEquals(WALLET_NOT_OPEN_TEXT, displayLastError("syncing", "wallet rpc error -13")) - } - // --- "there is no wallet open", on the wallet screen --------------------- @Test @@ -458,18 +430,4 @@ class WalletManagerTest { assertEquals(WALLET_NOT_OPEN_TEXT, once) assertEquals(once, walletFailureText(once)) } - - @Test - fun wallet_reads_reload_only_once_the_child_is_answering() { - // `walletBalance()` answers `"err"` — it does not throw — while the - // child is still dialling, so reloading in that window is what pins the - // headline on `balance —`. Reload only when the child has answered. - assertFalse(shouldReloadWalletReads(null)) - assertFalse(shouldReloadWalletReads("off")) - assertFalse(shouldReloadWalletReads("connecting")) - assertFalse(shouldReloadWalletReads("exited")) - assertTrue(shouldReloadWalletReads("syncing")) - assertTrue(shouldReloadWalletReads("ready")) - assertTrue(shouldReloadWalletReads(" Ready ")) - } }