From 971d8b38945d2f6a1b87d8daf652710e0f44527b Mon Sep 17 00:00:00 2001 From: agent Date: Wed, 23 Sep 2026 19:50:18 -0400 Subject: [PATCH] android: reload wallet reads when the child starts answering --- .../siriusdevops/onionwire/ui/WalletScreen.kt | 29 +++++++++++++++++++ .../onionwire/ui/WalletManagerTest.kt | 14 +++++++++ 2 files changed, 43 insertions(+) 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 10e0eb0..258b666 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,6 +134,20 @@ 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. @@ -1127,6 +1141,21 @@ 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. 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 b9388c4..7fc60c9 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 @@ -458,4 +458,18 @@ 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 ")) + } }