From b4f8bb809c074659fce7ec652f00ab9c1cc1a41c Mon Sep 17 00:00:00 2001 From: agent Date: Tue, 22 Sep 2026 14:11:34 -0400 Subject: [PATCH] android: filter the wallet child's last_error where the SDK record becomes the model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The status line renders WalletChildInput.lastError through walletChildLine, and the same field feeds walletChildStatusDescription for the screen reader. The filter added in 3f84021 sat on the sticky error card only, so in exactly the state this card targets — a live child with no wallet file open answering -13 No wallet file — the raw daemon sentence still reached the line and the screen-reader sentence. Move it to the producer: WalletChildStatus.toInput() now runs lastError through walletFailureText, the one seam where the SDK record becomes the Kotlin model. Idempotent on its own replacement texts, so the error card's second pass is stable. New JVM tests build the SDK record and assert on the rendered line (and its description), not on walletFailureText in isolation: with the filter removed they fail on the raw 'No wallet file'. --- .../siriusdevops/onionwire/ui/WalletScreen.kt | 13 ++- .../onionwire/ui/WalletManagerTest.kt | 84 +++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) 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 e03b744..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 @@ -1130,6 +1130,17 @@ private fun CuprateModeButton( /** * The SDK record as the pure model `WalletChildStatusText.kt` renders. Field for * field, nothing inferred. + * + * `lastError` is the one field that is not verbatim. It is the core's + * `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. 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, @@ -1141,7 +1152,7 @@ internal fun WalletChildStatus.toInput(): WalletChildInput = WalletChildInput( nodeState = nodeState, height = height, targetHeight = targetHeight, - lastError = 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 a095523..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 @@ -5,6 +5,7 @@ import org.junit.Assert.assertFalse import org.junit.Assert.assertNull import org.junit.Assert.assertTrue import org.junit.Test +import uniffi.onionwire_sdk.WalletChildStatus /** * The saved-wallets screen's rules, on the JVM. @@ -346,4 +347,87 @@ class WalletManagerTest { // The status line already says off/exited and Start is right there. assertNull(walletChildOpenHint(childRunning = false, walletOpen = false, needsPassphrase = true)) } + + // --- the status line itself, from the record the screen renders ----------- + + /** + * The child's record as the SDK hands it over, for the state this card + * exists for: a live `connecting` child pointed at a wallet file this + * install holds no passphrase for. Its probe answers `-13 No wallet file` + * and `parse_json_rpc` keeps only `error.message`, so the bare sentence is + * what the core reports as `last_error`. + */ + private fun sdkStatus( + state: String = "connecting", + running: Boolean = true, + walletOpen: Boolean = false, + needsPassphrase: Boolean = true, + lastError: String? = "No wallet file", + ) = WalletChildStatus( + state = state, + running = running, + walletOpen = walletOpen, + needsPassphrase = needsPassphrase, + configured = true, + chainSource = "remote daemon", + chainInProcess = false, + nodeAvailable = false, + nodeState = "", + height = 0uL, + targetHeight = 0uL, + lastError = lastError, + ) + + @Test + fun the_status_line_never_renders_the_daemons_own_words() { + // The render path, not the filter in isolation: the SDK record the + // poller lands is what the status line is drawn from, and the same + // field feeds the screen-reader sentence. + assertNoRawRpc(walletChildLine(sdkStatus().toInput())) + assertNoRawRpc(walletChildStatusDescription(sdkStatus().toInput())) + } + + @Test + fun a_raw_rpc_envelope_on_the_status_line_is_replaced_too() { + // A failure that never reached the parser arrives as the envelope. + val raw = """{"error": {"code": -13, "message": "No wallet file"}}""" + assertNoRawRpc(walletChildLine(sdkStatus(lastError = raw).toInput())) + } + + @Test + fun the_status_line_still_says_the_state_and_the_source() { + // Filtering the trailing text must not cost the line its own words. + val line = walletChildLine(sdkStatus().toInput()) + assertTrue("got '$line'", line.startsWith("connecting · remote daemon")) + } + + @Test + fun an_open_wallet_has_nothing_left_to_filter() { + val line = walletChildLine( + sdkStatus(state = "ready", walletOpen = true, needsPassphrase = false, lastError = null) + .toInput(), + ) + assertEquals("ready · remote daemon", line) + } + + @Test + fun the_cores_own_reason_for_a_dead_child_still_reaches_the_line() { + // The other side of the same seam: a reason written for a person is + // passed through, so the filter is not a mute button. + val line = walletChildLine( + sdkStatus(state = "exited", running = false, needsPassphrase = false, + lastError = "spawn monero-wallet-rpc: No such file").toInput(), + ) + assertTrue("got '$line'", line.contains("No such file")) + assertNoRawRpc(line) + } + + @Test + fun filtering_the_sdk_record_twice_changes_nothing() { + // The sticky error card runs the same filter over the same field, so + // the replacement must survive a second pass unchanged. + val once = sdkStatus().toInput().lastError + assertEquals(WALLET_NOT_OPEN_TEXT, once) + assertEquals(once, walletFailureText(once)) + } }