From 1d7cbd8503dc3164798fe60f81a93212f3868e42 Mon Sep 17 00:00:00 2001 From: agent Date: Thu, 29 Oct 2026 01:01:39 -0400 Subject: [PATCH 01/10] ui: hero wallet card and node card, and the status copy behind them (plan P4) The wallet tab was nine equal boxes: a balance card, a daemon card, and then four outlined twins (Invoice/Tip, Create/Import) pushed below the fold under a wall of grey helper text. This rebuilds it as two cards. Hero card. While no wallet file is open the card says "No Wallet Active" with the plan's subtitle and puts Create Wallet (primary) / Import Wallet (secondary) first, with Saved wallets in the card header. Once a wallet is open the balance is the headline at 28sp bold with a sync-state pill, then the gated receive address and its QR, then Receive / Invoice and Send / Tip, and a destructive Lock Wallet. Creating and importing a further wallet stay reachable in both states, and so does invoicing in the no-wallet state: the core resolves a payee address from the profile, so hiding the action there would drop a path that works ("no receive address - set profile xmr or ONIONWIRE_WALLET_RPC" is the both-missing case). A tip really does need the wallet, so it appears only when one is open. Node card. The raw "connecting . in-process mainnet pruned . node starting . sync 485253/3794383" line is replaced by a status sentence, a percentage, a 6dp progress track and "Block 485,253 of 3,794,383" with the free disk on the right; the full line is still the header's contentDescription, so a screen reader loses nothing. The three stacked mode buttons become one segmented control, Remote vs On-Device is a second one, and the lifecycle is a single context-aware control (Start Node and Wallet, or Stop Node while it runs) instead of a permanently disabled twin. Every raw paragraph (no binary, no wallet open, start blocked, core error) is now an AlertBanner. Fail-closed rules are unchanged and now tested: target_height == 0 prints no percentage (it is "no target reported", never "caught up", which is what Cuprate reports at the tip), a height past the target clamps at 100.0%, and an unrecognised state is never green. The wallet off / err sentinels still come back from the core untouched; only their display changed, to "No Wallet Loaded" and "Balance unavailable". Deliberate, and named in the handoff: WalletScreen drops its onBack parameter because Wallet is a top-level tab now (MainActivity updated; Chats and Settings already have no back affordance), and OwSegmentedControl gains an optional testTags list - additive, defaulting to empty, so no existing call site changes. --- .../siriusdevops/onionwire/MainActivity.kt | 4 +- .../onionwire/ui/WalletChildStatusText.kt | 169 +- .../siriusdevops/onionwire/ui/WalletScreen.kt | 1590 +++++++++-------- .../ui/components/SegmentedControl.kt | 11 + .../onionwire/ui/WalletChildStatusTextTest.kt | 124 +- 5 files changed, 1164 insertions(+), 734 deletions(-) diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/MainActivity.kt b/android/app/src/main/java/com/siriusdevops/onionwire/MainActivity.kt index 772f733..84d98a4 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/MainActivity.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/MainActivity.kt @@ -192,9 +192,11 @@ private fun ReadyGraph(vm: WireViewModel, ready: Phase.Ready, keepAliveNote: Str } composable(Routes.Wallet) { + // A top-level tab, so no back chevron — same shape as the + // Chats and Node & Settings destinations. The catalogue + // sub-screen still gets one from its own top bar. WalletScreen( vm = vm, - onBack = { nav.popBackStack() }, onOpenWallets = { nav.navigate(Routes.Wallets) }, ) } diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletChildStatusText.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletChildStatusText.kt index f9804fd..5bae4d1 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletChildStatusText.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletChildStatusText.kt @@ -5,7 +5,7 @@ import com.siriusdevops.onionwire.wallet.WalletChildBinaryPaths import java.util.Locale /** - * One snapshot of the app-owned wallet child, as the wallet screen sees it. + * One snapshot of the app-owned wallet process, as the wallet screen sees it. * * A plain mirror of the fields `WalletChildStatus` carries over UniFFI * (`state`, `running`, `configured`, `chain_source`, `last_error`) — the same @@ -97,7 +97,7 @@ sealed interface WalletChildPhase { data object Unread : WalletChildPhase { override val testTag: String = "child-unread" override val label: String = "reading…" - override val contentDescription: String = "Reading the wallet child status" + override val contentDescription: String = "Reading the wallet status" override val live: Boolean = false override val dead: Boolean = false } @@ -106,7 +106,7 @@ sealed interface WalletChildPhase { data object Off : WalletChildPhase { override val testTag: String = "child-off" override val label: String = "off" - override val contentDescription: String = "The wallet child is off" + override val contentDescription: String = "The wallet is off" override val live: Boolean = false override val dead: Boolean = false } @@ -116,7 +116,7 @@ sealed interface WalletChildPhase { override val testTag: String = "child-connecting" override val label: String = "connecting" override val contentDescription: String = - "The wallet child is up; its wallet RPC has not answered yet" + "The wallet is starting; its RPC has not answered yet" override val live: Boolean = true override val dead: Boolean = false } @@ -135,7 +135,7 @@ sealed interface WalletChildPhase { data object Ready : WalletChildPhase { override val testTag: String = "child-ready" override val label: String = "ready" - override val contentDescription: String = "The wallet child is ready" + override val contentDescription: String = "The wallet is ready" override val live: Boolean = true override val dead: Boolean = false } @@ -144,7 +144,7 @@ sealed interface WalletChildPhase { data class Exited(val reason: String?) : WalletChildPhase { override val testTag: String = "child-exited" override val label: String = "exited" - override val contentDescription: String = "The wallet child exited" + override val contentDescription: String = "The wallet process exited" override val live: Boolean = false override val dead: Boolean = true } @@ -158,7 +158,7 @@ sealed interface WalletChildPhase { override val testTag: String = "child-unrecognised" override val label: String = "unknown (${shortSendReason(raw, UNRECOGNISED_BUDGET)})" override val contentDescription: String = - "The wallet child reported a state this build does not know" + "The wallet reported a state this build does not know" override val live: Boolean = false override val dead: Boolean = false } @@ -336,25 +336,26 @@ const val ONION_NEEDS_ARTI_NOTICE: String = "A .onion daemon needs the arti SOCKS child, which this build does not bundle." /** Shown while the first `wallet_status()` read is still in flight. */ -const val READING_CHILD_NOTICE: String = "Reading the wallet child status…" +const val READING_CHILD_NOTICE: String = "Reading the wallet status…" const val STARTING_CHILD_NOTICE: String = "Start is running. Status stays off until the on-device node answers — that can take a minute, and is not a dead button." /** - * The caveat the on-device node is offered with, **before** Start. + * The alert banner the on-device node is offered with, **before** Start. * * Cuprate's own user book says *"do NOT use cuprated for any serious purposes"*, * its `monerod` RPC parity is incomplete (Cuprate issue #278, and the four gaps - * measured in this repo are in `docs/cuprate-launch-spike.md`), and the daemon - * this app launches is pinned to **testnet** (`src/cuprate.rs`). One sentence, not - * a glyph: the choice is opt-in and never a default, and a user who reads only - * this line still knows what they picked. + * measured in this repo are in `docs/cuprate-launch-spike.md`), and mainnet is + * unvalidated. The title is the banner's; the two sentences are the body — one + * copy of the caveat, never a second one elsewhere on the screen, so the two + * can never drift apart. */ -const val CUPRATE_PREPRODUCTION_WARNING: String = - "On-device node is Cuprate, which is pre-production: its own user book says do NOT use " + - "cuprated for any serious purposes, mainnet is unvalidated, and its monerod RPC parity " + - "is incomplete (Cuprate issue #278). Try the in-process path; do not hold funds on it." +const val CUPRATE_ON_DEVICE_TITLE: String = "Experimental On-Device Node (Cuprate)" +const val CUPRATE_ON_DEVICE_BODY: String = + "Pre-production software with incomplete RPC parity (#278). Do not use for significant " + + "funds. Mainnet is unvalidated, and Cuprate's own user book says do NOT use cuprated " + + "for any serious purposes." /** * This build was compiled without the `cuprate-daemon` feature, so the stored @@ -463,6 +464,131 @@ fun formatBytes(bytes: Long): String = when { else -> "$bytes B" } +/** + * A block height with thousands separators: `3794383` → `3,794,383`. + * + * Hand-grouped rather than `String.format("%,d")` on purpose: the grouped + * format is locale-dependent (some locales use a period or a non-breaking + * space), and a block height is a number in a monospace column, not prose. The + * screen and its test must print the same string everywhere. + */ +fun formatBlockCount(blocks: ULong): String { + val digits = blocks.toString() + val out = StringBuilder(digits.length + digits.length / 3) + digits.forEachIndexed { i, c -> + if (i > 0 && (digits.length - i) % 3 == 0) out.append(',') + out.append(c) + } + return out.toString() +} + +/** + * What the node card's progress header renders for one height / target pair. + * + * [percentText] and [blockText] are null when there is nothing honest to say — + * and `target == 0` is exactly that: the daemon reporting **no target** is not + * evidence of being caught up (`src/wallet.rs` returns `0` for a height it does + * not have, and Cuprate omits the target even at the tip). A percentage invented + * from a zero target would read as progress; an unknown target is said in words. + */ +data class SyncProgress( + /** 0f..1f of the track to fill. `0f` whenever the target is unknown. */ + val fraction: Float, + /** `12.8%`, or null when the daemon reported no target. */ + val percentText: String?, + /** `Block 485,253 of 3,794,383`, or null when neither number is known. */ + val blockText: String?, +) + +fun syncProgress(height: ULong, target: ULong): SyncProgress { + if (height == 0uL && target == 0uL) return SyncProgress(0f, null, null) + if (target == 0uL) { + return SyncProgress( + fraction = 0f, + percentText = null, + blockText = "Block ${formatBlockCount(height)} of an unknown target", + ) + } + val fraction = (height.toDouble() / target.toDouble()).coerceIn(0.0, 1.0) + return SyncProgress( + fraction = fraction.toFloat(), + percentText = String.format(Locale.US, "%.1f%%", fraction * 100.0), + blockText = "Block ${formatBlockCount(height)} of ${formatBlockCount(target)}", + ) +} + +/** + * The balance line, with the core's two sentinels translated into words. + * + * `walletBalance()` does not throw: it answers `off` (no chain source is + * configured at all) or `err` (configured, but the read failed — no wallet file + * open, or the process is down) and a formatted amount otherwise. Printing + * either sentinel raw is what put the string `wallet off` on the wallet screen; + * printing the same word for both is worse, because they are fixed in different + * places. The sentinels themselves are the core's contract and are not touched + * here — this is the display only. + */ +fun noWalletBalanceHeadline(balance: String?): String = when (balance) { + null -> "…" + "off" -> "No Wallet Loaded" + "err" -> "Balance unavailable" + else -> balance +} + +/** `Mainnet Pruned` / `Mainnet Full` / `Testnet` — the three stored modes, as words. */ +fun chainModeLabel(mainnet: Boolean, prune: Boolean): String = when { + !mainnet -> "Testnet" + prune -> "Mainnet Pruned" + else -> "Mainnet Full" +} + +/** + * How the node card's header reads. [tone] is the status dot's colour class, not + * a decoration: it is the caller's statement about the core's own word. + */ +enum class NodeStatusTone { + /** Nothing is running, and nothing is wrong. */ + Idle, + + /** Up, or on its way up. */ + Busy, + + /** Answered and at the tip. */ + Good, + + /** A state the app cannot read, or a process that is gone. */ + Bad, +} + +data class NodeStatusHead(val title: String, val tone: NodeStatusTone) + +/** + * The header sentence for the node card, from the core's `state` alone. + * + * Fail-closed exactly as [walletChildPhase] is: an unrecognised state gets + * [NodeStatusTone.Bad] and never reads as ready. A running child that has not + * answered is `Connecting…`, not `Ready` — the RPC has not spoken yet. + */ +fun nodeStatusHead( + input: WalletChildInput?, + inProcess: Boolean = false, + mainnet: Boolean = false, + prune: Boolean = false, +): NodeStatusHead { + val mode = if (inProcess) " (${chainModeLabel(mainnet, prune)})" else "" + return when (walletChildPhase(input)) { + WalletChildPhase.Unread -> NodeStatusHead("Reading wallet status", NodeStatusTone.Idle) + WalletChildPhase.Off -> + NodeStatusHead(if (inProcess) "Node Idle$mode" else "Wallet Offline", NodeStatusTone.Idle) + WalletChildPhase.Connecting -> NodeStatusHead("Connecting…", NodeStatusTone.Busy) + WalletChildPhase.Syncing -> + NodeStatusHead(if (inProcess) "Syncing Node$mode" else "Syncing Wallet", NodeStatusTone.Busy) + WalletChildPhase.Ready -> NodeStatusHead("Wallet Ready", NodeStatusTone.Good) + is WalletChildPhase.Exited -> NodeStatusHead("Wallet Stopped", NodeStatusTone.Bad) + is WalletChildPhase.Unrecognised -> NodeStatusHead("Unknown wallet state", NodeStatusTone.Bad) + } +} + /** * Why **Start** is not actionable, or `null` when it is. * @@ -479,8 +605,11 @@ fun startBlockedReason( bins.walletRpc == null -> NO_WALLET_RPC_MESSAGE starting -> STARTING_CHILD_NOTICE input == null -> READING_CHILD_NOTICE - input.running -> "The wallet child is already running." - !input.configured -> "No chain source yet: a wallet child needs a daemon to dial." + // Unreachable from the wallet screen: while the wallet runs the lifecycle + // control *is* Stop, so Start is never offered. Kept as a pure predicate so + // a stale status read cannot turn the one control into a no-op tap. + input.running -> "The wallet is already running." + !input.configured -> "No chain source yet: the wallet needs a daemon to dial." // The stored source is the app's own node but this build has no daemon: the // option is readable and unstoppable, so say it before the user presses Start. input.chainInProcess && !input.nodeAvailable -> CUPRATE_NOT_IN_BUILD_NOTICE @@ -494,7 +623,7 @@ fun startBlockedReason( */ fun stopBlockedReason(input: WalletChildInput?): String? = when { input == null -> READING_CHILD_NOTICE - !input.running -> "No wallet child is running." + !input.running -> "No wallet is running." else -> null } 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..448e8bd 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 @@ -3,6 +3,7 @@ package com.siriusdevops.onionwire.ui import android.graphics.Bitmap import android.graphics.Color import androidx.compose.foundation.Image +import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -15,21 +16,16 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.Button -import androidx.compose.material3.Card -import androidx.compose.material3.CardDefaults -import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.OutlinedButton import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.TextButton -import androidx.compose.material3.TopAppBar -import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect @@ -40,13 +36,16 @@ import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.testTag import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.google.zxing.BarcodeFormat import com.google.zxing.EncodeHintType @@ -54,6 +53,20 @@ import com.google.zxing.qrcode.QRCodeWriter import com.siriusdevops.onionwire.WireViewModel import com.siriusdevops.onionwire.wallet.NO_WALLET_RPC_MESSAGE import com.siriusdevops.onionwire.wallet.WalletChildBinaryPaths +import com.siriusdevops.onionwire.ui.components.Label +import com.siriusdevops.onionwire.ui.components.Mono +import com.siriusdevops.onionwire.ui.components.OwAlertBanner +import com.siriusdevops.onionwire.ui.components.OwAlertVariant +import com.siriusdevops.onionwire.ui.components.OwButton +import com.siriusdevops.onionwire.ui.components.OwButtonRow +import com.siriusdevops.onionwire.ui.components.OwButtonVariant +import com.siriusdevops.onionwire.ui.components.OwCard +import com.siriusdevops.onionwire.ui.components.OwDivider +import com.siriusdevops.onionwire.ui.components.OwPill +import com.siriusdevops.onionwire.ui.components.OwSectionTitle +import com.siriusdevops.onionwire.ui.components.OwSegmentedControl +import com.siriusdevops.onionwire.ui.components.OwStatusDot +import com.siriusdevops.onionwire.ui.components.OwTopBar import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import uniffi.onionwire_sdk.ChainChoice @@ -65,11 +78,31 @@ import uniffi.onionwire_sdk.WalletChildStatus private enum class PayKind { Invoice, Tip } private enum class SetupKind { Create, Import } -@OptIn(ExperimentalMaterial3Api::class) +/** + * The wallet tab. + * + * Three things changed from the alpha build, and each one is the plan's: + * + * - The page is a hero card and a node card, not a stack of nine equal boxes. + * The balance, the receive address and the two payment actions are the top + * card; the daemon, the network mode and the lifecycle are the second one. + * - Create / Import are the *first* thing on the page while no wallet is open, + * instead of two more outlined twins at the bottom of a long scroll. + * - The raw telemetry is gone from the surface: no daemon-process jargon, no + * `connecting · in-process mainnet pruned · node starting · sync 485253/…` + * string. What is left is a status sentence, a percentage, a progress track + * and two formatted block counts. The full line is still spoken — it is the + * header's `contentDescription` — so nothing an operator needs was deleted, + * it moved behind progressive disclosure. + * + * Behaviour is unchanged. Every callback below is the ViewModel call the old + * screen made; the gate on the seed card, the `shouldReloadWalletReads` key on + * the reload effect and the `openWalletChild` lifetime are untouched, because + * they are state, not layout. + */ @Composable fun WalletScreen( vm: WireViewModel, - onBack: () -> Unit, onOpenWallets: () -> Unit, ) { val friends by vm.friends.collectAsStateWithLifecycle() @@ -95,12 +128,18 @@ fun WalletScreen( var composer by remember { mutableStateOf(null) } var setup by remember { mutableStateOf(null) } // The seed currently on the blocking card: set by a successful create, or by - // "Back up seed" re-reading it from the wallet child. Null means no card. + // "Back up seed" re-reading it from the wallet process. Null means no card. // Never persisted and never logged — it is a spend key. var pendingSeed by remember { mutableStateOf(null) } var seedConfirm by remember { mutableStateOf("") } var daemonText by remember { mutableStateOf("") } var daemonError by remember { mutableStateOf(null) } + // Which pane of the node card's connection selector is open. `null` means + // "follow the stored chain source", which is the honest default: the pane is + // a view of what is configured, not a configuration of its own. It is reset + // whenever the stored source changes, so a started on-device node snaps the + // selector back to its own pane. + var remotePane by remember { mutableStateOf(null) } suspend fun reload() { runCatching { balance = vm.walletBalance() } @@ -110,10 +149,10 @@ fun WalletScreen( } /** - * "Back up seed": re-read the open wallet's seed from the wallet child and + * "Back up seed": re-read the open wallet's seed from the wallet process and * put it on the blocking card. This is the only path to a seed that was * created before this screen existed, so the failure is shown rather than - * swallowed — it is the difference between "the child is not running" and + * swallowed — it is the difference between "the wallet is not running" and * "there is nothing to recover". */ fun openSeedBackup() { @@ -134,21 +173,21 @@ fun WalletScreen( vm.refreshChainSource() } - // The same reads again, once the child has actually answered. They are + // The same reads again, once the wallet 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 —`. + // `Balance unavailable`. LaunchedEffect(childInput?.state) { if (shouldReloadWalletReads(childInput?.state)) { reload() } } - // The wallet child's 2s refresh loop lives in the ViewModel (like the chat + // The wallet'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. DisposableEffect(Unit) { @@ -156,8 +195,11 @@ fun WalletScreen( onDispose { vm.closeWalletChild() } } - // Prefill the daemon field from the stored config, never over typing. + // Prefill the daemon field from the stored config, never over typing — and + // drop the connection-pane override, so the selector follows the source that + // was just stored. LaunchedEffect(chain) { + remotePane = null val stored = chain if (stored != null && stored.kind == ChainChoice.REMOTE && daemonText.isBlank()) { daemonText = "${stored.host}:${stored.port}" @@ -170,21 +212,20 @@ fun WalletScreen( // navigation bar from being applied twice, and keeps the IME inset out // of the Scaffold's inner padding. contentWindowInsets = WindowInsets(0, 0, 0, 0), + containerColor = OwColors.Canvas, topBar = { - TopAppBar( - title = { Text("Wallet") }, - navigationIcon = { - TextButton(onClick = onBack) { Text("Back") } - }, + OwTopBar( + title = "Wallet", // The saved-wallet catalogue is its own screen: this one is the - // open wallet, and switching wallets restarts the child, so the - // picker does not belong in this page's scroll. + // open wallet, and switching wallets restarts the wallet + // process, so the picker does not belong in this page's scroll. actions = { - TextButton(onClick = onOpenWallets) { Text("Wallets") } + OwButton( + text = "Saved wallets", + variant = OwButtonVariant.Outline, + onClick = onOpenWallets, + ) }, - colors = TopAppBarDefaults.topAppBarColors( - containerColor = MaterialTheme.colorScheme.background, - ), ) }, ) { pad -> @@ -199,11 +240,10 @@ fun WalletScreen( ) { // The blocking seed step. While a seed is on screen this card is the // whole body: no Cancel, and Done stays dead until the confirm word - // is typed, so the one-shot seed cannot be dismissed unread. The - // app-bar Back still leaves the screen — that is the TUI's `Esc` — - // and it costs nothing now, because leaving no longer loses the - // seed: the wallet stays unbacked (strip up, receive address hidden) - // until "Back up seed" puts this card back on screen. + // is typed, so the one-shot seed cannot be dismissed unread. Leaving + // the tab costs nothing now, because leaving no longer loses the + // seed: the wallet stays unbacked (warning up, receive address + // hidden) until "Back up seed" puts this card back on screen. val seed = pendingSeed if (seed != null) { SeedBackupCard( @@ -223,97 +263,45 @@ fun WalletScreen( } // The persistent unbacked strip, above everything else on the page. - // `walletReadable` is the core's own evidence that the child has a + // `walletReadable` is the core's own evidence that the wallet has a // wallet open: `wallet_balance` returns exactly "off" for a chain // source that was never configured, "err" for a configured one whose - // read failed (no wallet file open yet, or the child is down), and a - // real amount otherwise. The gate uses it only for an install that + // read failed (no wallet file open yet, or the process is down), and + // a real amount otherwise. The gate uses it only for an install that // has never created a wallet here, so a first-run user who has // configured a daemon but not yet created anything is not nagged // about a seed they do not have. val walletReadable = balance != null && balance != "off" && balance != "err" + val walletOpen = child?.walletOpen == true val unbacked = SeedBackupGate.warningVisible(seedConfirmed, walletReadable) if (unbacked) { UnbackedSeedCard(error = error, onBackUpSeed = { openSeedBackup() }) } - Card( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 12.dp, vertical = 8.dp), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceVariant, - ), - ) { - Column( - Modifier.padding(16.dp), - horizontalAlignment = Alignment.CenterHorizontally, + val phase = walletChildPhase(childInput) + WalletHeroCard( + balance = balance, + address = address, + walletOpen = walletOpen, + phase = phase, + showQr = showQr, + onToggleQr = { showQr = !showQr }, + onOpenWallets = onOpenWallets, + onCreate = { setup = SetupKind.Create }, + onImport = { setup = SetupKind.Import }, + onInvoice = { composer = PayKind.Invoice }, + onTip = { composer = PayKind.Tip }, + onBackUpSeed = if ( + walletReadable && !SeedBackupGate.warningVisible(seedConfirmed, walletReadable) ) { - Text( - when (balance) { - null -> "loading…" - "off" -> "wallet off" - "err" -> "balance —" - else -> balance ?: "" - }, - style = MaterialTheme.typography.headlineSmall, - fontFamily = FontFamily.Monospace, - ) - // Hidden until the seed is confirmed written down: XMR into a - // wallet whose 25 words were never recorded is unrecoverable, - // so the address and its QR are gated, not just warned about. - val addr = address?.takeIf { - SeedBackupGate.receiveAddressVisible(seedConfirmed, walletReadable) - } - if (addr != null) { - Spacer(Modifier.height(8.dp)) - Text( - "receive address", - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - Spacer(Modifier.height(4.dp)) - Text( - addr, - style = MaterialTheme.typography.bodySmall, - fontFamily = FontFamily.Monospace, - modifier = Modifier.fillMaxWidth(), - ) - TextButton(onClick = { showQr = !showQr }) { - Text(if (showQr) "Hide QR" else "Show QR") - } - if (showQr) { - val qr = remember(addr) { generateQrBitmap(addr) } - qr?.let { bm -> - Box( - modifier = Modifier - .fillMaxWidth() - .aspectRatio(1f) - .border( - 1.dp, - MaterialTheme.colorScheme.outline, - RoundedCornerShape(8.dp), - ) - .padding(8.dp), - contentAlignment = Alignment.Center, - ) { - Image( - bitmap = bm.asImageBitmap(), - contentDescription = "QR code for receive address", - modifier = Modifier.fillMaxSize(), - contentScale = ContentScale.Fit, - ) - } - } - } - } - } - } + { openSeedBackup() } + } else { + null + }, + onLock = { scope.launch { vm.stopWalletChild() } }, + ) - // The app-owned `monero-wallet-rpc` control. Above the existing - // Create / Import / Invoice / Tip actions, which are untouched: the - // daemon is what makes the balance and the sends mean anything. - WalletChildCard( + NodeCard( bins = bins, input = childInput, chain = chain, @@ -321,8 +309,14 @@ fun WalletScreen( actionError = childError, daemonText = daemonText, daemonError = daemonError, - walletOpen = child?.walletOpen == true, + walletOpen = walletOpen, needsPassphrase = child?.needsPassphrase == true, + starting = starting, + remotePane = remotePane ?: !isInProcessSource(childInput, chain), + onSelectPane = { wantsRemote -> + remotePane = wantsRemote + daemonError = null + }, onDaemonText = { daemonText = it daemonError = null @@ -352,10 +346,10 @@ fun WalletScreen( vm.setInProcessCuprate(bins, mainnet, prune) .onFailure { daemonError = walletFailureText(it.message ?: it.toString()) } .onSuccess { - // The mode buttons used to only persist the choice, - // which read as a no-op besides the storage line. - // Start is still the core launch; tapping a mode - // fires it when the storage gate would allow Start. + // Selecting a mode stores it and, when the + // storage floor would allow Start, starts the + // node: a mode button that only rewrites a + // storage line reads as a no-op. if (shouldStartAfterSelectingChain( chainStorageBlockedReason( vm.chainFreeBytes(), @@ -370,35 +364,24 @@ fun WalletScreen( } } }, - starting = starting, onStart = { vm.startWalletChild() }, onStop = { scope.launch { vm.stopWalletChild() } }, ) if (transfers.isNotEmpty()) { - Text( - "recent transfers", - style = MaterialTheme.typography.titleSmall, - modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp), - ) - // Plain Column, not a LazyColumn: the root is a scrolling - // container now, so a nested lazy list would either throw on the - // unbounded height or need an arbitrary cap. `walletRecentTransfers` - // is bounded (25 rows), and the page scrolls as one gesture. - Column( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 12.dp), - verticalArrangement = Arrangement.spacedBy(4.dp), - ) { - transfers.forEach { t -> TransferCard(t) } + Column(Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp)) { + Label("RECENT TRANSFERS") + Spacer(Modifier.height(8.dp)) + Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { + transfers.forEach { t -> TransferCard(t) } + } } } val kind = composer val setupKind = setup - if (kind != null) { - PayComposer( + when { + kind != null -> PayComposer( kind = kind, friends = friends, onCancel = { composer = null }, @@ -419,8 +402,8 @@ fun WalletScreen( } }, ) - } else if (setupKind != null) { - WalletSetupCard( + + setupKind != null -> WalletSetupCard( kind = setupKind, warning = vm.spendAuthorityWarning(), onCancel = { setup = null }, @@ -440,72 +423,599 @@ fun WalletScreen( importWallet = { pw, seed -> vm.importWallet(pw, seed) }, scope = scope, ) - } else { - Column(Modifier.fillMaxWidth().padding(12.dp)) { - Row( - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.spacedBy(8.dp), - ) { - OutlinedButton( - onClick = { composer = PayKind.Invoice }, - modifier = Modifier.weight(1f), - ) { Text("Invoice") } - OutlinedButton( - onClick = { composer = PayKind.Tip }, - modifier = Modifier.weight(1f), - ) { Text("Tip") } - } - Spacer(Modifier.height(8.dp)) - Row( - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.spacedBy(8.dp), - ) { - OutlinedButton( - onClick = { setup = SetupKind.Create }, - modifier = Modifier.weight(1f), - ) { Text("Create") } - OutlinedButton( - onClick = { setup = SetupKind.Import }, - modifier = Modifier.weight(1f), - ) { Text("Import") } - } - // The recovery path for a wallet whose seed was missed. The - // strip above carries its own copy of this button while the - // seed is unconfirmed, so exactly one is ever on screen — - // and this copy is only offered once the child can actually - // read a wallet, which is the only state in which the seed - // read can succeed. - if (walletReadable && !SeedBackupGate.warningVisible(seedConfirmed, walletReadable)) { - Spacer(Modifier.height(8.dp)) - OutlinedButton( - onClick = { openSeedBackup() }, - modifier = Modifier - .fillMaxWidth() - .testTag("wallet-seed-backup-action"), - ) { Text("Back up seed") } - } - } } // While the strip is up the error belongs next to the button that - // caused it: this page is one long scroll and the daemon card sits + // caused it: this page is one long scroll and the node card sits // between the strip and the bottom, so a failed `wallet_seed` read // would otherwise land off-screen. if (!unbacked) { error?.let { ErrorLine(it) } } + + Spacer(Modifier.height(16.dp)) } } } -/** The one error line every wallet action shares. */ +/** + * The wallet at a glance: a balance, a receive address, and the four things a + * person actually does here. + * + * Two states, and the switch is the core's own `wallet_open` — not "is a chain + * source configured", which is a different question and answers yes for a + * receive-only install that has no wallet file at all. + */ +@Composable +private fun WalletHeroCard( + balance: String?, + address: String?, + walletOpen: Boolean, + phase: WalletChildPhase, + showQr: Boolean, + onToggleQr: () -> Unit, + onOpenWallets: () -> Unit, + onCreate: () -> Unit, + onImport: () -> Unit, + onInvoice: () -> Unit, + onTip: () -> Unit, + onBackUpSeed: (() -> Unit)?, + onLock: () -> Unit, +) { + OwCard( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp, vertical = 8.dp), + ) { + Row( + Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, + ) { + Row(verticalAlignment = Alignment.CenterVertically) { + OwStatusDot( + when { + !walletOpen -> OwColors.TextMuted + phase is WalletChildPhase.Ready -> OwColors.Accent + else -> OwColors.Warning + }, + ) + Spacer(Modifier.width(8.dp)) + OwSectionTitle(if (walletOpen) "Wallet" else "No Wallet Active") + } + OwButton( + text = "Saved wallets", + variant = OwButtonVariant.Outline, + onClick = onOpenWallets, + ) + } + Spacer(Modifier.height(12.dp)) + + if (!walletOpen) { + // The §4.1 replacement for the old `wallet off` string, kept as a + // value line rather than a second heading: the card already says + // "No Wallet Active", and "off" vs "err" is the difference between + // "nothing is configured" and "configured, but the read failed". + Text( + noWalletBalanceHeadline(balance), + style = MaterialTheme.typography.titleMedium, + color = OwColors.TextSecondary, + modifier = Modifier.testTag("wallet-balance"), + ) + Spacer(Modifier.height(6.dp)) + Text( + "Create a new Monero wallet or restore an existing seed.", + style = MaterialTheme.typography.bodySmall, + color = OwColors.TextSecondary, + ) + Spacer(Modifier.height(16.dp)) + OwButtonRow { + OwButton( + text = "Create Wallet", + variant = OwButtonVariant.Primary, + onClick = onCreate, + modifier = Modifier.weight(1f).testTag("wallet-create"), + ) + OwButton( + text = "Import Wallet", + variant = OwButtonVariant.Secondary, + onClick = onImport, + modifier = Modifier.weight(1f).testTag("wallet-import"), + ) + } + // Invoicing does not need a wallet file: the core resolves the payee + // address from the profile (`no receive address — set profile xmr or + // ONIONWIRE_WALLET_RPC` is the both-missing case). Hiding the action + // in this state would remove a path that works, so it stays — as a + // text action, not a third button competing with Create. A tip + // genuinely needs the wallet (it calls `Wallet::transfer`), so it + // only appears once one is open. + TextButton(onClick = onInvoice) { Text("Send an invoice") } + return@OwCard + } + + // A wallet is open: the balance is the headline, 28sp bold, sans — it is + // money, not cryptographic material, so it is not monospaced. + Text( + noWalletBalanceHeadline(balance), + style = MaterialTheme.typography.displaySmall, + color = OwColors.TextPrimary, + modifier = Modifier.testTag("wallet-balance"), + ) + Spacer(Modifier.height(6.dp)) + OwPill( + text = phase.label, + textColor = when (phase) { + WalletChildPhase.Ready -> OwColors.Accent + is WalletChildPhase.Exited, is WalletChildPhase.Unrecognised -> OwColors.Danger + else -> OwColors.Warning + }, + container = when (phase) { + WalletChildPhase.Ready -> OwColors.InfoTint + is WalletChildPhase.Exited, is WalletChildPhase.Unrecognised -> OwColors.DangerTint + else -> OwColors.WarningTint + }, + borderColor = when (phase) { + WalletChildPhase.Ready -> OwColors.InfoBorder + is WalletChildPhase.Exited, is WalletChildPhase.Unrecognised -> OwColors.DangerBorder + else -> OwColors.WarningBorder + }, + dotColor = when (phase) { + WalletChildPhase.Ready -> OwColors.Accent + is WalletChildPhase.Exited, is WalletChildPhase.Unrecognised -> OwColors.Danger + else -> OwColors.Warning + }, + ) + + // Hidden until the seed is confirmed written down: XMR into a wallet + // whose 25 words were never recorded is unrecoverable, so the address + // and its QR are gated, not just warned about. + val addr = address + if (addr != null) { + Spacer(Modifier.height(16.dp)) + OwDivider() + Spacer(Modifier.height(12.dp)) + Label("RECEIVE ADDRESS") + Spacer(Modifier.height(4.dp)) + Mono(addr, modifier = Modifier.fillMaxWidth(), color = OwColors.TextPrimary) + TextButton(onClick = onToggleQr) { Text(if (showQr) "Hide QR" else "Show QR") } + if (showQr) { + val qr = remember(addr) { generateQrBitmap(addr) } + qr?.let { bm -> + Box( + modifier = Modifier + .fillMaxWidth() + .aspectRatio(1f) + .border(1.dp, OwColors.Border, RoundedCornerShape(OwRadius.Control)) + .padding(8.dp), + contentAlignment = Alignment.Center, + ) { + Image( + bitmap = bm.asImageBitmap(), + contentDescription = "QR code for receive address", + modifier = Modifier.fillMaxSize(), + contentScale = ContentScale.Fit, + ) + } + } + } + } + + Spacer(Modifier.height(16.dp)) + OwButtonRow { + OwButton( + text = "Receive / Invoice", + variant = OwButtonVariant.Primary, + onClick = onInvoice, + modifier = Modifier.weight(1f), + ) + OwButton( + text = "Send / Tip", + variant = OwButtonVariant.Secondary, + onClick = onTip, + modifier = Modifier.weight(1f), + ) + } + Spacer(Modifier.height(8.dp)) + OwButtonRow { + // Creating a second wallet and importing a third are real flows + // (each wallet gets its own file, and the catalogue lists them), so + // both stay reachable once the first one is open — they just stop + // being the loudest thing on the page. + OwButton( + text = "New wallet", + variant = OwButtonVariant.Outline, + onClick = onCreate, + modifier = Modifier.weight(1f).testTag("wallet-create"), + ) + OwButton( + text = "Import wallet", + variant = OwButtonVariant.Outline, + onClick = onImport, + modifier = Modifier.weight(1f).testTag("wallet-import"), + ) + } + // The recovery path for a wallet whose seed was missed: a quiet action, + // because a healthy wallet needs it rarely and a seed is a spend key. + // While the seed is unconfirmed the strip above carries the button + // instead, so exactly one is ever on screen. + if (onBackUpSeed != null) { + TextButton( + onClick = onBackUpSeed, + modifier = Modifier.testTag("wallet-seed-backup-action"), + ) { Text("Back up seed") } + } + Spacer(Modifier.height(8.dp)) + OwButton( + text = "Lock Wallet", + variant = OwButtonVariant.Destructive, + onClick = onLock, + modifier = Modifier.fillMaxWidth().testTag("wallet-lock"), + ) + } +} + +/** + * The node and the daemon: one status header, one progress track, one choice of + * where the chain comes from, and one lifecycle control. + * + * The single most important property of this card is that it never asserts a + * state the core did not report. `target_height == 0` prints no percentage, an + * unrecognised state is never green, and a running process whose RPC has not + * answered is `Connecting…`, not `Wallet Ready`. + */ +@Composable +private fun NodeCard( + bins: WalletChildBinaryPaths, + input: WalletChildInput?, + chain: ChainConfig?, + nodeFreeBytes: Long?, + actionError: String?, + daemonText: String, + daemonError: String?, + /** + * The core's `wallet_open` / `needs_passphrase`, straight off the same + * `WalletChildStatus` the status header is drawn from — not a second idea of + * which wallet is open. + */ + walletOpen: Boolean, + needsPassphrase: Boolean, + starting: Boolean, + /** Which pane the connection selector shows; the caller owns the override. */ + remotePane: Boolean, + onSelectPane: (Boolean) -> Unit, + onDaemonText: (String) -> Unit, + onSaveDaemon: () -> Unit, + onReceiveOnly: () -> Unit, + onInProcessNode: (mainnet: Boolean, prune: Boolean) -> Unit, + onStart: () -> Unit, + onStop: () -> Unit, +) { + val inProcess = isInProcessSource(input, chain) + val head = nodeStatusHead( + input, + inProcess = inProcess, + mainnet = chain?.mainnet == true, + prune = chain?.prune == true, + ) + val progress = syncProgress(input?.height ?: 0uL, input?.targetHeight ?: 0uL) + val node = nodePhase(input) + val onionDaemon = chain?.kind == ChainChoice.REMOTE && isOnionHost(chain.host) + val startWhy = startBlockedReason(bins, input, onionDaemon, starting) + ?: if (inProcess) { + chainStorageBlockedReason( + nodeFreeBytes, + mainnet = chain?.mainnet == true, + prune = chain?.prune == true, + ) + } else { + null + } + val stopWhy = stopBlockedReason(input) + // A live wallet with no wallet file open answers every read with the + // daemon's own `-13 No wallet file`. Say that in this app's words, here, + // rather than letting the raw string arrive later on whichever card asked. + val openHint = walletChildOpenHint( + childRunning = input?.running == true, + walletOpen = walletOpen, + needsPassphrase = needsPassphrase, + ) + val running = input?.running == true + + OwCard( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp, vertical = 8.dp), + ) { + // --- the status header ------------------------------------------------ + Row( + Modifier + .fillMaxWidth() + .testTag(walletChildPhase(input).testTag) + .semantics(mergeDescendants = true) { + // The whole raw line — `syncing · in-process mainnet pruned + // · node syncing · sync 485253/3794383` — is still spoken. + // A screen reader is never told less than the sighted user. + contentDescription = walletChildStatusDescription(input) + }, + verticalAlignment = Alignment.CenterVertically, + ) { + OwStatusDot( + when (head.tone) { + NodeStatusTone.Idle -> OwColors.TextMuted + NodeStatusTone.Busy -> OwColors.Warning + NodeStatusTone.Good -> OwColors.Accent + NodeStatusTone.Bad -> OwColors.Danger + }, + ) + Spacer(Modifier.width(8.dp)) + Text( + head.title, + style = MaterialTheme.typography.titleMedium, + color = OwColors.TextPrimary, + modifier = Modifier.weight(1f), + ) + progress.percentText?.let { pct -> + Mono(pct, color = OwColors.TextSecondary) + } + } + + // --- the progress track ---------------------------------------------- + if (progress.blockText != null) { + Spacer(Modifier.height(10.dp)) + Box( + Modifier + .fillMaxWidth() + .height(OwSize.ProgressTrack) + .clip(RoundedCornerShape(OwRadius.Pill)) + .background(OwColors.SurfaceInteractive), + ) { + Box( + Modifier + .fillMaxWidth(progress.fraction) + .height(OwSize.ProgressTrack) + .clip(RoundedCornerShape(OwRadius.Pill)) + .background(OwColors.Accent), + ) + } + Spacer(Modifier.height(6.dp)) + Row( + Modifier.fillMaxWidth().testTag("wallet-chain-progress"), + horizontalArrangement = Arrangement.SpaceBetween, + ) { + Text( + progress.blockText, + style = MonoStyle.copy(fontSize = 12.sp, color = OwColors.TextSecondary), + ) + Text( + nodeFreeBytes?.let { "${formatBytes(it)} free" } ?: "free space unknown", + style = MonoStyle.copy(fontSize = 12.sp, color = OwColors.TextSecondary), + ) + } + } + + // The node's own word, when there is one, as its own assertable line: + // an unrecognised node state can never be read as ready. + if (node !is NodePhase.Absent) { + Spacer(Modifier.height(6.dp)) + Text( + "node: ${node.label}", + style = MonoStyle.copy(fontSize = 12.sp, color = OwColors.TextSecondary), + modifier = Modifier + .fillMaxWidth() + .testTag(node.testTag) + .semantics(mergeDescendants = true) { + contentDescription = node.contentDescription + }, + ) + } + + Spacer(Modifier.height(12.dp)) + OwDivider() + Spacer(Modifier.height(12.dp)) + + // --- where the chain comes from --------------------------------------- + Label("CONNECTION TYPE") + Spacer(Modifier.height(8.dp)) + OwSegmentedControl( + options = listOf("Remote Node", "On-Device Node"), + selectedIndex = if (remotePane) 0 else 1, + onSelect = { onSelectPane(it == 0) }, + testTags = listOf("wallet-connection-remote", "wallet-connection-on-device"), + ) + + if (remotePane) { + Spacer(Modifier.height(12.dp)) + OutlinedTextField( + value = daemonText, + onValueChange = onDaemonText, + singleLine = true, + label = { Text("daemon host:port") }, + modifier = Modifier + .fillMaxWidth() + .testTag("wallet-daemon-input"), + ) + Spacer(Modifier.height(4.dp)) + Text( + "LAN (e.g. 192.168.1.20:18089) or a public clearnet node.", + style = MaterialTheme.typography.labelSmall, + color = OwColors.TextSecondary, + ) + Spacer(Modifier.height(10.dp)) + OwButtonRow { + OwButton( + text = "Save Daemon", + variant = OwButtonVariant.Secondary, + onClick = onSaveDaemon, + enabled = bins.walletRpcBundled, + modifier = Modifier.weight(1f).testTag("wallet-daemon-save"), + ) + OwButton( + text = "Receive-Only", + variant = OwButtonVariant.Outline, + onClick = onReceiveOnly, + modifier = Modifier.weight(1f).testTag("wallet-daemon-receive-only"), + ) + } + } else { + Spacer(Modifier.height(12.dp)) + Label("NETWORK MODE") + Spacer(Modifier.height(8.dp)) + val mode = selectedCuprateMode( + inProcess = true, + mainnet = chain?.mainnet == true, + prune = chain?.prune == true, + ) + OwSegmentedControl( + options = listOf("Pruned", "Full", "Testnet"), + selectedIndex = when (mode) { + CuprateMode.MainnetFull -> 1 + CuprateMode.Testnet -> 2 + // MainnetPruned, and the not-in-process case before anything + // is stored: the pruned store is the conservative default. + else -> 0 + }, + onSelect = { index -> + when (index) { + 0 -> onInProcessNode(true, true) + 1 -> onInProcessNode(true, false) + else -> onInProcessNode(false, false) + } + }, + testTags = listOf( + "wallet-chain-mainnet-pruned", + "wallet-chain-mainnet-full", + "wallet-chain-in-process", + ), + ) + Spacer(Modifier.height(10.dp)) + OwAlertBanner( + variant = OwAlertVariant.Warning, + title = CUPRATE_ON_DEVICE_TITLE, + description = CUPRATE_ON_DEVICE_BODY, + modifier = Modifier.testTag("wallet-cuprate-warning"), + ) + Spacer(Modifier.height(8.dp)) + Text( + chainStorageLine( + nodeFreeBytes, + mainnet = chain?.mainnet == true, + prune = chain?.prune == true, + ), + style = MaterialTheme.typography.labelSmall, + color = OwColors.TextSecondary, + modifier = Modifier + .fillMaxWidth() + .testTag("wallet-chain-storage"), + ) + } + + // --- the lifecycle ---------------------------------------------------- + Spacer(Modifier.height(16.dp)) + if (starting) { + OwButton( + text = "Starting…", + variant = OwButtonVariant.Primary, + enabled = false, + onClick = {}, + modifier = Modifier.fillMaxWidth().testTag("wallet-child-start"), + ) + } else if (running) { + OwButton( + text = "Stop Node", + variant = OwButtonVariant.Destructive, + enabled = stopWhy == null, + onClick = onStop, + modifier = Modifier.fillMaxWidth().testTag("wallet-child-stop"), + ) + } else { + OwButton( + text = "Start Node & Wallet", + variant = OwButtonVariant.Primary, + enabled = startWhy == null, + onClick = onStart, + modifier = Modifier.fillMaxWidth().testTag("wallet-child-start"), + ) + } + + // --- what is wrong, in banners rather than paragraphs ----------------- + if (starting) { + Spacer(Modifier.height(8.dp)) + OwAlertBanner( + variant = OwAlertVariant.Info, + title = "Starting", + description = STARTING_CHILD_NOTICE, + ) + } + + // Why Start is dead, in the core's terms rather than a grey button. + if (!starting && !running) { + startWhy?.let { + Spacer(Modifier.height(8.dp)) + OwAlertBanner( + variant = OwAlertVariant.Info, + title = "Not ready to start", + description = it, + modifier = Modifier.testTag("wallet-child-start-blocked"), + ) + } + } + + if (!bins.walletRpcBundled) { + Spacer(Modifier.height(8.dp)) + OwAlertBanner( + variant = OwAlertVariant.Error, + title = "No wallet binary", + description = NO_WALLET_RPC_MESSAGE, + ) + } + + // "No wallet file open" is a state of a live wallet, not a failure of + // the last call, so it is said here rather than left to surface as the + // daemon's `-13` on whichever card asked for a read. + openHint?.let { + Spacer(Modifier.height(8.dp)) + OwAlertBanner( + variant = OwAlertVariant.Info, + title = "No wallet open", + description = it, + modifier = Modifier.testTag("wallet-child-no-wallet"), + ) + } + + // The last thing the core or the RPC call said. Sticky until the user + // acts, like the chat screen's load error. Filtered through + // `walletFailureText`: the daemon's own `-13 No wallet file` / JSON + // answer is not a sentence about this app and never reaches the screen. + val failure = walletFailureText(input?.lastError) ?: actionError ?: daemonError + failure?.let { + Spacer(Modifier.height(8.dp)) + OwAlertBanner( + variant = OwAlertVariant.Error, + title = "Wallet error", + description = it, + modifier = Modifier.testTag("wallet-child-error"), + ) + } + } +} + +/** + * True when the stored chain source (or the live status, before the store is + * re-read) is the app's own node. The connection selector and the network-mode + * control both key off this one predicate. + */ +private fun isInProcessSource(input: WalletChildInput?, chain: ChainConfig?): Boolean = + input?.chainInProcess == true || chain?.kind == ChainChoice.IN_PROCESS_CUPRATE + +/** The one error line every wallet action shares, as a banner. */ @Composable private fun ErrorLine(text: String) { - Text( - text, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.error, - modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp), + OwAlertBanner( + variant = OwAlertVariant.Error, + title = "Something went wrong", + description = text, + modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp), ) } @@ -523,38 +1033,23 @@ private fun UnbackedSeedCard( error: String?, onBackUpSeed: () -> Unit, ) { - Card( + OwAlertBanner( + variant = OwAlertVariant.Error, + title = "This wallet is not backed up", + description = SeedBackupGate.WARNING, modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 12.dp, vertical = 8.dp) + .padding(horizontal = 16.dp, vertical = 8.dp) .testTag("wallet-seed-warning"), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.errorContainer, - ), - ) { - Column(Modifier.padding(12.dp)) { - Text( - SeedBackupGate.WARNING, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onErrorContainer, - ) - Spacer(Modifier.height(8.dp)) - OutlinedButton( + action = { + OwButton( + text = "Back up seed", + variant = OwButtonVariant.Outline, onClick = onBackUpSeed, - modifier = Modifier - .fillMaxWidth() - .testTag("wallet-seed-backup-action"), - ) { Text("Back up seed") } - error?.let { - Spacer(Modifier.height(6.dp)) - Text( - it, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.error, - ) - } - } - } + modifier = Modifier.testTag("wallet-seed-backup-action"), + ) + }, + ) + error?.let { ErrorLine(it) } } /** @@ -584,91 +1079,76 @@ internal fun SeedBackupCard( onTyped: (String) -> Unit, onDone: () -> Unit, ) { - Card( + OwCard( modifier = Modifier .fillMaxWidth() - .padding(12.dp) + .padding(16.dp) .testTag("wallet-seed-card"), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceVariant, - ), ) { - Column(Modifier.padding(12.dp)) { - Text("Back up this seed", style = MaterialTheme.typography.titleSmall) - Spacer(Modifier.height(8.dp)) - Text( - "These 25 words are the only way to recover this wallet, and anyone who " + - "reads them can spend it. Write them down now — this is the only copy.", - style = MaterialTheme.typography.bodySmall, - ) - Spacer(Modifier.height(8.dp)) - Text( - seed, - style = MaterialTheme.typography.bodyMedium, - fontFamily = FontFamily.Monospace, - modifier = Modifier - .fillMaxWidth() - .testTag("wallet-seed-words"), - ) - Spacer(Modifier.height(12.dp)) - Text( - "Type ${SeedBackupGate.CONFIRM_WORD} to confirm you have written it down.", - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - Spacer(Modifier.height(4.dp)) - OutlinedTextField( - value = typed, - onValueChange = onTyped, - singleLine = true, - label = { Text("type ${SeedBackupGate.CONFIRM_WORD}") }, - modifier = Modifier - .fillMaxWidth() - .testTag("wallet-seed-confirm-input"), - ) - Spacer(Modifier.height(8.dp)) - Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) { - Button( - onClick = onDone, - enabled = SeedBackupGate.confirmEnabled(typed), - modifier = Modifier.testTag("wallet-seed-confirm-done"), - ) { Text("Done") } - } - } + OwSectionTitle("Back up this seed") + Spacer(Modifier.height(8.dp)) + Text( + "These 25 words are the only way to recover this wallet, and anyone who " + + "reads them can spend it. Write them down now — this is the only copy.", + style = MaterialTheme.typography.bodySmall, + color = OwColors.TextSecondary, + ) + Spacer(Modifier.height(12.dp)) + Mono( + seed, + modifier = Modifier + .fillMaxWidth() + .testTag("wallet-seed-words"), + ) + Spacer(Modifier.height(16.dp)) + Text( + "Type ${SeedBackupGate.CONFIRM_WORD} to confirm you have written it down.", + style = MaterialTheme.typography.labelSmall, + color = OwColors.TextSecondary, + ) + Spacer(Modifier.height(4.dp)) + OutlinedTextField( + value = typed, + onValueChange = onTyped, + singleLine = true, + label = { Text("type ${SeedBackupGate.CONFIRM_WORD}") }, + modifier = Modifier + .fillMaxWidth() + .testTag("wallet-seed-confirm-input"), + ) + Spacer(Modifier.height(10.dp)) + OwButton( + text = "Done", + variant = OwButtonVariant.Primary, + enabled = SeedBackupGate.confirmEnabled(typed), + onClick = onDone, + modifier = Modifier.testTag("wallet-seed-confirm-done"), + ) } } @Composable private fun TransferCard(t: TransferRow) { - Card( - modifier = Modifier.fillMaxWidth(), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceVariant, - ), - ) { + OwCard(modifier = Modifier.fillMaxWidth(), padding = 12.dp) { Row( - modifier = Modifier - .fillMaxWidth() - .padding(12.dp), + Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, ) { - Column(modifier = Modifier.weight(1f)) { - Text( - t.txid.take(16) + "…", - style = MaterialTheme.typography.bodySmall, - fontFamily = FontFamily.Monospace, - ) - Text( - t.address, - style = MaterialTheme.typography.labelSmall, - fontFamily = FontFamily.Monospace, - color = MaterialTheme.colorScheme.onSurfaceVariant, + Column(Modifier.weight(1f)) { + Mono(t.txid.take(16) + "…", color = OwColors.TextSecondary) + Spacer(Modifier.height(2.dp)) + Mono( + t.address.take(12) + "…" + t.address.takeLast(4), + color = OwColors.TextMuted, ) } + Spacer(Modifier.width(12.dp)) Text( t.amount, - style = MaterialTheme.typography.bodyMedium, - fontFamily = FontFamily.Monospace, + style = MaterialTheme.typography.titleSmall, + color = OwColors.TextPrimary, + textAlign = TextAlign.End, ) } } @@ -688,64 +1168,64 @@ private fun PayComposer( var memo by remember { mutableStateOf("") } val ready = selected != null && amount.trim().isNotEmpty() - Card( + OwCard( modifier = Modifier .fillMaxWidth() - .padding(12.dp), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceVariant, - ), + .padding(horizontal = 16.dp, vertical = 8.dp), ) { - Column(Modifier.padding(12.dp)) { + OwSectionTitle(if (kind == PayKind.Invoice) "Send invoice" else "Send tip") + Spacer(Modifier.height(8.dp)) + if (friends.isEmpty()) { Text( - if (kind == PayKind.Invoice) "Send invoice" else "Send tip", - style = MaterialTheme.typography.titleSmall, + "Add a contact first. Invoice and tip are one-shot to a peer onion.", + style = MaterialTheme.typography.bodySmall, + color = OwColors.TextSecondary, ) - Spacer(Modifier.height(8.dp)) - if (friends.isEmpty()) { - Text( - "Add a friend first. Invoice and tip are one-shot to a peer onion.", - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - } else { - Text("to", style = MaterialTheme.typography.labelSmall) - friends.forEach { f -> - val label = f.petname?.takeIf { it.isNotBlank() } ?: f.fingerprint - TextButton(onClick = { selected = f.pubkeyHex }) { - Text(if (selected == f.pubkeyHex) "• $label" else label) - } + } else { + Label("TO") + friends.forEach { f -> + val label = f.petname?.takeIf { it.isNotBlank() } ?: f.fingerprint + TextButton(onClick = { selected = f.pubkeyHex }) { + Text(if (selected == f.pubkeyHex) "• $label" else label) } } - OutlinedTextField( - value = amount, - onValueChange = { amount = it }, - singleLine = true, - label = { Text("amount XMR") }, - modifier = Modifier.fillMaxWidth(), + } + Spacer(Modifier.height(4.dp)) + OutlinedTextField( + value = amount, + onValueChange = { amount = it }, + singleLine = true, + label = { Text("amount XMR") }, + modifier = Modifier.fillMaxWidth(), + ) + Spacer(Modifier.height(8.dp)) + OutlinedTextField( + value = memo, + onValueChange = { memo = it }, + singleLine = true, + label = { Text("memo (optional)") }, + modifier = Modifier.fillMaxWidth(), + ) + Spacer(Modifier.height(12.dp)) + OwButtonRow { + OwButton( + text = "Cancel", + variant = OwButtonVariant.Outline, + onClick = onCancel, + modifier = Modifier.weight(1f), ) - Spacer(Modifier.height(8.dp)) - OutlinedTextField( - value = memo, - onValueChange = { memo = it }, - singleLine = true, - label = { Text("memo (optional)") }, - modifier = Modifier.fillMaxWidth(), + OwButton( + text = "Send", + variant = OwButtonVariant.Primary, + enabled = ready, + onClick = { + // Dead button without a recipient, and `ready` says so; the + // null check is only here because `selected` is nullable. + val pk = selected + if (pk != null) onSend(pk, amount.trim(), memo.trim()) + }, + modifier = Modifier.weight(1f), ) - Spacer(Modifier.height(8.dp)) - Row( - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.End, - ) { - TextButton(onClick = onCancel) { Text("Cancel") } - Button( - onClick = { - val pk = selected ?: return@Button - onSend(pk, amount.trim(), memo.trim()) - }, - enabled = ready, - ) { Text("Send") } - } } } } @@ -767,377 +1247,83 @@ private fun WalletSetupCard( var seed by remember { mutableStateOf("") } val ready = password.isNotEmpty() && (kind == SetupKind.Create || seed.isNotBlank()) - Card( + OwCard( modifier = Modifier .fillMaxWidth() - .padding(12.dp), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceVariant, - ), + .padding(horizontal = 16.dp, vertical = 8.dp), ) { - Column(Modifier.padding(12.dp)) { - Text( - if (kind == SetupKind.Create) "Create wallet" else "Import wallet", - style = MaterialTheme.typography.titleSmall, - ) - Spacer(Modifier.height(8.dp)) - if (kind == SetupKind.Create && !accepted) { - Text(warning, style = MaterialTheme.typography.bodySmall) - Spacer(Modifier.height(8.dp)) - Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) { - TextButton(onClick = onCancel) { Text("Cancel") } - Button(onClick = { accepted = true }) { Text("I accept spend authority") } - } - return@Column - } - if (kind == SetupKind.Import) { - Text( - "Paste the 25-word seed. Create does not need a key.", - style = MaterialTheme.typography.bodySmall, + OwSectionTitle(if (kind == SetupKind.Create) "Create wallet" else "Import wallet") + Spacer(Modifier.height(8.dp)) + if (kind == SetupKind.Create && !accepted) { + Text(warning, style = MaterialTheme.typography.bodySmall, color = OwColors.TextSecondary) + Spacer(Modifier.height(12.dp)) + OwButtonRow { + OwButton( + text = "Cancel", + variant = OwButtonVariant.Outline, + onClick = onCancel, + modifier = Modifier.weight(1f), ) - Spacer(Modifier.height(8.dp)) - OutlinedTextField( - value = seed, - onValueChange = { seed = it }, - label = { Text("seed") }, - modifier = Modifier.fillMaxWidth(), + OwButton( + text = "I accept spend authority", + variant = OwButtonVariant.Primary, + onClick = { accepted = true }, + modifier = Modifier.weight(1f), ) - Spacer(Modifier.height(8.dp)) - } - OutlinedTextField( - value = password, - onValueChange = { password = it }, - singleLine = true, - label = { Text("wallet passphrase") }, - modifier = Modifier.fillMaxWidth(), - ) - Spacer(Modifier.height(8.dp)) - Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) { - TextButton(onClick = onCancel) { Text("Cancel") } - Button( - onClick = { - scope.launch { - when (kind) { - SetupKind.Create -> create(password).fold( - onSuccess = onCreated, - onFailure = { onError(it.message ?: it.toString()) }, - ) - SetupKind.Import -> importWallet(password, seed.trim()).fold( - onSuccess = { onImported() }, - onFailure = { onError(it.message ?: it.toString()) }, - ) - } - } - }, - enabled = ready, - ) { Text(if (kind == SetupKind.Create) "Create" else "Import") } } + return@OwCard } - } -} - -/** - * The app-owned `monero-wallet-rpc` control (issue #107), now with the third chain - * source: the chain daemon **inside this app** (Cuprate). - * - * **Start** / **Stop** drive `Wire::start_wallet_child` / `stop_wallet_child` - * through [WireViewModel]; the status line is `Wire::wallet_status()` rendered - * verbatim, so a child that died reads `exited` and never `off`, and an in-process - * source grows a `node ` segment that is the core's own `node_state`. - * - * The card is deliberately talkative about what it *cannot* do: no bundled - * binary, no chain source, a `.onion` daemon with no bundled `arti` SOCKS child, - * or a build without `cuprate-daemon` each get their own sentence, because a Start - * button that can only fail is worse than no button. There is no "starting…" state - * to hide behind — the only spinner-free words on screen are the core's own. - * - * The on-device node is opt-in and carries its pre-production warning **above the - * Start button**, plus the free space on the filesystem its fjall store grows - * into. A device that cannot hold the chain is told before it commits, not left to - * fail at sync time. - */ -@Composable -private fun WalletChildCard( - bins: WalletChildBinaryPaths, - input: WalletChildInput?, - chain: ChainConfig?, - nodeFreeBytes: Long?, - actionError: String?, - daemonText: String, - daemonError: String?, - /** - * The core's `wallet_open` / `needs_passphrase`, straight off the same - * `WalletChildStatus` the status line is drawn from — not a second idea of - * which wallet is open. - */ - walletOpen: Boolean, - needsPassphrase: Boolean, - onDaemonText: (String) -> Unit, - onSaveDaemon: () -> Unit, - onReceiveOnly: () -> Unit, - onInProcessNode: (mainnet: Boolean, prune: Boolean) -> Unit, - starting: Boolean = false, - onStart: () -> Unit, - onStop: () -> Unit, -) { - val phase = walletChildPhase(input) - val node = nodePhase(input) - val onionDaemon = chain?.kind == ChainChoice.REMOTE && isOnionHost(chain.host) - // The selection is in-process as soon as it is stored, before the first status - // read comes back: the warning and the storage line must not wait for the - // poller, or the user would press Start having seen neither. - val inProcess = input?.chainInProcess == true || chain?.kind == ChainChoice.IN_PROCESS_CUPRATE - val startWhy = startBlockedReason(bins, input, onionDaemon, starting) - ?: if (inProcess) { - chainStorageBlockedReason( - nodeFreeBytes, - mainnet = chain?.mainnet == true, - prune = chain?.prune == true, - ) - } else { - null - } - val stopWhy = stopBlockedReason(input) - // A live child with no wallet file open answers every read with the daemon's - // own `-13 No wallet file`. Say that in this app's words, here, rather than - // letting the raw string arrive later on whichever card asked. - val openHint = walletChildOpenHint( - childRunning = input?.running == true, - walletOpen = walletOpen, - needsPassphrase = needsPassphrase, - ) - - Card( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 12.dp, vertical = 8.dp), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceVariant, - ), - ) { - Column(Modifier.padding(12.dp)) { - Text("wallet daemon", style = MaterialTheme.typography.titleSmall) - Spacer(Modifier.height(6.dp)) - - // The core's own words: `ready · remote onion daemon`, plus - // `· node syncing` for the in-process source. Tagged with the phase so - // a UI test can assert `exited` is never `off`. + if (kind == SetupKind.Import) { Text( - walletChildLine(input), + "Paste the 25-word seed. Create does not need a key.", style = MaterialTheme.typography.bodySmall, - fontFamily = FontFamily.Monospace, - modifier = Modifier - .fillMaxWidth() - .testTag(phase.testTag) - .semantics(mergeDescendants = true) { - contentDescription = walletChildStatusDescription(input) - }, + color = OwColors.TextSecondary, ) - - // The node's own word, when there is one, as its own assertable line: - // an unrecognised node state can never be read as ready. - if (node !is NodePhase.Absent) { - Text( - "node: ${node.label}", - style = MaterialTheme.typography.labelSmall, - fontFamily = FontFamily.Monospace, - color = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = Modifier - .fillMaxWidth() - .testTag(node.testTag) - .semantics(mergeDescendants = true) { - contentDescription = node.contentDescription - }, - ) - } - - if (!bins.walletRpcBundled) { - Spacer(Modifier.height(6.dp)) - Text( - NO_WALLET_RPC_MESSAGE, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.error, - modifier = Modifier.fillMaxWidth(), - ) - } - - // "No wallet file open" is a state of a live child, not a failure of - // the last call, so it is said here rather than left to surface as - // the daemon's `-13` on whichever card asked for a read. - openHint?.let { - Spacer(Modifier.height(6.dp)) - Text( - it, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = Modifier - .fillMaxWidth() - .testTag("wallet-child-no-wallet"), - ) - } - - // What the user can fix from here: which daemon the child dials. Spacer(Modifier.height(8.dp)) OutlinedTextField( - value = daemonText, - onValueChange = onDaemonText, - singleLine = true, - label = { Text("daemon host:port") }, - supportingText = { - Text( - "A daemon on your LAN (e.g. 192.168.1.20:18089) or a public node's " + - "clearnet address. A phone cannot run monerod — for a chain with no " + - "daemon at all, use the on-device node below.", - style = MaterialTheme.typography.labelSmall, - ) - }, - modifier = Modifier - .fillMaxWidth() - .testTag("wallet-daemon-input"), - ) - Spacer(Modifier.height(4.dp)) - Row( + value = seed, + onValueChange = { seed = it }, + label = { Text("seed") }, modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.spacedBy(8.dp), - ) { - OutlinedButton( - onClick = onSaveDaemon, - enabled = bins.walletRpcBundled, - modifier = Modifier - .weight(1f) - .testTag("wallet-daemon-save"), - ) { Text("Save daemon") } - OutlinedButton( - onClick = onReceiveOnly, - modifier = Modifier - .weight(1f) - .testTag("wallet-daemon-receive-only"), - ) { Text("Receive-only") } - } - - // Tapping a mode stores it and, when the storage floor allows, - // starts the node. Filled = the stored choice. + ) Spacer(Modifier.height(8.dp)) - val mode = selectedCuprateMode( - inProcess = inProcess, - mainnet = chain?.mainnet == true, - prune = chain?.prune == true, - ) - CuprateModeButton( - label = "Mainnet pruned", - selected = mode == CuprateMode.MainnetPruned, - testTag = "wallet-chain-mainnet-pruned", - onClick = { onInProcessNode(true, true) }, - ) - Spacer(Modifier.height(4.dp)) - CuprateModeButton( - label = "Mainnet full", - selected = mode == CuprateMode.MainnetFull, - testTag = "wallet-chain-mainnet-full", - onClick = { onInProcessNode(true, false) }, - ) - Spacer(Modifier.height(4.dp)) - CuprateModeButton( - label = "Testnet (experimental)", - selected = mode == CuprateMode.Testnet, - testTag = "wallet-chain-in-process", - onClick = { onInProcessNode(false, false) }, - ) - - if (inProcess) { - Spacer(Modifier.height(8.dp)) - Text( - CUPRATE_PREPRODUCTION_WARNING, - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = Modifier - .fillMaxWidth() - .testTag("wallet-cuprate-warning"), - ) - Spacer(Modifier.height(4.dp)) - Text( - chainStorageLine( - nodeFreeBytes, - mainnet = chain?.mainnet == true, - prune = chain?.prune == true, - ), - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = Modifier - .fillMaxWidth() - .testTag("wallet-chain-storage"), - ) - } - - Spacer(Modifier.height(8.dp)) - Row( - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.spacedBy(8.dp), - ) { - Button( - onClick = onStart, - enabled = startWhy == null, - modifier = Modifier - .weight(1f) - .testTag("wallet-child-start"), - ) { Text("Start wallet") } - OutlinedButton( - onClick = onStop, - enabled = stopWhy == null, - modifier = Modifier - .weight(1f) - .testTag("wallet-child-stop"), - ) { Text("Stop wallet") } - } - - // Why Start is dead, in the core's terms rather than a grey button. - startWhy?.let { - Spacer(Modifier.height(6.dp)) - Text( - it, - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = Modifier - .fillMaxWidth() - .testTag("wallet-child-start-blocked"), - ) - } - - // The last thing the core or the RPC call said. Sticky until the - // user acts, like the chat screen's load error. Filtered through - // `walletFailureText`: the daemon's own `-13 No wallet file` / JSON - // answer is not a sentence about this app and never reaches the - // screen. - val failure = walletFailureText(input?.lastError) ?: actionError ?: daemonError - failure?.let { - Spacer(Modifier.height(6.dp)) - Text( - it, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.error, - modifier = Modifier - .fillMaxWidth() - .testTag("wallet-child-error"), - ) - } } - } -} - -@Composable -private fun CuprateModeButton( - label: String, - selected: Boolean, - testTag: String, - onClick: () -> Unit, -) { - val modifier = Modifier - .fillMaxWidth() - .testTag(testTag) - if (selected) { - Button(onClick = onClick, modifier = modifier) { Text(label) } - } else { - OutlinedButton(onClick = onClick, modifier = modifier) { Text(label) } + OutlinedTextField( + value = password, + onValueChange = { password = it }, + singleLine = true, + label = { Text("wallet passphrase") }, + modifier = Modifier.fillMaxWidth(), + ) + Spacer(Modifier.height(12.dp)) + OwButtonRow { + OwButton( + text = "Cancel", + variant = OwButtonVariant.Outline, + onClick = onCancel, + modifier = Modifier.weight(1f), + ) + OwButton( + text = if (kind == SetupKind.Create) "Create" else "Import", + variant = OwButtonVariant.Primary, + enabled = ready, + onClick = { + scope.launch { + when (kind) { + SetupKind.Create -> create(password).fold( + onSuccess = onCreated, + onFailure = { onError(it.message ?: it.toString()) }, + ) + SetupKind.Import -> importWallet(password, seed.trim()).fold( + onSuccess = { onImported() }, + onFailure = { onError(it.message ?: it.toString()) }, + ) + } + } + }, + modifier = Modifier.weight(1f), + ) + } } } @@ -1149,7 +1335,7 @@ private fun CuprateModeButton( * `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. + * `Balance unavailable` after the wallet comes up. */ internal fun shouldReloadWalletReads(state: String?): Boolean { val s = state?.trim()?.lowercase() @@ -1162,16 +1348,16 @@ internal fun shouldReloadWalletReads(state: String?): Boolean { * * `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. A probe that dialled a port the child had not bound yet can also + * this screen exists for: a live wallet with no wallet file 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 wallet 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. + * that one while the wallet is still `connecting`. The status header renders + * this field through `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, diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/SegmentedControl.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/SegmentedControl.kt index 11be548..c5f2f2b 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/SegmentedControl.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/components/SegmentedControl.kt @@ -17,6 +17,7 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.platform.testTag import androidx.compose.ui.semantics.Role import androidx.compose.ui.semantics.role import androidx.compose.ui.semantics.selected @@ -42,6 +43,14 @@ fun OwSegmentedControl( onSelect: (Int) -> Unit, modifier: Modifier = Modifier, enabled: Boolean = true, + /** + * Optional per-segment `testTag`s, one per option. Additive: omitted (the + * default) leaves every existing call site byte-identical. It exists because + * a merged "Pruned / Full / Testnet" track has no per-value handle otherwise, + * and the wallet screen's tests address each segment by the tag it had when + * the three options were three stacked buttons. + */ + testTags: List = emptyList(), ) { Row( modifier = modifier @@ -67,12 +76,14 @@ fun OwSegmentedControl( animationSpec = tween(durationMillis = 160), label = "segment-text", ) + val tag = testTags.getOrNull(index) Box( modifier = Modifier .weight(1f) .height(36.dp) .clip(RoundedCornerShape(9.dp)) .background(container) + .then(if (tag != null) Modifier.testTag(tag) else Modifier) .clickable(enabled = enabled && !selected) { onSelect(index) } .semantics { role = Role.Tab diff --git a/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletChildStatusTextTest.kt b/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletChildStatusTextTest.kt index aa92f6c..def027a 100644 --- a/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletChildStatusTextTest.kt +++ b/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletChildStatusTextTest.kt @@ -207,8 +207,8 @@ class WalletChildStatusTextTest { @Test fun stop_is_blocked_when_nothing_is_running() { - assertTrue(stopBlockedReason(input("off"))!!.contains("No wallet child")) - assertTrue(stopBlockedReason(input("exited"))!!.contains("No wallet child")) + assertTrue(stopBlockedReason(input("off"))!!.contains("No wallet is running")) + assertTrue(stopBlockedReason(input("exited"))!!.contains("No wallet is running")) assertEquals(READING_CHILD_NOTICE, stopBlockedReason(null)) } @@ -397,7 +397,7 @@ class WalletChildStatusTextTest { "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")) + assertTrue("it is still a sentence", spoken.startsWith("The wallet is starting")) } @Test @@ -417,14 +417,17 @@ class WalletChildStatusTextTest { } @Test - fun the_preproduction_warning_is_a_sentence_a_user_can_act_on() { - val warning = CUPRATE_PREPRODUCTION_WARNING - assertTrue("it names the software", warning.contains("Cuprate")) - assertTrue("it quotes the user book", warning.contains("do NOT use cuprated")) - assertTrue("it names the parity gap", warning.contains("Cuprate issue #278")) - assertTrue("it says mainnet is unvalidated", warning.contains("mainnet is unvalidated")) - assertTrue("it is a sentence, not a glyph", warning.trim().endsWith(".")) - assertTrue("it is long enough to be a sentence", warning.length > 80) + fun the_on_device_banner_is_titled_and_says_what_it_costs() { + // The banner's title is the plan's exact string; the body keeps every + // honesty bound the old single-sentence warning carried. + assertEquals("Experimental On-Device Node (Cuprate)", CUPRATE_ON_DEVICE_TITLE) + val body = CUPRATE_ON_DEVICE_BODY + assertTrue("it names the software", body.contains("Cuprate")) + assertTrue("it names the parity gap", body.contains("#278")) + assertTrue("it quotes the user book", body.contains("do NOT use cuprated")) + assertTrue("it says mainnet is unvalidated", body.contains("Mainnet is unvalidated")) + assertTrue("it says not to hold funds", body.contains("Do not use for significant funds")) + assertTrue("it is a sentence, not a glyph", body.trim().endsWith(".")) } // --- storage honesty ---------------------------------------------------- @@ -519,4 +522,103 @@ class WalletChildStatusTextTest { assertEquals("1.5 GiB", formatBytes(3L * 1024 * 1024 * 1024 / 2)) assertEquals("3.0 GiB", formatBytes(CHAIN_FREE_SPACE_FLOOR_BYTES)) } + + // --- the node card's progress header (plan P4.3) ------------------------- + + @Test + fun block_counts_group_by_three_regardless_of_locale() { + assertEquals("0", formatBlockCount(0uL)) + assertEquals("999", formatBlockCount(999uL)) + assertEquals("1,000", formatBlockCount(1_000uL)) + assertEquals("485,253", formatBlockCount(485_253uL)) + assertEquals("3,794,383", formatBlockCount(3_794_383uL)) + assertEquals("12,345,678", formatBlockCount(12_345_678uL)) + } + + @Test + fun the_progress_header_says_percent_and_formatted_blocks() { + val p = syncProgress(485_253uL, 3_794_383uL) + assertEquals("12.8%", p.percentText) + assertEquals("Block 485,253 of 3,794,383", p.blockText) + assertTrue("a fraction of the track", p.fraction > 0.12f && p.fraction < 0.13f) + } + + @Test + fun a_caught_up_node_fills_the_track_and_does_not_overflow() { + val atTip = syncProgress(3_794_383uL, 3_794_383uL) + assertEquals("100.0%", atTip.percentText) + assertEquals(1f, atTip.fraction) + // A daemon one block ahead of the target it reported must not render + // 108% — the bar clamps and the text is the clamped number. + val ahead = syncProgress(4_100_000uL, 3_794_383uL) + assertEquals("100.0%", ahead.percentText) + assertEquals(1f, ahead.fraction) + } + + @Test + fun an_unknown_target_is_never_a_percentage() { + // `target_height == 0` is "the daemon reported no target" — Cuprate + // omits it even at the tip. Printing 100% there would claim synced. + val p = syncProgress(4_549uL, 0uL) + assertNull("no percent from a zero target", p.percentText) + assertEquals(0f, p.fraction) + assertEquals("Block 4,549 of an unknown target", p.blockText) + assertFalse("no percent string leaks", p.blockText!!.contains("%")) + } + + @Test + fun no_numbers_means_no_progress_row() { + val p = syncProgress(0uL, 0uL) + assertNull(p.percentText) + assertNull(p.blockText) + assertEquals(0f, p.fraction) + } + + @Test + fun the_three_modes_are_named_the_way_the_stored_choice_reads() { + assertEquals("Mainnet Pruned", chainModeLabel(mainnet = true, prune = true)) + assertEquals("Mainnet Full", chainModeLabel(mainnet = true, prune = false)) + assertEquals("Testnet", chainModeLabel(mainnet = false, prune = false)) + } + + @Test + fun the_node_header_never_reads_ready_without_the_cores_word() { + assertEquals("Wallet Offline", nodeStatusHead(input("off", configured = false)).title) + assertEquals("Connecting…", nodeStatusHead(input("connecting", running = true)).title) + assertEquals(NodeStatusTone.Busy, nodeStatusHead(input("connecting", running = true)).tone) + assertTrue( + "a running child that has not answered is not ready", + nodeStatusHead(input("connecting", running = true)).tone != NodeStatusTone.Good, + ) + assertEquals(NodeStatusTone.Good, nodeStatusHead(input("ready", running = true)).tone) + assertEquals(NodeStatusTone.Bad, nodeStatusHead(input("mining", running = true)).tone) + assertEquals( + "an unknown state is never green", + NodeStatusTone.Bad, + nodeStatusHead(input("mining", running = true)).tone, + ) + assertEquals("Wallet Stopped", nodeStatusHead(input("exited")).title) + assertEquals("Reading wallet status", nodeStatusHead(null).title) + } + + @Test + fun the_node_header_names_the_mode_only_for_the_on_device_node() { + assertEquals( + "Syncing Node (Mainnet Pruned)", + nodeStatusHead( + node(state = "syncing", chainSource = "in-process mainnet pruned", nodeState = "syncing"), + inProcess = true, + mainnet = true, + prune = true, + ).title, + ) + assertEquals( + "Node Idle (Testnet)", + nodeStatusHead(input("off", configured = false), inProcess = true, mainnet = false).title, + ) + assertEquals( + "Syncing Wallet", + nodeStatusHead(input("syncing", running = true, chainSource = "remote daemon")).title, + ) + } } From 0d0b0b975dc54881fb3a0274b65c0f22b66e39ee Mon Sep 17 00:00:00 2001 From: agent Date: Thu, 29 Oct 2026 01:01:45 -0400 Subject: [PATCH 02/10] ui: saved-wallets screen and profile copy on the shared components (plan P4.1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The catalogue screen was still the alpha build: a TopAppBar with a text "Back" and a text "Refresh", eight hand-rolled Cards on Material's surfaceVariant, outlined twins for the two secret actions, and every failure — including "no wallet is open", which is a state the app is in, not a failure — printed as a raw red Text. It now uses the shared components: a chevron top bar, OwCard rows with an "In use" pill, and OwButton tiers. Copy, verbatim from the plan: "No wallet is open in the wallet child yet. Open a saved wallet on the Saved wallets screen, or create or import one here." -> "Select a saved wallet or create a new one to view your balance and transact." "No wallet is open in the wallet child yet. Open one from the list below — a wallet that needs a passphrase asks for it here — and the balance, address and backups work again." -> "Open or create a wallet to enable balance, address, and backup controls." WALLET_NOT_OPEN_TEXT is now rendered as an info banner with its own title, not as an error; ErrorText picks the variant from the text, so the same string cannot read as a crash on one screen and a state on the other. The "no wallet open" hint, the passphrase prompt's blocked reasons and its "wallet is not running" line, and the catalogue/keys failures are banners too. The two remaining user-facing mentions of the daemon process are gone: the passphrase card says "the wallet is pointed at " and the secrets block reason says "the wallet is not running". ProfileScreen's empty-address notice loses its copy of the same phrase ("then comes from the running wallet"), and its test now asserts the consequence instead of the internal name. No behaviour change: every predicate (walletSecretsEnabled, walletPassphraseSubmitEnabled, walletChildReadable, walletFailureText, displayLastError) is the same function with the same branches; only strings and layout moved. The four WalletManagerTest assertions that pinned the old strings are updated here, in the same commit, as the card requires. --- .../onionwire/ui/ProfileScreen.kt | 8 +- .../onionwire/ui/WalletManagerScreen.kt | 510 +++++++++--------- .../onionwire/ui/ProfileDraftTest.kt | 4 +- .../onionwire/ui/WalletManagerTest.kt | 15 +- 4 files changed, 272 insertions(+), 265 deletions(-) diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/ProfileScreen.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/ProfileScreen.kt index a0e3243..5ef799d 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/ProfileScreen.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/ProfileScreen.kt @@ -56,7 +56,7 @@ import uniffi.onionwire_sdk.checkAddress * store error after it. * - An **empty** address is a real, allowed value: it clears the profile * address. It is labelled with its consequence, because with no profile - * address and no running wallet child the core has nothing to hand a payer + * address and no running wallet the core has nothing to hand a payer * (`Node::wallet_receive_address`) and the invoice path fails. * - The bio is carried, not owned: a save that did not touch the bio field * writes back the value read from the store immediately before the write, so @@ -211,7 +211,7 @@ fun ProfileScreen( supportingText = { Text( // The consequence, on the screen, before a payment fails: - // `Node::wallet_receive_address` uses the wallet child's + // `Node::wallet_receive_address` uses the wallet process's // subaddress while it is up and this address otherwise, // and with neither there is nothing to be paid to. profileAddressNotice(form.address), @@ -437,7 +437,7 @@ internal const val PROFILE_SAVED: String = "profile saved" /** * What an empty address means, stated where the address is typed. * - * `Node::wallet_receive_address` answers with the wallet child's own subaddress + * `Node::wallet_receive_address` answers with the wallet process's own subaddress * while it is up, and this address otherwise; with neither, the invoice path * fails outright. The user should read that here, not after a friend's payment * bounces. @@ -445,7 +445,7 @@ internal const val PROFILE_SAVED: String = "profile saved" internal fun profileAddressNotice(address: String): String = if (address.trim().isEmpty()) { "Empty is allowed, and it clears the profile address. Your receive address " + - "then comes from the wallet child while it is running — with no address " + + "then comes from the running wallet — with no address " + "here and no wallet running, nobody can send you an invoice." } else { "What friends pay to. Validated before it is saved; an invalid address is " + 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..68884be 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 @@ -14,20 +14,13 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.Button -import androidx.compose.material3.Card -import androidx.compose.material3.CardDefaults -import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.OutlinedButton import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Scaffold import androidx.compose.material3.Text -import androidx.compose.material3.TextButton -import androidx.compose.material3.TopAppBar -import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect @@ -40,11 +33,21 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalView import androidx.compose.ui.platform.testTag -import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.siriusdevops.onionwire.WireViewModel +import com.siriusdevops.onionwire.ui.components.Label +import com.siriusdevops.onionwire.ui.components.Mono +import com.siriusdevops.onionwire.ui.components.OwAlertBanner +import com.siriusdevops.onionwire.ui.components.OwAlertVariant +import com.siriusdevops.onionwire.ui.components.OwButton +import com.siriusdevops.onionwire.ui.components.OwButtonRow +import com.siriusdevops.onionwire.ui.components.OwButtonVariant +import com.siriusdevops.onionwire.ui.components.OwCard +import com.siriusdevops.onionwire.ui.components.OwPill +import com.siriusdevops.onionwire.ui.components.OwSectionTitle +import com.siriusdevops.onionwire.ui.components.OwTopBar import kotlinx.coroutines.launch import uniffi.onionwire_sdk.WalletKeys import uniffi.onionwire_sdk.WalletRow @@ -83,7 +86,7 @@ internal fun walletRowDate(createdAt: Long): String { } /** - * Whether the wallet child has a wallet open that the RPC answers for. + * Whether the wallet process has a wallet open that the RPC answers for. * * The core's `state` is the only honest signal available here: `connecting` * means its wallet RPC has not answered, `off`/`exited` mean there is no child @@ -126,8 +129,8 @@ internal fun walletSecretsBlockedReason( isActive: Boolean, walletReadable: Boolean, ): String? = when { - !isActive -> "open this wallet to view its backup" - !walletReadable -> "the wallet child is not running — start it on the wallet screen to read the backup" + !isActive -> "Open this wallet to view its backup." + !walletReadable -> "The wallet is not running — start it on the wallet screen to read the backup." else -> null } @@ -159,14 +162,18 @@ private val RAW_RPC_CODE = Regex("""(? - "the wallet child is not pointed at a wallet file yet — open one from the list below" - typed.isEmpty() -> "type the passphrase for this wallet file" + "No wallet file is open yet — open one from the list below." + typed.isEmpty() -> "Type the passphrase for this wallet file." else -> null } /** - * Why the wallet child has nothing open, in this app's words — or `null` when - * it has a wallet open, or no child is running to hold one. + * Why the wallet process has nothing open, in this app's words — or `null` when + * it has a wallet open, or nothing is running to hold one. * * A live `monero-wallet-rpc` is not a usable wallet: it starts with no wallet * file open, and every read then answers `-13 No wallet file`. The status line @@ -294,11 +301,10 @@ internal fun walletChildOpenHint( ): String? = when { !childRunning || walletOpen -> null needsPassphrase -> - "No wallet is open in the wallet child: it needs the passphrase for the file it is " + - "pointed at. Open it on the Saved wallets screen, where the prompt is." + "The wallet needs its passphrase: open it on the Saved wallets screen, where the " + + "prompt is." else -> - "No wallet is open in the wallet child yet. Open a saved wallet on the Saved wallets " + - "screen, or create or import one here." + "Select a saved wallet or create a new one to view your balance and transact." } /** @@ -319,7 +325,6 @@ internal fun walletChildOpenHint( * in saved state (`remember`, not `rememberSaveable`, and cleared on * dispose). */ -@OptIn(ExperimentalMaterial3Api::class) @Composable fun WalletManagerScreen( vm: WireViewModel, @@ -503,25 +508,24 @@ fun WalletManagerScreen( // Root owns systemBars ∪ ime, exactly as the wallet screen does (see // `screenContentInsets`). contentWindowInsets = WindowInsets(0, 0, 0, 0), + containerColor = OwColors.Canvas, topBar = { - TopAppBar( - title = { Text("Saved wallets") }, - navigationIcon = { - TextButton(onClick = onBack) { Text("Back") } - }, + OwTopBar( + title = "Saved wallets", + // A pushed sub-screen, so the chevron — never the word "Back". + onBack = onBack, actions = { - TextButton( + OwButton( + text = "Refresh", + variant = OwButtonVariant.Outline, onClick = { scope.launch { vm.refreshWalletChild() reload() } }, - ) { Text("Refresh") } + ) }, - colors = TopAppBarDefaults.topAppBarColors( - containerColor = MaterialTheme.colorScheme.background, - ), ) }, ) { pad -> @@ -559,22 +563,21 @@ fun WalletManagerScreen( ) } keysError?.let { message -> - Card( + OwAlertBanner( + variant = OwAlertVariant.Error, + title = "Could not read the open wallet's private keys", + description = message, modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 12.dp, vertical = 8.dp), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.errorContainer, - ), - ) { - Column(Modifier.padding(12.dp)) { - Text("could not read the open wallet's private keys") - Spacer(Modifier.height(4.dp)) - Text(message, style = MaterialTheme.typography.bodySmall) - Spacer(Modifier.height(8.dp)) - TextButton(onClick = { keysError = null }) { Text("Dismiss") } - } - } + .padding(horizontal = 16.dp, vertical = 8.dp) + .testTag("wallet-keys-error"), + action = { + OwButton( + text = "Dismiss", + variant = OwButtonVariant.Outline, + onClick = { keysError = null }, + ) + }, + ) } actionError?.let { ErrorText(it) } @@ -608,46 +611,55 @@ fun WalletManagerScreen( // A read failure is not an empty catalogue, and the two must // not read alike: one is "the store did not answer", the other // is "you have no wallets yet". - listError != null -> Column(Modifier.padding(12.dp)) { - Text( - "could not read the wallet catalogue", - style = MaterialTheme.typography.titleSmall, - color = MaterialTheme.colorScheme.error, - ) - Spacer(Modifier.height(4.dp)) - Text( - listError ?: "", - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.error, - ) - Spacer(Modifier.height(8.dp)) - TextButton(onClick = { scope.launch { reload() } }) { Text("Retry") } - } - - listed == null -> Text( - "loading…", - style = MaterialTheme.typography.bodyMedium, - modifier = Modifier.padding(12.dp), + listError != null -> OwAlertBanner( + variant = OwAlertVariant.Error, + title = "Could not read the wallet catalogue", + description = listError ?: "", + modifier = Modifier + .padding(horizontal = 16.dp, vertical = 8.dp) + .testTag("wallet-list-error"), + action = { + OwButton( + text = "Retry", + variant = OwButtonVariant.Outline, + onClick = { scope.launch { reload() } }, + ) + }, ) - listed.isEmpty() -> Column(Modifier.padding(12.dp)) { - Text("No saved wallets yet", style = MaterialTheme.typography.titleSmall) - Spacer(Modifier.height(4.dp)) + listed == null -> Text( + "Loading…", + style = MaterialTheme.typography.bodyMedium, + color = OwColors.TextSecondary, + modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp), + ) + + listed.isEmpty() -> OwCard( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp, vertical = 8.dp), + ) { + OwSectionTitle("No saved wallets yet") + Spacer(Modifier.height(6.dp)) Text( "Wallets this install remembers show up here. Create or import one " + "on the wallet screen and it appears on the next look.", style = MaterialTheme.typography.bodySmall, + color = OwColors.TextSecondary, + ) + Spacer(Modifier.height(12.dp)) + OwButton( + text = "Create or import a wallet", + variant = OwButtonVariant.Primary, + onClick = onBack, + modifier = Modifier.fillMaxWidth(), ) - Spacer(Modifier.height(8.dp)) - Button(onClick = onBack) { Text("Create or import a wallet") } } else -> { - Text( - "${listed.size} saved ${if (listed.size == 1) "wallet" else "wallets"}", - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp), + Label( + "${listed.size} SAVED ${if (listed.size == 1) "WALLET" else "WALLETS"}", + modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp), ) listed.forEach { row -> val isActive = active != null && active == row.walletFilename @@ -680,7 +692,7 @@ fun WalletManagerScreen( * and whether it is the open one. * * The open row is not tappable. Re-opening it would stop and restart a running - * wallet child onto the file it already has open — a slow no-op whose only + * wallet process onto the file it already has open — a slow no-op whose only * effect is to make the screen look like it did something. */ @Composable @@ -694,72 +706,70 @@ private fun WalletRowCard( onShowPhrase: () -> Unit, onShowKeys: () -> Unit, ) { - Card( + OwCard( modifier = Modifier .fillMaxWidth() - .padding(horizontal = 12.dp, vertical = 6.dp) + .padding(horizontal = 16.dp, vertical = 6.dp) .then(if (isActive) Modifier else Modifier.clickable(enabled = !opening, onClick = onOpen)), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceVariant, - ), ) { - Column(Modifier.padding(12.dp)) { - Row( - Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically, - ) { - Text( - walletRowLabel(row.name, row.walletFilename), - style = MaterialTheme.typography.titleSmall, + Row( + Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, + ) { + Text( + walletRowLabel(row.name, row.walletFilename), + style = MaterialTheme.typography.titleMedium, + color = OwColors.TextPrimary, + modifier = Modifier.weight(1f), + ) + Spacer(Modifier.width(8.dp)) + when { + isActive -> OwPill( + text = "In use", + textColor = OwColors.Accent, + container = OwColors.InfoTint, + borderColor = OwColors.InfoBorder, + dotColor = OwColors.Accent, ) - when { - isActive -> Text( - "in use", - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.primary, - ) - opening -> Text( - "opening…", - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - else -> Text( - "tap to open", - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - } + opening -> OwPill(text = "Opening…", textColor = OwColors.TextSecondary) + else -> OwPill(text = "Tap to open", textColor = OwColors.TextSecondary) } - Spacer(Modifier.height(4.dp)) - Text( - "file ${row.walletFilename}", - style = MaterialTheme.typography.bodySmall, - fontFamily = FontFamily.Monospace, - ) - Text( - "created ${walletRowDate(row.createdAt)}", - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) + } + Spacer(Modifier.height(8.dp)) + Label("FILE") + Mono(row.walletFilename) + Spacer(Modifier.height(4.dp)) + Text( + "Created ${walletRowDate(row.createdAt)}", + style = MaterialTheme.typography.bodySmall, + color = OwColors.TextSecondary, + ) - Spacer(Modifier.height(8.dp)) - Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { - OutlinedButton(onClick = onShowPhrase, enabled = secretsEnabled) { - Text("Recovery phrase") - } - OutlinedButton(onClick = onShowKeys, enabled = secretsEnabled) { - Text("Private keys") - } - } - blockedReason?.let { - Spacer(Modifier.height(4.dp)) - Text( - it, - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - } + Spacer(Modifier.height(10.dp)) + OwButtonRow { + OwButton( + text = "Recovery phrase", + variant = OwButtonVariant.Outline, + enabled = secretsEnabled, + onClick = onShowPhrase, + modifier = Modifier.weight(1f), + ) + OwButton( + text = "Private keys", + variant = OwButtonVariant.Outline, + enabled = secretsEnabled, + onClick = onShowKeys, + modifier = Modifier.weight(1f), + ) + } + blockedReason?.let { + Spacer(Modifier.height(6.dp)) + Text( + it, + style = MaterialTheme.typography.labelSmall, + color = OwColors.TextMuted, + ) } } } @@ -774,10 +784,10 @@ private fun WalletRowCard( * wallet file. It is never logged, never persisted, and the caller drops it when * the screen goes. * - * Submit is dead while the wallet child is not running: the core verifies a + * Submit is dead while the wallet is not running: the core verifies a * passphrase against a live daemon and refuses to seal an unverified one, so a - * tap there could only fail. When the child *is* up — including `connecting`, - * whose RPC has not answered yet — the core restarts it onto the file with this + * tap there could only fail. When it *is* up — including `connecting`, whose RPC + * has not answered yet — the core restarts it onto the file with this * passphrase, which is exactly the fix. */ @Composable @@ -791,77 +801,74 @@ private fun WalletPassphraseCard( error: String?, onSubmit: () -> Unit, ) { - Card( + OwCard( modifier = Modifier .fillMaxWidth() - .padding(horizontal = 12.dp, vertical = 8.dp) + .padding(horizontal = 16.dp, vertical = 8.dp) .testTag("wallet-passphrase-card"), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceVariant, - ), ) { - Column(Modifier.padding(12.dp)) { - Text("This wallet needs its passphrase", style = MaterialTheme.typography.titleSmall) - Spacer(Modifier.height(4.dp)) - Text( - "The wallet child is pointed at ${filename ?: "a wallet file"} but this install " + - "holds no passphrase that opens it — the wallet was created before the " + - "passphrase was stored, or on another device. Type it once: the wallet " + - "opens, and later starts reopen it on their own.", - style = MaterialTheme.typography.bodySmall, - ) + OwSectionTitle("This wallet needs its passphrase") + Spacer(Modifier.height(6.dp)) + Text( + "The wallet is pointed at ${filename ?: "a wallet file"} but this install " + + "holds no passphrase that opens it — the wallet was created before the " + + "passphrase was stored, or on another device. Type it once: the wallet " + + "opens, and later starts reopen it on their own.", + style = MaterialTheme.typography.bodySmall, + color = OwColors.TextSecondary, + ) + Spacer(Modifier.height(12.dp)) + OutlinedTextField( + value = typed, + onValueChange = onTyped, + singleLine = true, + // Masked on screen: this string opens a spend-capable wallet. + visualTransformation = PasswordVisualTransformation(), + label = { Text("wallet passphrase") }, + modifier = Modifier + .fillMaxWidth() + .testTag("wallet-passphrase-input"), + ) + Spacer(Modifier.height(6.dp)) + Text( + "Never copied to the clipboard, never logged, and dropped when you leave this screen.", + style = MaterialTheme.typography.labelSmall, + color = OwColors.TextSecondary, + ) + if (!childRunning) { Spacer(Modifier.height(8.dp)) - OutlinedTextField( - value = typed, - onValueChange = onTyped, - singleLine = true, - // Masked on screen: this string opens a spend-capable wallet. - visualTransformation = PasswordVisualTransformation(), - label = { Text("wallet passphrase") }, - modifier = Modifier - .fillMaxWidth() - .testTag("wallet-passphrase-input"), + OwAlertBanner( + variant = OwAlertVariant.Info, + title = "The wallet is not running", + description = "Start it on the wallet screen, then come back.", ) - Spacer(Modifier.height(4.dp)) - Text( - "Never copied to the clipboard, never logged, and dropped when you leave this screen.", - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - if (!childRunning) { - Spacer(Modifier.height(4.dp)) - Text( - "the wallet child is not running — start it on the wallet screen, then come back", - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - } - error?.let { - Spacer(Modifier.height(6.dp)) - Text( - it, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.error, - ) - } - blockedReason?.let { - Spacer(Modifier.height(4.dp)) - Text( - it, - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - } - Spacer(Modifier.height(8.dp)) - Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) { - Button( - onClick = onSubmit, - enabled = childRunning && - walletPassphraseSubmitEnabled(filename, typed, inFlight), - modifier = Modifier.testTag("wallet-passphrase-submit"), - ) { Text(if (inFlight) "Opening…" else "Open this wallet") } - } } + error?.let { + Spacer(Modifier.height(8.dp)) + OwAlertBanner( + variant = OwAlertVariant.Error, + title = "Could not open this wallet", + description = it, + ) + } + blockedReason?.let { + Spacer(Modifier.height(8.dp)) + OwAlertBanner( + variant = OwAlertVariant.Info, + title = "Not ready to open", + description = it, + ) + } + Spacer(Modifier.height(12.dp)) + OwButton( + text = if (inFlight) "Opening…" else "Open this wallet", + variant = OwButtonVariant.Primary, + enabled = childRunning && walletPassphraseSubmitEnabled(filename, typed, inFlight), + onClick = onSubmit, + modifier = Modifier + .fillMaxWidth() + .testTag("wallet-passphrase-submit"), + ) } } @@ -880,64 +887,57 @@ private fun PrivateKeysCard( warning: String, onDone: () -> Unit, ) { - Card( + OwCard( modifier = Modifier .fillMaxWidth() - .padding(horizontal = 12.dp, vertical = 8.dp), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.errorContainer, - ), + .padding(horizontal = 16.dp, vertical = 8.dp) + .testTag("wallet-private-keys-card"), ) { - Column(Modifier.padding(12.dp)) { - Text("Private keys of the open wallet", style = MaterialTheme.typography.titleSmall) - Spacer(Modifier.height(4.dp)) - Text(warning, style = MaterialTheme.typography.bodySmall) - Spacer(Modifier.height(8.dp)) + OwSectionTitle("Private keys of the open wallet") + Spacer(Modifier.height(6.dp)) + Text(warning, style = MaterialTheme.typography.bodySmall, color = OwColors.Danger) + Spacer(Modifier.height(12.dp)) + Label("VIEW KEY") + // Mono, and deliberately no testTag: a handle on a spend secret is a + // handle an automation can read back. + Mono(keys.viewKey, modifier = Modifier.fillMaxWidth()) + Spacer(Modifier.height(10.dp)) + val spend = keys.spendKey + if (spend != null) { + Label("SPEND KEY") + Mono(spend, modifier = Modifier.fillMaxWidth()) + } else { Text( - "view key", - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, + "View-only wallet — no spend key.", + style = MaterialTheme.typography.bodyMedium, + color = OwColors.TextSecondary, ) - Text( - keys.viewKey, - style = MaterialTheme.typography.bodySmall, - fontFamily = FontFamily.Monospace, - ) - Spacer(Modifier.height(8.dp)) - val spend = keys.spendKey - if (spend != null) { - Text( - "spend key", - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - Text( - spend, - style = MaterialTheme.typography.bodySmall, - fontFamily = FontFamily.Monospace, - ) - } else { - Text( - "view-only wallet — no spend key", - style = MaterialTheme.typography.bodyMedium, - ) - } - Spacer(Modifier.height(8.dp)) - Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) { - Button(onClick = onDone) { Text("Done") } - } } + Spacer(Modifier.height(12.dp)) + OwButton( + text = "Done", + variant = OwButtonVariant.Outline, + onClick = onDone, + modifier = Modifier.fillMaxWidth(), + ) } } -/** A display-ready failure line. Never carries a secret; callers pass errors. */ +/** + * A display-ready failure line, as a banner. Never carries a secret; callers + * pass errors. + * + * "No wallet is open" is not a failure — it is a state the app is in, and it + * gets the info banner and its own title. Only a real refusal is red. + */ @Composable private fun ErrorText(text: String) { - Text( - text, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.error, - modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp), + val notOpen = text == WALLET_NOT_OPEN_TEXT + OwAlertBanner( + variant = if (notOpen) OwAlertVariant.Info else OwAlertVariant.Error, + title = if (notOpen) "No wallet open" else "Something went wrong", + description = text, + modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp), ) } diff --git a/android/app/src/test/java/com/siriusdevops/onionwire/ui/ProfileDraftTest.kt b/android/app/src/test/java/com/siriusdevops/onionwire/ui/ProfileDraftTest.kt index f112b91..aa7f9b2 100644 --- a/android/app/src/test/java/com/siriusdevops/onionwire/ui/ProfileDraftTest.kt +++ b/android/app/src/test/java/com/siriusdevops/onionwire/ui/ProfileDraftTest.kt @@ -239,7 +239,9 @@ class ProfileDraftTest { fun an_empty_address_says_nobody_can_pay() { val text = profileAddressNotice("") assertTrue(text.contains("clears the profile address")) - assertTrue(text.contains("wallet child")) + // The consequence, not the process name: the copy no longer says + // "wallet child" anywhere a user can read it. + assertTrue(text.contains("running wallet")) assertTrue(text.contains("nobody can send you an invoice")) } 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..fac959d 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 @@ -117,7 +117,7 @@ class WalletManagerTest { @Test fun a_row_that_is_not_open_says_to_open_it() { val why = walletSecretsBlockedReason(isActive = false, walletReadable = readable) - assertEquals("open this wallet to view its backup", why) + assertEquals("Open this wallet to view its backup.", why) } @Test @@ -212,7 +212,7 @@ class WalletManagerTest { walletPassphraseSubmitEnabled(activeFilename = null, typed = "pw", inFlight = false), ) val why = walletPassphraseBlockedReason(activeFilename = null, typed = "pw") - assertTrue("got '$why'", why != null && why.contains("not pointed at")) + assertTrue("got '$why'", why != null && why.contains("No wallet file is open yet")) // The two reasons are different fixes and must not read alike. assertFalse(why == walletPassphraseBlockedReason(activeFilename = openFile, typed = "")) } @@ -225,7 +225,7 @@ class WalletManagerTest { @Test fun nothing_typed_is_the_other_reason() { val why = walletPassphraseBlockedReason(activeFilename = openFile, typed = "") - assertTrue("got '$why'", why != null && why.contains("type the passphrase")) + assertTrue("got '$why'", why != null && why.contains("Type the passphrase")) } // --- the daemon's own words never reach the screen ----------------------- @@ -348,7 +348,12 @@ class WalletManagerTest { walletOpen = false, needsPassphrase = false, ) - assertTrue("got '$hint'", hint != null && hint.contains("No wallet is open")) + // The §4.1 replacement copy, verbatim: a live wallet with no file open + // is a state, not an error. + assertEquals( + "Select a saved wallet or create a new one to view your balance and transact.", + hint, + ) assertNoRawRpc(hint!!) } @@ -463,7 +468,7 @@ class WalletManagerTest { 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. + // headline on `Balance unavailable`. Reload only when the child has answered. assertFalse(shouldReloadWalletReads(null)) assertFalse(shouldReloadWalletReads("off")) assertFalse(shouldReloadWalletReads("connecting")) From ef149ac496ad1abab6223026dde6cc876e592a94 Mon Sep 17 00:00:00 2001 From: agent Date: Thu, 29 Oct 2026 01:02:59 -0400 Subject: [PATCH 03/10] ui: one door to the saved-wallet catalogue The wallet tab was carrying "Saved wallets" twice: once as a top-bar action (the alpha screen's "Wallets" text link, which I kept when I moved the screen onto OwTopBar) and once in the hero card's header, where the plan puts it. Two controls that do the same thing on one page is how a screen starts to look unfinished. The hero header keeps it; the top bar is a title and nothing else. --- .../siriusdevops/onionwire/ui/WalletScreen.kt | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) 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 448e8bd..cfd0dee 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 @@ -214,19 +214,10 @@ fun WalletScreen( contentWindowInsets = WindowInsets(0, 0, 0, 0), containerColor = OwColors.Canvas, topBar = { - OwTopBar( - title = "Wallet", - // The saved-wallet catalogue is its own screen: this one is the - // open wallet, and switching wallets restarts the wallet - // process, so the picker does not belong in this page's scroll. - actions = { - OwButton( - text = "Saved wallets", - variant = OwButtonVariant.Outline, - onClick = onOpenWallets, - ) - }, - ) + // No actions: the catalogue's entry point is in the hero card's + // header, where the plan puts it. A second "Saved wallets" button + // here would be two doors to one screen on the same page. + OwTopBar(title = "Wallet") }, ) { pad -> Column( From 9b3a0ad177764da4c36fe20a6680fce14f36e6b9 Mon Sep 17 00:00:00 2001 From: agent Date: Thu, 29 Oct 2026 01:03:51 -0400 Subject: [PATCH 04/10] ui: drop two imports the wallet screen no longer uses --- .../src/main/java/com/siriusdevops/onionwire/ui/WalletScreen.kt | 2 -- 1 file changed, 2 deletions(-) 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 cfd0dee..67c2f29 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 @@ -16,7 +16,6 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape @@ -42,7 +41,6 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.testTag import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp From 6216475b13b260c6ee99ca2612e9804047522f10 Mon Sep 17 00:00:00 2001 From: sirius Date: Fri, 30 Oct 2026 23:04:43 -0400 Subject: [PATCH 05/10] docs: point the docs at v0.7.0, and name the Android UI overhaul The README and VERIFY.md pinned downloads to v0.5.0 while v0.6.0 had already shipped, so every documented asset URL was two versions stale. A release tags the default-branch tip, so the fix has to land before the cut, not after. Also one sentence on the Android section: the APK's UI is now a design-token system with a three-tab shell, which android/README.md documents in detail. --- README.md | 20 +++++++++++--------- docs/VERIFY.md | 6 +++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e28c3a2..8061fde 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Lean Tor messenger: one Rust process (ratatui + Noise IK + sqlite + in-process Arti). No hosted server. Identity is an ed25519 public key; the onion is only a locator. -Current tagged release: **v0.5.0**. Linux TUI + Android SDK/APK. Two people add +Current tagged release: **v0.7.0**. Linux TUI + Android SDK/APK. Two people add each other with an `onionwire:v2:…` invite string (`F2` share / `F3` paste; ~1.9 KB because it carries an ML-KEM-768 key). There is no invite QR graphic. Chat is Noise IK over your own v3 onion; when the friend was added from a v2 @@ -61,8 +61,8 @@ resulting hash) next to its `.sha256`. **x86_64:** ```bash -curl -fL -O https://forgejo.siriusdevops.com/sirius/onionwire/releases/download/v0.5.0/onionwire-x86_64-unknown-linux-gnu -curl -fL -O https://forgejo.siriusdevops.com/sirius/onionwire/releases/download/v0.5.0/onionwire-x86_64-unknown-linux-gnu.sha256 +curl -fL -O https://forgejo.siriusdevops.com/sirius/onionwire/releases/download/v0.7.0/onionwire-x86_64-unknown-linux-gnu +curl -fL -O https://forgejo.siriusdevops.com/sirius/onionwire/releases/download/v0.7.0/onionwire-x86_64-unknown-linux-gnu.sha256 sha256sum -c onionwire-x86_64-unknown-linux-gnu.sha256 chmod +x onionwire-x86_64-unknown-linux-gnu ./onionwire-x86_64-unknown-linux-gnu --version @@ -71,8 +71,8 @@ chmod +x onionwire-x86_64-unknown-linux-gnu **aarch64:** ```bash -curl -fL -O https://forgejo.siriusdevops.com/sirius/onionwire/releases/download/v0.5.0/onionwire-aarch64-unknown-linux-gnu -curl -fL -O https://forgejo.siriusdevops.com/sirius/onionwire/releases/download/v0.5.0/onionwire-aarch64-unknown-linux-gnu.sha256 +curl -fL -O https://forgejo.siriusdevops.com/sirius/onionwire/releases/download/v0.7.0/onionwire-aarch64-unknown-linux-gnu +curl -fL -O https://forgejo.siriusdevops.com/sirius/onionwire/releases/download/v0.7.0/onionwire-aarch64-unknown-linux-gnu.sha256 sha256sum -c onionwire-aarch64-unknown-linux-gnu.sha256 chmod +x onionwire-aarch64-unknown-linux-gnu ./onionwire-aarch64-unknown-linux-gnu --version @@ -134,7 +134,7 @@ system OpenSSL headers or `pkg-config` are required — Arti's TLS backend is `rustls`. The crate version in `Cargo.toml` is **not** bumped by the release workflow. The -tag (`v0.5.0`) is the version users download; `onionwire --version` prints +tag (`v0.7.0`) is the version users download; `onionwire --version` prints `CARGO_PKG_VERSION` from the tree that was built. ### Two instances on one machine @@ -433,7 +433,9 @@ invites interoperate. - **SDK** — `onionwire-sdk-.aar`. UniFFI Kotlin over the same Rust crate the TUI runs. See [crates/onionwire-sdk/README.md](crates/onionwire-sdk/README.md). - **APK** — `onionwire--android-arm64-v8a.apk`. Kotlin + Jetpack Compose. - Build notes: [android/README.md](android/README.md). + Build notes: [android/README.md](android/README.md). The UI is a design-token + system (one accent, 16px cards, three-tab shell: Chats / Wallet / Node & + Settings) rather than per-screen styling; see *App shell* in that README. The APK build is amd64-only. After the Linux `release` workflow finishes, dispatch `android-release` with that tag so the APK/AAR attach to the same @@ -441,7 +443,7 @@ Forgejo release. ```bash scripts/build-android-local.sh # -> dist/, with .sha256 -PUBLISH_TAG=v0.5.0 scripts/build-android-local.sh # + upload to that release +PUBLISH_TAG=v0.7.0 scripts/build-android-local.sh # + upload to that release ``` ## Releases (maintainers) @@ -461,7 +463,7 @@ Actions → **release** → Run workflow: Then dispatch **android-release** with `tag=` to attach the APK + AAR. ```bash -FORGEJO_TOKEN= scripts/build-release-local.sh v0.5.0 +FORGEJO_TOKEN= scripts/build-release-local.sh v0.7.0 ``` Do not run `cargo publish`; `publish = false`. diff --git a/docs/VERIFY.md b/docs/VERIFY.md index ea1e57e..d2f2c4e 100644 --- a/docs/VERIFY.md +++ b/docs/VERIFY.md @@ -67,7 +67,7 @@ missing: - **`/releases/latest/download/…` is not served by this Forgejo — it is a 404.** The GitHub habit fails here. Always pin the tag: - `…/releases/download/v0.5.0/onionwire-x86_64-unknown-linux-gnu`. + `…/releases/download/v0.7.0/onionwire-x86_64-unknown-linux-gnu`. - **Cloudflare in front of the Forgejo rejects non-browser User-Agents.** A script that sends a default library UA gets `HTTP 403` with the body `error code: 1010` — even with a correct tag and URL. Measured against a real @@ -157,10 +157,10 @@ is public": *the binary I downloaded might not be that source.* git clone https://forgejo.siriusdevops.com/sirius/onionwire cd onionwire git fetch --tags -scripts/verify-reproducible.sh v0.5.0 +scripts/verify-reproducible.sh v0.7.0 ``` -Replace `v0.5.0` with the tag you are checking. You need docker; you do not +Replace `v0.7.0` with the tag you are checking. You need docker; you do not need Rust, or the right glibc, or the right distro. The rebuild happens inside the same builder image, pinned **by digest**, that CI uses, with the source paths, the target path, and `SOURCE_DATE_EPOCH` all fixed by From 9d93fb5cfa9b863319569e5f1a005ad3c120184b Mon Sep 17 00:00:00 2001 From: agent Date: Fri, 30 Oct 2026 23:24:58 -0400 Subject: [PATCH 06/10] fuzz: pass the 4th bootstrap arg (hybrid ML-KEM peer key) RatchetState::bootstrap gained remote_kem_pub in b22abd7 (PR #185), so the fuzz target has not compiled since 2026-10-20 and the nightly fuzz job has been red for ten days. Pass None for the classical shape and a real ML-KEM-768 encapsulation key (crate::kem::PK_LEN bytes, built once from a fixed 64-byte seed) for the hybrid shape, so both bootstrap paths are fuzzed. The invariants are unchanged: arbitrary bytes never panic, a parsed state re-serializes, and a rejected frame rolls back to the exact pre-decrypt state. --- fuzz/fuzz_targets/ratchet_frame.rs | 54 ++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/fuzz/fuzz_targets/ratchet_frame.rs b/fuzz/fuzz_targets/ratchet_frame.rs index 9361768..9d7f50f 100644 --- a/fuzz/fuzz_targets/ratchet_frame.rs +++ b/fuzz/fuzz_targets/ratchet_frame.rs @@ -10,26 +10,45 @@ //! Neither call may panic, and neither may leave the state mutated on a frame //! it rejects (asserted in `tests/ratchet.rs`, re-checked cheaply here by //! re-serializing after every decrypt). +//! +//! Both bootstrap shapes are exercised: a classical friend (`remote_kem_pub = +//! None`) and a hybrid friend, whose peer ML-KEM ratchet key is a real +//! encapsulation key of `kem::PK_LEN` bytes derived from a fixed seed. A +//! garbage key would only ever hit the "invalid encapsulation key" error path. #![no_main] use libfuzzer_sys::fuzz_target; +use onionwire::kem::{self, PK_LEN, SEED_LEN}; use onionwire::ratchet::{RatchetKeyPair, RatchetState}; +use std::sync::OnceLock; -fuzz_target!(|data: &[u8]| { - // Restore path: arbitrary bytes as a persisted ratchet state. - if let Ok(state) = RatchetState::from_bytes(data) { - // A state that parsed must re-serialize without panicking. - let _ = state.to_bytes(); - } +/// A canonical ML-KEM-768 encapsulation key, built once: key generation is +/// deterministic for a fixed seed, so this only pays for itself on iteration 1. +fn peer_kem_pub() -> &'static [u8] { + static PK: OnceLock> = OnceLock::new(); + PK.get_or_init(|| { + let pk = kem::pk_from_seed(&[0x44u8; SEED_LEN]).expect("64 bytes is a valid ML-KEM seed"); + assert_eq!(pk.len(), PK_LEN, "crate ML-KEM public key length changed"); + pk + }) +} - // Wire path: a fresh bootstrap epoch for every input, so one iteration can - // never influence the next. The keys are fixed (not fuzzed) on purpose: - // the interesting surface is `data` as the frame. - let mut state = RatchetState::bootstrap( +fn bootstrap(remote_kem_pub: Option<&[u8]>) -> RatchetState { + // The keys are fixed (not fuzzed) on purpose: the interesting surface is + // `data` as the frame. + RatchetState::bootstrap( [0x42u8; 32], RatchetKeyPair::from_secret([0x11u8; 32]), [0x33u8; 32], - ); + remote_kem_pub, + ) +} + +/// Feed `data` to a fresh state and hold the existing invariants: a reject must +/// roll back, an accept must have advanced the receiving chain, and re-sending +/// from the resulting state must not panic. +fn exercise(remote_kem_pub: Option<&[u8]>, data: &[u8]) { + let mut state = bootstrap(remote_kem_pub); let before = state.to_bytes(); match state.decrypt(data) { @@ -45,4 +64,17 @@ fuzz_target!(|data: &[u8]| { // Re-encrypting a byte-identical state must stay a pure function. let _ = state.encrypt(b"fuzz"); +} + +fuzz_target!(|data: &[u8]| { + // Restore path: arbitrary bytes as a persisted ratchet state. + if let Ok(state) = RatchetState::from_bytes(data) { + // A state that parsed must re-serialize without panicking. + let _ = state.to_bytes(); + } + + // Wire path: a fresh bootstrap epoch for every input, so one iteration can + // never influence the next. Classical and hybrid, both. + exercise(None, data); + exercise(Some(peer_kem_pub()), data); }); From 3cd70ca9b58049ed578df7ee770198ba6fd34a68 Mon Sep 17 00:00:00 2001 From: agent Date: Sat, 31 Oct 2026 01:10:34 -0400 Subject: [PATCH 07/10] android wallet: self-heal the stored wallet_rpc_bin, gate Start/Create, one info banner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Device report (v0.7.0): Start died with `spawn monero-wallet-rpc: No such file or directory`, and Create answered with the desktop TUI's `wallet not configured — open F7 …`. Both were reachable states on the phone, so the screen offered two dead ends. - WireViewModel: `healStoredWalletBin()` re-points a stored wallet_rpc_bin that this device cannot execute at the resolved nativeLibraryDir path, preserving kind/mode/host/port/datadir/filename, skipping receive-only, and never overwriting a stored path that is a real executable file. It runs on wallet-screen open and again at the top of `startWalletChild()`, which then re-reads the stored record and refuses to spawn when the path still cannot run — writing the named path instead of ENOENT. - Gate: `startGateReason()` = existing `startBlockedReason()` plus `storedWalletBinBlockedReason()`, which names the stored path, the resolved path, or the absent-binary message (unchanged strings). `shouldStartAfterSelectingChain()` now takes that reason, so a mode tap stores the source but cannot launch what Start would refuse. - Create/Import: `walletSetupBlockedReason()` disables both controls with a sentence until the child answers; the TUI's unconfigured copy is mapped by `walletFailureText` to a phone sentence, so `open F7` and ONIONWIRE_WALLET_RPC never render. - Banner: `walletFailureBanner()` paints `WALLET_NOT_OPEN_TEXT` as one info banner (or nothing when the No-wallet-open hint is already up), never as the red `Wallet error`; the sticky error is cleared when a wallet opens. Real failures (connect refusals, exited) still paint red. Tests: 241/241 `:app:testDebugUnitTest`, including the four required cases. Not verified on a device — no adb/device on this host. --- .../siriusdevops/onionwire/WireViewModel.kt | 79 ++++++++ .../onionwire/ui/WalletChildStatusText.kt | 183 +++++++++++++++++- .../onionwire/ui/WalletManagerScreen.kt | 28 +++ .../siriusdevops/onionwire/ui/WalletScreen.kt | 96 +++++++-- .../onionwire/ui/WalletChildStatusTextTest.kt | 136 +++++++++++++ .../onionwire/ui/WalletManagerTest.kt | 23 +++ 6 files changed, 528 insertions(+), 17 deletions(-) diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/WireViewModel.kt b/android/app/src/main/java/com/siriusdevops/onionwire/WireViewModel.kt index cc16ef2..5da0390 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/WireViewModel.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/WireViewModel.kt @@ -15,6 +15,9 @@ import com.siriusdevops.onionwire.keepalive.KeepAliveStatus import com.siriusdevops.onionwire.keepalive.NodeHost import com.siriusdevops.onionwire.ui.SeedBackupGate import com.siriusdevops.onionwire.ui.WalletKeyOrigin +import com.siriusdevops.onionwire.ui.NO_CHAIN_SOURCE_NOTICE +import com.siriusdevops.onionwire.ui.storedWalletBinBlockedReason +import com.siriusdevops.onionwire.ui.walletBinHealPath import com.siriusdevops.onionwire.ui.walletFailureText import com.siriusdevops.onionwire.wallet.ChainStorage import com.siriusdevops.onionwire.wallet.NO_WALLET_RPC_MESSAGE @@ -1015,10 +1018,72 @@ class WireViewModel(app: Application) : AndroidViewModel(app) { */ fun chainFreeBytes(): Long? = ChainStorage.freeBytes(home) + /** + * Repairs a stored `walletRpcBin` this device cannot execute, and reports + * whether it wrote anything back. + * + * A wallet-child record written by an older install can carry the bare name + * `monero-wallet-rpc` (or an empty string). Nothing in an APK sandbox + * resolves a bare name on `PATH`, so `start_wallet_child` spawns it and dies + * with `No such file or directory` — while the Start gate, which only ever + * looked at the *resolved* bundle, stayed green. This re-points the stored + * record at the absolute `nativeLibraryDir` path this install actually + * carries, before anything is spawned. + * + * What it deliberately does not do: + * - it never changes `kind`, host, port, mode, datadir or wallet filename — + * a repair of the binary is not a change of chain source; + * - it does nothing for receive-only (`ChainChoice.NONE`), which stores a + * bin it never spawns; + * - it never overwrites a stored path that exists and is executable, even + * when that path is not the bundled binary — a user who pointed at a real + * file keeps it; + * - it never fails loudly: a repair that cannot be made leaves the stored + * record alone, and the gate then names the path it will try to spawn. + */ + suspend fun healStoredWalletBin(bins: WalletChildBinaryPaths): Result = + withContext(Dispatchers.IO) { + runCatching { + val wire = requireWire() + val stored = runCatching { wire.chainSource() }.getOrNull() + ?: return@runCatching false + if (stored.kind == ChainChoice.NONE) return@runCatching false + val healed = walletBinHealPath(stored.walletRpcBin, bins.walletRpc) + ?: return@runCatching false + wire.setChainSource( + ChainConfig( + kind = stored.kind, + monerodBin = stored.monerodBin, + monerodDatadir = stored.monerodDatadir, + host = stored.host, + port = stored.port, + walletRpcBin = healed, + artiBin = stored.artiBin, + walletFilename = stored.walletFilename, + mainnet = stored.mainnet, + prune = stored.prune, + ), + ) + true + } + }.onSuccess { healed -> + if (healed) { + refreshChainSource() + refreshWalletChild() + } + } + /** * Kick off start on [viewModelScope] so leaving the composition does not * cancel Cuprate launch. Returns immediately; watch [walletChildStarting] * and [walletChildError]. Core status stays `off` until the node answers. + * + * Self-heals the stored binary first, then re-reads that stored record and + * refuses to spawn when it still names a path this device cannot run. The + * screen's gate is the primary door, but an auto-start from a mode tap is + * not the only caller: this is the last place that can stop a doomed spawn, + * and the reason it writes is the named path rather than the core's opaque + * `spawn monero-wallet-rpc: …`. */ fun startWalletChild() { if (!startInFlight.compareAndSet(false, true)) return @@ -1026,6 +1091,20 @@ class WireViewModel(app: Application) : AndroidViewModel(app) { _walletChildError.value = null viewModelScope.launch { try { + val bins = bundledBinaries() + healStoredWalletBin(bins) + val stored = withContext(Dispatchers.IO) { + runCatching { requireWire().chainSource() }.getOrNull() + } + if (stored == null || stored.kind == ChainChoice.NONE) { + _walletChildError.value = NO_CHAIN_SOURCE_NOTICE + return@launch + } + val blocked = storedWalletBinBlockedReason(stored.walletRpcBin, bins.walletRpc) + if (blocked != null) { + _walletChildError.value = blocked + return@launch + } val started = withContext(Dispatchers.IO) { runCatching { requireWire().startWalletChild() } } diff --git a/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletChildStatusText.kt b/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletChildStatusText.kt index 5bae4d1..2f15281 100644 --- a/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletChildStatusText.kt +++ b/android/app/src/main/java/com/siriusdevops/onionwire/ui/WalletChildStatusText.kt @@ -2,6 +2,7 @@ package com.siriusdevops.onionwire.ui import com.siriusdevops.onionwire.wallet.NO_WALLET_RPC_MESSAGE import com.siriusdevops.onionwire.wallet.WalletChildBinaryPaths +import java.io.File import java.util.Locale /** @@ -446,13 +447,21 @@ fun selectedCuprateMode(inProcess: Boolean, mainnet: Boolean, prune: Boolean): C /** * Tapping a mode used to only persist `ChainConfig`, which looked like a no-op - * besides the storage line. Start when the storage floor would allow Start and - * a launch is not already in flight. + * besides the storage line. Start when the storage floor would allow Start, + * **the Start gate itself would allow it**, and a launch is not already in + * flight. + * + * [startBlocked] is the same reason the Start button is disabled by + * (`startGateReason`). A mode tap stores the source either way, but persisting + * a choice must never launch a child the gate would refuse — the old + * storage-only predicate is exactly how an auto-start slipped past a stored + * binary that could not run. */ fun shouldStartAfterSelectingChain( storageBlocked: String?, starting: Boolean, -): Boolean = storageBlocked == null && !starting + startBlocked: String? = null, +): Boolean = storageBlocked == null && startBlocked == null && !starting /** * Bytes as a screen-sized string. Binary units (a "GB" that is really a GiB is how @@ -609,7 +618,7 @@ fun startBlockedReason( // control *is* Stop, so Start is never offered. Kept as a pure predicate so // a stale status read cannot turn the one control into a no-op tap. input.running -> "The wallet is already running." - !input.configured -> "No chain source yet: the wallet needs a daemon to dial." + !input.configured -> NO_CHAIN_SOURCE_NOTICE // The stored source is the app's own node but this build has no daemon: the // option is readable and unstoppable, so say it before the user presses Start. input.chainInProcess && !input.nodeAvailable -> CUPRATE_NOT_IN_BUILD_NOTICE @@ -617,6 +626,172 @@ fun startBlockedReason( else -> null } +/** The stored config names no chain source, so there is no daemon to dial. */ +const val NO_CHAIN_SOURCE_NOTICE: String = + "No chain source yet: the wallet needs a daemon to dial." + +/** + * Whether [path] is a file this process may `exec`, measured the way the kernel + * will measure it at spawn time. A missing file and an existing file without + * the execute bit are both "cannot run here" — they differ only in errno. + * + * Never throws: a path the filesystem refuses to answer for is not executable. + */ +fun isExecutableWalletBin(path: String): Boolean = + runCatching { File(path).let { it.isFile && it.canExecute() } }.getOrDefault(false) + +/** + * The absolute path the stored config should keep instead of [storedBin], or + * `null` when the stored path is already runnable here (or there is nothing + * better to offer). + * + * This is the repair rule behind the self-heal. A record written by an older + * install can carry the bare name `monero-wallet-rpc` (or nothing at all), + * which nothing in an APK sandbox resolves on `PATH`; the spawn then dies with + * `ENOENT` and the screen had no way to say why. When this build *does* carry + * the binary at a resolved absolute path, that path replaces the unusable one. + * + * It never overwrites a path the user pointed at that actually runs: an + * existing, executable file is left alone even when it is not the bundled one. + */ +fun walletBinHealPath( + storedBin: String?, + resolvedBin: String?, + executable: (String) -> Boolean = ::isExecutableWalletBin, +): String? { + val resolved = resolvedBin?.takeIf { it.isNotBlank() } ?: return null + val stored = storedBin?.trim().orEmpty() + if (stored.isNotEmpty() && executable(stored)) return null + return resolved +} + +/** + * Why the **stored** `ChainConfig.walletRpcBin` will not produce a child, or + * `null` when it will. [startBlockedReason] only ever sees the *resolved* + * binaries, so a stale path saved by an older install passed that gate and + * then failed inside `spawn`. + * + * The reason always names the path it is about, so the next failure report + * carries its own cause instead of the opaque `spawn monero-wallet-rpc: No such + * file or directory`. A store that holds no path at all is named as such — + * "stored bin missing" is a distinct condition from "this build ships none". + */ +fun storedWalletBinBlockedReason( + storedBin: String?, + resolvedBin: String?, + executable: (String) -> Boolean = ::isExecutableWalletBin, +): String? { + if (resolvedBin.isNullOrBlank()) return NO_WALLET_RPC_MESSAGE + val stored = storedBin?.trim().orEmpty() + if (stored.isEmpty()) { + return "No wallet binary path is stored for this chain source, so there is nothing to " + + "spawn. This build ships $resolvedBin — pick a chain source to store it." + } + if (executable(stored)) return null + return "The stored wallet binary cannot be run on this device: $stored. " + + "This build ships $resolvedBin." +} + +/** + * The full **Start** gate: the eligibility rules above plus the stored binary. + * + * [startBlockedReason] runs first so its established copy and ordering (no + * binary in this build, start in flight, no chain source) is unchanged; the + * stored-path check is the new second half. Together they make a populated + * `bins` insufficient on its own — which was the hole that let a bare stored + * name through. + */ +fun startGateReason( + bins: WalletChildBinaryPaths, + input: WalletChildInput?, + storedWalletBin: String?, + onionDaemon: Boolean = false, + starting: Boolean = false, + executable: (String) -> Boolean = ::isExecutableWalletBin, +): String? = + startBlockedReason(bins, input, onionDaemon, starting) + ?: storedWalletBinBlockedReason(storedWalletBin, bins.walletRpc, executable) + +/** + * Why **Create wallet** / **Import wallet** cannot be offered yet, or `null` + * when they can. + * + * Both are RPC calls (`create_wallet` / `restore_deterministic_wallet`) against + * the running child. With no child the call cannot succeed, and the core's + * refusal is the desktop TUI's `wallet not configured — open F7 …` — a key that + * does not exist on a phone. Collecting a passphrase only to print that is the + * second dead end this screen must not offer. + */ +fun walletSetupBlockedReason(input: WalletChildInput?): String? = + when (walletChildPhase(input)) { + WalletChildPhase.Unread -> READING_CHILD_NOTICE + WalletChildPhase.Off -> WALLET_SETUP_NEEDS_CHILD + WalletChildPhase.Connecting -> WALLET_SETUP_STARTING + is WalletChildPhase.Exited, is WalletChildPhase.Unrecognised -> WALLET_SETUP_NEEDS_CHILD + WalletChildPhase.Syncing, WalletChildPhase.Ready -> null + } + +/** Shown on the disabled Create / Import controls when no wallet process is up. */ +const val WALLET_SETUP_NEEDS_CHILD: String = + "Create and Import need the wallet process running. Start it on the node card first." + +/** Shown while the child is up but its RPC has not answered yet. */ +const val WALLET_SETUP_STARTING: String = + "The wallet is still starting. Wait until it answers, then create or import." + +/** Tone of the one failure banner a card may paint. */ +enum class WalletFailureTone { + /** Information about a state the app is in, not a failed call. */ + Info, + + /** A call actually failed. */ + Error, +} + +/** + * The banner a card should paint for a display-ready failure string, or `null` + * when it should paint none. + * + * [WALLET_NOT_OPEN_TEXT] is documented as a *state*, not a failure — a running + * child with no wallet file open answers every read with the daemon's `-13`, + * and that is exactly what first-run looks like. It nevertheless reached the + * node card's red `Wallet error` banner, duplicating the `No wallet open` info + * banner directly above it. This decision is keyed on the *mapped* text only: + * the mapping in [walletFailureText] is untouched, so nothing raw becomes + * visible, and only the paint changes. + * + * - [walletOpen] true: the state has ended, so a stale no-wallet sentence is + * dropped entirely. + * - [openHintVisible] true: the info banner above already says it — one + * sentence, once. + * - otherwise the sentence is still information, so it is painted as + * [WalletFailureTone.Info] rather than red. + */ +fun walletFailureBanner( + text: String?, + openHintVisible: Boolean, + walletOpen: Boolean, +): WalletFailureBanner? { + val shown = text?.takeIf { it.isNotBlank() } ?: return null + return if (shown == WALLET_NOT_OPEN_TEXT) { + when { + walletOpen -> null + openHintVisible -> null + else -> WalletFailureBanner(shown, WalletFailureTone.Info, "No wallet open") + } + } else { + WalletFailureBanner(shown, WalletFailureTone.Error, "Wallet error") + } +} + +/** One banner: its sentence, its tone, and its title. */ +data class WalletFailureBanner( + val text: String, + val tone: WalletFailureTone, + val title: String, +) + + /** * Why **Stop** is not actionable, or `null` when it is. `stop_wallet_child` is * idempotent in the core, so this is only about not offering a no-op button. 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 68884be..214394d 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 @@ -176,6 +176,31 @@ const val WALLET_DAEMON_REFUSED_TEXT: String = "The wallet daemon refused that request and gave no readable reason. Check the wallet " + "on the wallet screen, then try again." +/** + * The desktop TUI's refusal, in the phone's words. + * + * `src/wallet.rs::NOT_CONFIGURED_MSG` is written for the Linux TUI: "wallet not + * configured — open F7 to set it up, or set ONIONWIRE_WALLET_RPC". Neither `F7` + * nor an environment variable exists on the phone, and the actual condition is + * simply that no wallet child is running. Printing that string was the second + * dead end on the device: a user who typed a passphrase into Create got told to + * press a key that is not on the device. + */ +const val WALLET_RPC_NOT_RUNNING_TEXT: String = + "The wallet process is not running, so there is nothing to open a wallet on. " + + "Start it on the node card, then create or import." + +/** + * The TUI's unconfigured copy, and nothing else: the F7 hint, the phrase + * "wallet not configured", or an instruction to set `ONIONWIRE_WALLET_RPC`. + * All three describe the same fact — no wallet RPC to dial — and none of them + * is actionable on a phone. + */ +private val TUI_WALLET_NOT_CONFIGURED = Regex( + """open\s*f7|wallet not configured|ONIONWIRE_WALLET_RPC""", + RegexOption.IGNORE_CASE, +) + /** * A failure string safe to put on screen, or `null` when there is nothing to * show. @@ -201,6 +226,9 @@ internal fun walletFailureText(raw: String?): String? { val text = raw?.trim().orEmpty() return when { text.isEmpty() -> null + // Before the JSON / -13 filters: the TUI's refusal is a plain sentence + // the raw pass-through would otherwise let reach the phone verbatim. + TUI_WALLET_NOT_CONFIGURED.containsMatchIn(text) -> WALLET_RPC_NOT_RUNNING_TEXT NO_WALLET_FILE.containsMatchIn(text) || RAW_RPC_CODE.containsMatchIn(text) -> WALLET_NOT_OPEN_TEXT RAW_JSON.containsMatchIn(text) -> WALLET_DAEMON_REFUSED_TEXT 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 67c2f29..4299cc2 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 @@ -169,6 +169,11 @@ fun WalletScreen( LaunchedEffect(Unit) { reload() vm.refreshChainSource() + // Self-heal before the gate is asked: a stored `wallet_rpc_bin` left by + // an older install can point at a path this device cannot execute, and + // the bundled binary is the right answer for it. The gate below then + // names the path only when no repair was possible. + vm.healStoredWalletBin(bins) } // The same reads again, once the wallet has actually answered. They are @@ -262,22 +267,33 @@ fun WalletScreen( // about a seed they do not have. val walletReadable = balance != null && balance != "off" && balance != "err" val walletOpen = child?.walletOpen == true + // A sticky failure captured while no wallet was open is not a + // failure once one is: drop it, so the red line does not outlive + // the state that produced it. + LaunchedEffect(walletOpen) { + if (walletOpen) vm.clearWalletChildError() + } val unbacked = SeedBackupGate.warningVisible(seedConfirmed, walletReadable) if (unbacked) { UnbackedSeedCard(error = error, onBackUpSeed = { openSeedBackup() }) } val phase = walletChildPhase(childInput) + // Create and Import are RPC calls against the running child. With no + // child up they can only fail, and the failure is the TUI's `open F7` + // copy — so the controls stay dead and say why instead. + val setupBlocked = walletSetupBlockedReason(childInput) WalletHeroCard( balance = balance, address = address, walletOpen = walletOpen, phase = phase, showQr = showQr, + setupBlocked = setupBlocked, onToggleQr = { showQr = !showQr }, onOpenWallets = onOpenWallets, - onCreate = { setup = SetupKind.Create }, - onImport = { setup = SetupKind.Import }, + onCreate = { if (setupBlocked == null) setup = SetupKind.Create }, + onImport = { if (setupBlocked == null) setup = SetupKind.Import }, onInvoice = { composer = PayKind.Invoice }, onTip = { composer = PayKind.Tip }, onBackUpSeed = if ( @@ -336,9 +352,12 @@ fun WalletScreen( .onFailure { daemonError = walletFailureText(it.message ?: it.toString()) } .onSuccess { // Selecting a mode stores it and, when the - // storage floor would allow Start, starts the - // node: a mode button that only rewrites a - // storage line reads as a no-op. + // storage floor *and* the Start gate would allow + // a launch, starts the node. The stored binary is + // what the just-saved config holds; the gate + // asks it the same question Start does, so a + // mode tap can never launch a child Start would + // have refused. if (shouldStartAfterSelectingChain( chainStorageBlockedReason( vm.chainFreeBytes(), @@ -346,6 +365,10 @@ fun WalletScreen( prune = prune, ), starting = starting, + startBlocked = storedWalletBinBlockedReason( + bins.walletRpc, + bins.walletRpc, + ), ) ) { vm.startWalletChild() @@ -442,6 +465,12 @@ private fun WalletHeroCard( walletOpen: Boolean, phase: WalletChildPhase, showQr: Boolean, + /** + * Why Create / Import cannot be offered yet, or `null` when they can. From + * [walletSetupBlockedReason]: both flows are RPC calls against a running + * wallet child, so a stopped child is a dead end the screen may not offer. + */ + setupBlocked: String?, onToggleQr: () -> Unit, onOpenWallets: () -> Unit, onCreate: () -> Unit, @@ -502,16 +531,30 @@ private fun WalletHeroCard( OwButton( text = "Create Wallet", variant = OwButtonVariant.Primary, + enabled = setupBlocked == null, onClick = onCreate, modifier = Modifier.weight(1f).testTag("wallet-create"), ) OwButton( text = "Import Wallet", variant = OwButtonVariant.Secondary, + enabled = setupBlocked == null, onClick = onImport, modifier = Modifier.weight(1f).testTag("wallet-import"), ) } + // Why the two flows are dead, in a sentence rather than a grey pair + // of buttons. The only fix is on the node card below, so the copy + // points there. + setupBlocked?.let { + Spacer(Modifier.height(8.dp)) + OwAlertBanner( + variant = OwAlertVariant.Info, + title = "Wallet not running", + description = it, + modifier = Modifier.testTag("wallet-setup-blocked"), + ) + } // Invoicing does not need a wallet file: the core resolves the payee // address from the profile (`no receive address — set profile xmr or // ONIONWIRE_WALLET_RPC` is the both-missing case). Hiding the action @@ -614,16 +657,27 @@ private fun WalletHeroCard( OwButton( text = "New wallet", variant = OwButtonVariant.Outline, + enabled = setupBlocked == null, onClick = onCreate, modifier = Modifier.weight(1f).testTag("wallet-create"), ) OwButton( text = "Import wallet", variant = OwButtonVariant.Outline, + enabled = setupBlocked == null, onClick = onImport, modifier = Modifier.weight(1f).testTag("wallet-import"), ) } + setupBlocked?.let { + Spacer(Modifier.height(8.dp)) + OwAlertBanner( + variant = OwAlertVariant.Info, + title = "Wallet not running", + description = it, + modifier = Modifier.testTag("wallet-setup-blocked"), + ) + } // The recovery path for a wallet whose seed was missed: a quiet action, // because a healthy wallet needs it rarely and a seed is a spend key. // While the seed is unconfirmed the strip above carries the button @@ -690,7 +744,10 @@ private fun NodeCard( val progress = syncProgress(input?.height ?: 0uL, input?.targetHeight ?: 0uL) val node = nodePhase(input) val onionDaemon = chain?.kind == ChainChoice.REMOTE && isOnionHost(chain.host) - val startWhy = startBlockedReason(bins, input, onionDaemon, starting) + // The full gate: eligibility *and* the stored binary this build will + // actually spawn. A populated `bins` alone used to pass, which is how a + // stored bare name got as far as `spawn` and failed with ENOENT. + val startWhy = startGateReason(bins, input, chain?.walletRpcBin, onionDaemon, starting) ?: if (inProcess) { chainStorageBlockedReason( nodeFreeBytes, @@ -976,15 +1033,28 @@ private fun NodeCard( // acts, like the chat screen's load error. Filtered through // `walletFailureText`: the daemon's own `-13 No wallet file` / JSON // answer is not a sentence about this app and never reaches the screen. + // + // "No wallet open" is a state, not a failure: the info banner above + // already owns it, so it is not painted red and not printed twice. val failure = walletFailureText(input?.lastError) ?: actionError ?: daemonError failure?.let { - Spacer(Modifier.height(8.dp)) - OwAlertBanner( - variant = OwAlertVariant.Error, - title = "Wallet error", - description = it, - modifier = Modifier.testTag("wallet-child-error"), - ) + walletFailureBanner( + text = it, + openHintVisible = openHint != null, + walletOpen = walletOpen, + )?.let { banner -> + Spacer(Modifier.height(8.dp)) + OwAlertBanner( + variant = if (banner.tone == WalletFailureTone.Info) { + OwAlertVariant.Info + } else { + OwAlertVariant.Error + }, + title = banner.title, + description = banner.text, + modifier = Modifier.testTag("wallet-child-error"), + ) + } } } } diff --git a/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletChildStatusTextTest.kt b/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletChildStatusTextTest.kt index def027a..255c217 100644 --- a/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletChildStatusTextTest.kt +++ b/android/app/src/test/java/com/siriusdevops/onionwire/ui/WalletChildStatusTextTest.kt @@ -621,4 +621,140 @@ class WalletChildStatusTextTest { nodeStatusHead(input("syncing", running = true, chainSource = "remote daemon")).title, ) } + + // --- the stored wallet binary: heal before spawn, then gate on it ------- + + private val hostsBundled = "/data/app/~~abc/onionwire-1/lib/arm64/libmonerowalletrpc.so" + + @Test + fun a_stored_bare_name_is_repaired_to_the_bundled_absolute_path() { + // A record written by an older install: a bare name nothing in an APK + // sandbox resolves on PATH. The repair is the absolute path this + // install actually carries. + assertEquals(hostsBundled, walletBinHealPath("monero-wallet-rpc", hostsBundled) { false }) + assertEquals("an empty stored bin is healed too", hostsBundled, walletBinHealPath("", hostsBundled) { false }) + assertEquals("and a missing field", hostsBundled, walletBinHealPath(null, hostsBundled) { false }) + } + + @Test + fun a_stored_path_that_actually_runs_is_never_overwritten() { + val userBin = "/data/user/0/com.siriusdevops.onionwire/files/monero-wallet-rpc" + assertNull( + "a real executable file the user pointed at is left alone", + walletBinHealPath(userBin, hostsBundled) { it == userBin }, + ) + assertNull( + "a bundled path already stored needs no write", + walletBinHealPath(hostsBundled, hostsBundled) { it == hostsBundled }, + ) + } + + @Test + fun no_bundled_binary_means_there_is_nothing_to_repair_with() { + assertNull(walletBinHealPath("monero-wallet-rpc", null) { false }) + assertNull(walletBinHealPath("monero-wallet-rpc", " ") { false }) + } + + @Test + fun a_stored_bin_missing_on_the_device_blocks_start_and_names_the_path() { + val why = startGateReason(bundled, input("off"), "monero-wallet-rpc") { false } + assertNotNull("a stored path that cannot run must block Start", why) + assertTrue("the reason names the stored path it is about", why!!.contains("monero-wallet-rpc")) + assertTrue("and the path this build does carry", why.contains(bundled.walletRpc!!)) + assertTrue("and says it cannot run", why.contains("cannot be run")) + assertFalse( + "a gate that refuses never lets a mode tap auto-start", + shouldStartAfterSelectingChain(storageBlocked = null, starting = false, startBlocked = why), + ) + } + + @Test + fun an_absent_resolved_bin_blocks_with_the_resolved_absence_message() { + // Nothing in this build to spawn: the established string, unchanged. + val why = startGateReason(noBinary, input("off"), "/stale/libmonerowalletrpc.so") { false } + assertEquals(NO_WALLET_RPC_MESSAGE, why) + assertFalse(shouldStartAfterSelectingChain(null, false, why)) + } + + @Test + fun a_runnable_stored_bin_passes_the_gate() { + assertNull(startGateReason(bundled, input("off"), bundled.walletRpc) { it == bundled.walletRpc }) + assertNull(storedWalletBinBlockedReason(bundled.walletRpc, bundled.walletRpc) { true }) + } + + @Test + fun the_gate_keeps_the_established_start_ordering() { + // Reading the status still wins over a stored-path complaint: the + // existing copy and its order were not rewritten to make room. + assertEquals(READING_CHILD_NOTICE, startGateReason(bundled, null, null) { false }) + assertEquals( + NO_CHAIN_SOURCE_NOTICE, + startGateReason(bundled, input("off", configured = false, chainSource = "receive-only"), null) { false }, + ) + } + + @Test + fun a_mode_tap_stores_the_source_but_cannot_auto_start_what_the_gate_refuses() { + assertTrue(shouldStartAfterSelectingChain(storageBlocked = null, starting = false)) + assertTrue( + shouldStartAfterSelectingChain(storageBlocked = null, starting = false, startBlocked = null), + ) + assertFalse( + shouldStartAfterSelectingChain( + storageBlocked = null, + starting = false, + startBlocked = "The stored wallet binary cannot be run on this device: …", + ), + ) + } + + @Test + fun create_and_import_are_blocked_without_a_running_child() { + assertEquals(WALLET_SETUP_NEEDS_CHILD, walletSetupBlockedReason(input("off"))) + assertEquals(WALLET_SETUP_NEEDS_CHILD, walletSetupBlockedReason(input("exited", lastError = "spawn …"))) + assertEquals(WALLET_SETUP_NEEDS_CHILD, walletSetupBlockedReason(input("mining"))) + assertEquals(WALLET_SETUP_STARTING, walletSetupBlockedReason(input("connecting", running = true))) + assertEquals(READING_CHILD_NOTICE, walletSetupBlockedReason(null)) + assertNull( + "a syncing wallet answers RPC, so a create is fine", + walletSetupBlockedReason(input("syncing", running = true)), + ) + assertNull(walletSetupBlockedReason(input("ready", running = true))) + } + + // --- the no-wallet-open state is information, not a failure ------------ + + @Test + fun the_no_wallet_open_state_is_information_never_the_red_failure() { + // The `No wallet open` info banner owns this sentence; printing it a + // second time in red is the duplicate the device report caught. + assertNull( + "already said once by the info banner above", + walletFailureBanner(WALLET_NOT_OPEN_TEXT, openHintVisible = true, walletOpen = false), + ) + val alone = walletFailureBanner(WALLET_NOT_OPEN_TEXT, openHintVisible = false, walletOpen = false) + assertNotNull(alone) + assertEquals(WalletFailureTone.Info, alone!!.tone) + assertEquals("No wallet open", alone.title) + assertEquals(WALLET_NOT_OPEN_TEXT, alone.text) + assertNull( + "the state ended when a wallet was opened", + walletFailureBanner(WALLET_NOT_OPEN_TEXT, openHintVisible = false, walletOpen = true), + ) + } + + @Test + fun a_real_failure_still_paints_red() { + val refused = walletFailureText("wallet connect: Connection refused (os error 111)")!! + val banner = walletFailureBanner(refused, openHintVisible = true, walletOpen = false)!! + assertEquals("a refusal is still a failure", WalletFailureTone.Error, banner.tone) + assertEquals("Wallet error", banner.title) + assertEquals(refused, banner.text) + + val exited = walletFailureText("spawn monero-wallet-rpc: No such file or directory (os error 2)")!! + assertEquals(WalletFailureTone.Error, walletFailureBanner(exited, false, false)!!.tone) + + assertNull(walletFailureBanner(null, true, false)) + assertNull(walletFailureBanner(" ", true, false)) + } } 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 fac959d..aab4313 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 @@ -477,4 +477,27 @@ class WalletManagerTest { assertTrue(shouldReloadWalletReads("ready")) assertTrue(shouldReloadWalletReads(" Ready ")) } + + @Test + fun the_tui_not_configured_copy_is_mapped_and_never_rendered_verbatim() { + // `src/wallet.rs::NOT_CONFIGURED_MSG` is the desktop TUI's refusal. A + // phone has no F7 key and no ONIONWIRE_WALLET_RPC, so that sentence is + // the second dead end the device report caught: a passphrase was typed + // into Create, and the screen answered with a keyboard shortcut. + val tui = "wallet not configured — open F7 to set it up, or set ONIONWIRE_WALLET_RPC" + val shown = walletFailureText(tui) + assertEquals(WALLET_RPC_NOT_RUNNING_TEXT, shown) + assertFalse("no F7 reaches the screen", shown!!.contains("F7")) + assertFalse("no env var name either", shown.contains("ONIONWIRE_WALLET_RPC")) + assertTrue("the phone sentence says what to do", shown.contains("Start it on the node card")) + + // Each fragment alone is the same fact and is mapped too; case and + // spacing are not load-bearing. + assertEquals(WALLET_RPC_NOT_RUNNING_TEXT, walletFailureText("Open F7")) + assertEquals(WALLET_RPC_NOT_RUNNING_TEXT, walletFailureText("Wallet Not Configured")) + assertEquals(WALLET_RPC_NOT_RUNNING_TEXT, walletFailureText("set ONIONWIRE_WALLET_RPC")) + + // And it is idempotent: the sticky error card re-filters its own text. + assertEquals(WALLET_RPC_NOT_RUNNING_TEXT, walletFailureText(shown)) + } } From a375ef9d1e86582c35ccaced0ac87e83a2a14204 Mon Sep 17 00:00:00 2001 From: agent Date: Sat, 31 Oct 2026 01:23:18 -0400 Subject: [PATCH 08/10] wallet_child: name argv[0] in spawn errors and pre-flight the RPC bin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Android report was `spawn monero-wallet-rpc: No such file or directory (os error 2)` — the label, not the argv[0] that failed, so a bare name and an absolute jniLibs path read identically. - spawn() now prints the label and argv[0]: `spawn monero-wallet-rpc (/data/app/.../libmonerowalletrpc.so): ...`, errno verbatim. - check_wallet_rpc_bin() pre-flights the resolved bin before anything is spawned: not found / not a file / not executable, with the configured path in the message. No PATH search, no fallback. - A bare wallet_rpc_bin is refused where a child has no PATH to resolve it (cfg(target_os = "android")), in ChildConfig::validate() and in the start-path pre-flight. Desktop keeps the bare-name default. - Tests for each refusal and for the argv[0] error; the node test that asserted the old `spawn` copy now asserts the path. --- src/node.rs | 5 +- src/wallet_child.rs | 205 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 201 insertions(+), 9 deletions(-) diff --git a/src/node.rs b/src/node.rs index 86b6412..16efa37 100644 --- a/src/node.rs +++ b/src/node.rs @@ -4347,7 +4347,10 @@ pub(crate) mod tests { let err = node .start_wallet_child() .expect_err("a missing binary fails"); - assert!(err.contains("spawn"), "{err}"); + // The refusal names the configured path: the old `spawn