Compare commits

..
9 changed files with 994 additions and 1420 deletions

View file

@ -192,11 +192,9 @@ private fun ReadyGraph(vm: WireViewModel, ready: Phase.Ready, keepAliveNote: Str
} }
composable(Routes.Wallet) { 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( WalletScreen(
vm = vm, vm = vm,
onBack = { nav.popBackStack() },
onOpenWallets = { nav.navigate(Routes.Wallets) }, onOpenWallets = { nav.navigate(Routes.Wallets) },
) )
} }

View file

@ -56,7 +56,7 @@ import uniffi.onionwire_sdk.checkAddress
* store error after it. * store error after it.
* - An **empty** address is a real, allowed value: it clears the profile * - An **empty** address is a real, allowed value: it clears the profile
* address. It is labelled with its consequence, because with no profile * address. It is labelled with its consequence, because with no profile
* address and no running wallet the core has nothing to hand a payer * address and no running wallet child the core has nothing to hand a payer
* (`Node::wallet_receive_address`) and the invoice path fails. * (`Node::wallet_receive_address`) and the invoice path fails.
* - The bio is carried, not owned: a save that did not touch the bio field * - 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 * writes back the value read from the store immediately before the write, so
@ -211,7 +211,7 @@ fun ProfileScreen(
supportingText = { supportingText = {
Text( Text(
// The consequence, on the screen, before a payment fails: // The consequence, on the screen, before a payment fails:
// `Node::wallet_receive_address` uses the wallet process's // `Node::wallet_receive_address` uses the wallet child's
// subaddress while it is up and this address otherwise, // subaddress while it is up and this address otherwise,
// and with neither there is nothing to be paid to. // and with neither there is nothing to be paid to.
profileAddressNotice(form.address), 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. * What an empty address means, stated where the address is typed.
* *
* `Node::wallet_receive_address` answers with the wallet process's own subaddress * `Node::wallet_receive_address` answers with the wallet child's own subaddress
* while it is up, and this address otherwise; with neither, the invoice path * 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 * fails outright. The user should read that here, not after a friend's payment
* bounces. * bounces.
@ -445,7 +445,7 @@ internal const val PROFILE_SAVED: String = "profile saved"
internal fun profileAddressNotice(address: String): String = internal fun profileAddressNotice(address: String): String =
if (address.trim().isEmpty()) { if (address.trim().isEmpty()) {
"Empty is allowed, and it clears the profile address. Your receive address " + "Empty is allowed, and it clears the profile address. Your receive address " +
"then comes from the running wallet — with no address " + "then comes from the wallet child while it is running — with no address " +
"here and no wallet running, nobody can send you an invoice." "here and no wallet running, nobody can send you an invoice."
} else { } else {
"What friends pay to. Validated before it is saved; an invalid address is " + "What friends pay to. Validated before it is saved; an invalid address is " +

View file

@ -5,7 +5,7 @@ import com.siriusdevops.onionwire.wallet.WalletChildBinaryPaths
import java.util.Locale import java.util.Locale
/** /**
* One snapshot of the app-owned wallet process, as the wallet screen sees it. * One snapshot of the app-owned wallet child, as the wallet screen sees it.
* *
* A plain mirror of the fields `WalletChildStatus` carries over UniFFI * A plain mirror of the fields `WalletChildStatus` carries over UniFFI
* (`state`, `running`, `configured`, `chain_source`, `last_error`) — the same * (`state`, `running`, `configured`, `chain_source`, `last_error`) — the same
@ -97,7 +97,7 @@ sealed interface WalletChildPhase {
data object Unread : WalletChildPhase { data object Unread : WalletChildPhase {
override val testTag: String = "child-unread" override val testTag: String = "child-unread"
override val label: String = "reading…" override val label: String = "reading…"
override val contentDescription: String = "Reading the wallet status" override val contentDescription: String = "Reading the wallet child status"
override val live: Boolean = false override val live: Boolean = false
override val dead: Boolean = false override val dead: Boolean = false
} }
@ -106,7 +106,7 @@ sealed interface WalletChildPhase {
data object Off : WalletChildPhase { data object Off : WalletChildPhase {
override val testTag: String = "child-off" override val testTag: String = "child-off"
override val label: String = "off" override val label: String = "off"
override val contentDescription: String = "The wallet is off" override val contentDescription: String = "The wallet child is off"
override val live: Boolean = false override val live: Boolean = false
override val dead: Boolean = false override val dead: Boolean = false
} }
@ -116,7 +116,7 @@ sealed interface WalletChildPhase {
override val testTag: String = "child-connecting" override val testTag: String = "child-connecting"
override val label: String = "connecting" override val label: String = "connecting"
override val contentDescription: String = override val contentDescription: String =
"The wallet is starting; its RPC has not answered yet" "The wallet child is up; its wallet RPC has not answered yet"
override val live: Boolean = true override val live: Boolean = true
override val dead: Boolean = false override val dead: Boolean = false
} }
@ -135,7 +135,7 @@ sealed interface WalletChildPhase {
data object Ready : WalletChildPhase { data object Ready : WalletChildPhase {
override val testTag: String = "child-ready" override val testTag: String = "child-ready"
override val label: String = "ready" override val label: String = "ready"
override val contentDescription: String = "The wallet is ready" override val contentDescription: String = "The wallet child is ready"
override val live: Boolean = true override val live: Boolean = true
override val dead: Boolean = false override val dead: Boolean = false
} }
@ -144,7 +144,7 @@ sealed interface WalletChildPhase {
data class Exited(val reason: String?) : WalletChildPhase { data class Exited(val reason: String?) : WalletChildPhase {
override val testTag: String = "child-exited" override val testTag: String = "child-exited"
override val label: String = "exited" override val label: String = "exited"
override val contentDescription: String = "The wallet process exited" override val contentDescription: String = "The wallet child exited"
override val live: Boolean = false override val live: Boolean = false
override val dead: Boolean = true override val dead: Boolean = true
} }
@ -158,7 +158,7 @@ sealed interface WalletChildPhase {
override val testTag: String = "child-unrecognised" override val testTag: String = "child-unrecognised"
override val label: String = "unknown (${shortSendReason(raw, UNRECOGNISED_BUDGET)})" override val label: String = "unknown (${shortSendReason(raw, UNRECOGNISED_BUDGET)})"
override val contentDescription: String = override val contentDescription: String =
"The wallet reported a state this build does not know" "The wallet child reported a state this build does not know"
override val live: Boolean = false override val live: Boolean = false
override val dead: Boolean = false override val dead: Boolean = false
} }
@ -336,26 +336,25 @@ const val ONION_NEEDS_ARTI_NOTICE: String =
"A .onion daemon needs the arti SOCKS child, which this build does not bundle." "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. */ /** Shown while the first `wallet_status()` read is still in flight. */
const val READING_CHILD_NOTICE: String = "Reading the wallet status…" const val READING_CHILD_NOTICE: String = "Reading the wallet child status…"
const val STARTING_CHILD_NOTICE: String = 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." "Start is running. Status stays off until the on-device node answers — that can take a minute, and is not a dead button."
/** /**
* The alert banner the on-device node is offered with, **before** Start. * The caveat the on-device node is offered with, **before** Start.
* *
* Cuprate's own user book says *"do NOT use cuprated for any serious purposes"*, * 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 * 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 mainnet is * measured in this repo are in `docs/cuprate-launch-spike.md`), and the daemon
* unvalidated. The title is the banner's; the two sentences are the body — one * this app launches is pinned to **testnet** (`src/cuprate.rs`). One sentence, not
* copy of the caveat, never a second one elsewhere on the screen, so the two * a glyph: the choice is opt-in and never a default, and a user who reads only
* can never drift apart. * this line still knows what they picked.
*/ */
const val CUPRATE_ON_DEVICE_TITLE: String = "Experimental On-Device Node (Cuprate)" const val CUPRATE_PREPRODUCTION_WARNING: String =
const val CUPRATE_ON_DEVICE_BODY: String = "On-device node is Cuprate, which is pre-production: its own user book says do NOT use " +
"Pre-production software with incomplete RPC parity (#278). Do not use for significant " + "cuprated for any serious purposes, mainnet is unvalidated, and its monerod RPC parity " +
"funds. Mainnet is unvalidated, and Cuprate's own user book says do NOT use cuprated " + "is incomplete (Cuprate issue #278). Try the in-process path; do not hold funds on it."
"for any serious purposes."
/** /**
* This build was compiled without the `cuprate-daemon` feature, so the stored * This build was compiled without the `cuprate-daemon` feature, so the stored
@ -464,131 +463,6 @@ fun formatBytes(bytes: Long): String = when {
else -> "$bytes B" 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. * Why **Start** is not actionable, or `null` when it is.
* *
@ -605,11 +479,8 @@ fun startBlockedReason(
bins.walletRpc == null -> NO_WALLET_RPC_MESSAGE bins.walletRpc == null -> NO_WALLET_RPC_MESSAGE
starting -> STARTING_CHILD_NOTICE starting -> STARTING_CHILD_NOTICE
input == null -> READING_CHILD_NOTICE input == null -> READING_CHILD_NOTICE
// Unreachable from the wallet screen: while the wallet runs the lifecycle input.running -> "The wallet child is already running."
// control *is* Stop, so Start is never offered. Kept as a pure predicate so !input.configured -> "No chain source yet: a wallet child needs a daemon to dial."
// 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 // 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. // option is readable and unstoppable, so say it before the user presses Start.
input.chainInProcess && !input.nodeAvailable -> CUPRATE_NOT_IN_BUILD_NOTICE input.chainInProcess && !input.nodeAvailable -> CUPRATE_NOT_IN_BUILD_NOTICE
@ -623,7 +494,7 @@ fun startBlockedReason(
*/ */
fun stopBlockedReason(input: WalletChildInput?): String? = when { fun stopBlockedReason(input: WalletChildInput?): String? = when {
input == null -> READING_CHILD_NOTICE input == null -> READING_CHILD_NOTICE
!input.running -> "No wallet is running." !input.running -> "No wallet child is running."
else -> null else -> null
} }

View file

@ -14,13 +14,20 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll 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.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text 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.Composable
import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
@ -33,21 +40,11 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalView import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.platform.testTag import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.siriusdevops.onionwire.WireViewModel 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 kotlinx.coroutines.launch
import uniffi.onionwire_sdk.WalletKeys import uniffi.onionwire_sdk.WalletKeys
import uniffi.onionwire_sdk.WalletRow import uniffi.onionwire_sdk.WalletRow
@ -86,7 +83,7 @@ internal fun walletRowDate(createdAt: Long): String {
} }
/** /**
* Whether the wallet process has a wallet open that the RPC answers for. * Whether the wallet child has a wallet open that the RPC answers for.
* *
* The core's `state` is the only honest signal available here: `connecting` * 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 * means its wallet RPC has not answered, `off`/`exited` mean there is no child
@ -129,8 +126,8 @@ internal fun walletSecretsBlockedReason(
isActive: Boolean, isActive: Boolean,
walletReadable: Boolean, walletReadable: Boolean,
): String? = when { ): String? = when {
!isActive -> "Open this wallet to view its 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." !walletReadable -> "the wallet child is not running — start it on the wallet screen to read the backup"
else -> null else -> null
} }
@ -162,18 +159,14 @@ private val RAW_RPC_CODE = Regex("""(?<![\d-])-13(?!\d)""")
*/ */
private val RAW_JSON = Regex("""[{}]|\[\s*\{|"(error|code|message|result|jsonrpc)"\s*:""") private val RAW_JSON = Regex("""[{}]|\[\s*\{|"(error|code|message|result|jsonrpc)"\s*:""")
/** /** Shown instead of the daemon's `-13` / `No wallet file` / JSON answer. */
* Shown instead of the daemon's `-13` / `No wallet file` / JSON answer.
*
* A state the app is *in*, not a failure of the last call — the wallet screen
* renders it as an info banner, never as a red error line.
*/
const val WALLET_NOT_OPEN_TEXT: String = const val WALLET_NOT_OPEN_TEXT: String =
"Open or create a wallet to enable balance, address, and backup controls." "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."
/** Shown instead of a raw JSON refusal that names no condition the user can act on. */ /** Shown instead of a raw JSON refusal that names no condition the user can act on. */
const val WALLET_DAEMON_REFUSED_TEXT: String = const val WALLET_DAEMON_REFUSED_TEXT: String =
"The wallet daemon refused that request and gave no readable reason. Check the wallet " + "The wallet daemon refused that request and gave no readable reason. Check the wallet child " +
"on the wallet screen, then try again." "on the wallet screen, then try again."
/** /**
@ -258,7 +251,7 @@ internal fun walletPassphrasePromptVisible(needsPassphrase: Boolean, walletOpen:
* A file name is required because the open is per-file (`open_wallet` on the * A file name is required because the open is per-file (`open_wallet` on the
* file the child is pointed at); a blank passphrase is refused by the core * file the child is pointed at); a blank passphrase is refused by the core
* anyway, so the button stays dead rather than round-tripping a guaranteed * anyway, so the button stays dead rather than round-tripping a guaranteed
* failure. An in-flight open is not re-submitted: it restarts the wallet process. * failure. An in-flight open is not re-submitted: it restarts the wallet child.
*/ */
internal fun walletPassphraseSubmitEnabled( internal fun walletPassphraseSubmitEnabled(
activeFilename: String?, activeFilename: String?,
@ -277,14 +270,14 @@ internal fun walletPassphraseBlockedReason(
typed: String, typed: String,
): String? = when { ): String? = when {
activeFilename == null -> activeFilename == null ->
"No wallet file is open yet — open one from the list below." "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." typed.isEmpty() -> "type the passphrase for this wallet file"
else -> null else -> null
} }
/** /**
* Why the wallet process has nothing open, in this app's words — or `null` when * Why the wallet child has nothing open, in this app's words — or `null` when
* it has a wallet open, or nothing is running to hold one. * it has a wallet open, or no child is running to hold one.
* *
* A live `monero-wallet-rpc` is not a usable wallet: it starts with no wallet * 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 * file open, and every read then answers `-13 No wallet file`. The status line
@ -301,10 +294,11 @@ internal fun walletChildOpenHint(
): String? = when { ): String? = when {
!childRunning || walletOpen -> null !childRunning || walletOpen -> null
needsPassphrase -> needsPassphrase ->
"The wallet needs its passphrase: open it on the Saved wallets screen, where the " + "No wallet is open in the wallet child: it needs the passphrase for the file it is " +
"prompt is." "pointed at. Open it on the Saved wallets screen, where the prompt is."
else -> else ->
"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 a saved wallet on the Saved wallets " +
"screen, or create or import one here."
} }
/** /**
@ -325,6 +319,7 @@ internal fun walletChildOpenHint(
* in saved state (`remember`, not `rememberSaveable`, and cleared on * in saved state (`remember`, not `rememberSaveable`, and cleared on
* dispose). * dispose).
*/ */
@OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun WalletManagerScreen( fun WalletManagerScreen(
vm: WireViewModel, vm: WireViewModel,
@ -508,24 +503,25 @@ fun WalletManagerScreen(
// Root owns systemBars ∪ ime, exactly as the wallet screen does (see // Root owns systemBars ∪ ime, exactly as the wallet screen does (see
// `screenContentInsets`). // `screenContentInsets`).
contentWindowInsets = WindowInsets(0, 0, 0, 0), contentWindowInsets = WindowInsets(0, 0, 0, 0),
containerColor = OwColors.Canvas,
topBar = { topBar = {
OwTopBar( TopAppBar(
title = "Saved wallets", title = { Text("Saved wallets") },
// A pushed sub-screen, so the chevron — never the word "Back". navigationIcon = {
onBack = onBack, TextButton(onClick = onBack) { Text("Back") }
},
actions = { actions = {
OwButton( TextButton(
text = "Refresh",
variant = OwButtonVariant.Outline,
onClick = { onClick = {
scope.launch { scope.launch {
vm.refreshWalletChild() vm.refreshWalletChild()
reload() reload()
} }
}, },
) ) { Text("Refresh") }
}, },
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.background,
),
) )
}, },
) { pad -> ) { pad ->
@ -563,21 +559,22 @@ fun WalletManagerScreen(
) )
} }
keysError?.let { message -> keysError?.let { message ->
OwAlertBanner( Card(
variant = OwAlertVariant.Error,
title = "Could not read the open wallet's private keys",
description = message,
modifier = Modifier modifier = Modifier
.padding(horizontal = 16.dp, vertical = 8.dp) .fillMaxWidth()
.testTag("wallet-keys-error"), .padding(horizontal = 12.dp, vertical = 8.dp),
action = { colors = CardDefaults.cardColors(
OwButton( containerColor = MaterialTheme.colorScheme.errorContainer,
text = "Dismiss", ),
variant = OwButtonVariant.Outline, ) {
onClick = { keysError = null }, 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") }
}
}
} }
actionError?.let { ErrorText(it) } actionError?.let { ErrorText(it) }
@ -611,55 +608,46 @@ fun WalletManagerScreen(
// A read failure is not an empty catalogue, and the two must // A read failure is not an empty catalogue, and the two must
// not read alike: one is "the store did not answer", the other // not read alike: one is "the store did not answer", the other
// is "you have no wallets yet". // is "you have no wallets yet".
listError != null -> OwAlertBanner( listError != null -> Column(Modifier.padding(12.dp)) {
variant = OwAlertVariant.Error, Text(
title = "Could not read the wallet catalogue", "could not read the wallet catalogue",
description = listError ?: "", style = MaterialTheme.typography.titleSmall,
modifier = Modifier color = MaterialTheme.colorScheme.error,
.padding(horizontal = 16.dp, vertical = 8.dp) )
.testTag("wallet-list-error"), Spacer(Modifier.height(4.dp))
action = { Text(
OwButton( listError ?: "",
text = "Retry", style = MaterialTheme.typography.bodySmall,
variant = OwButtonVariant.Outline, color = MaterialTheme.colorScheme.error,
onClick = { scope.launch { reload() } }, )
) Spacer(Modifier.height(8.dp))
}, TextButton(onClick = { scope.launch { reload() } }) { Text("Retry") }
) }
listed == null -> Text( listed == null -> Text(
"Loading…", "loading…",
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyMedium,
color = OwColors.TextSecondary, modifier = Modifier.padding(12.dp),
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
) )
listed.isEmpty() -> OwCard( listed.isEmpty() -> Column(Modifier.padding(12.dp)) {
modifier = Modifier Text("No saved wallets yet", style = MaterialTheme.typography.titleSmall)
.fillMaxWidth() Spacer(Modifier.height(4.dp))
.padding(horizontal = 16.dp, vertical = 8.dp),
) {
OwSectionTitle("No saved wallets yet")
Spacer(Modifier.height(6.dp))
Text( Text(
"Wallets this install remembers show up here. Create or import one " + "Wallets this install remembers show up here. Create or import one " +
"on the wallet screen and it appears on the next look.", "on the wallet screen and it appears on the next look.",
style = MaterialTheme.typography.bodySmall, 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 -> { else -> {
Label( Text(
"${listed.size} SAVED ${if (listed.size == 1) "WALLET" else "WALLETS"}", "${listed.size} saved ${if (listed.size == 1) "wallet" else "wallets"}",
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp), style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp),
) )
listed.forEach { row -> listed.forEach { row ->
val isActive = active != null && active == row.walletFilename val isActive = active != null && active == row.walletFilename
@ -692,7 +680,7 @@ fun WalletManagerScreen(
* and whether it is the open one. * and whether it is the open one.
* *
* The open row is not tappable. Re-opening it would stop and restart a running * The open row is not tappable. Re-opening it would stop and restart a running
* wallet process onto the file it already has open — a slow no-op whose only * wallet child onto the file it already has open — a slow no-op whose only
* effect is to make the screen look like it did something. * effect is to make the screen look like it did something.
*/ */
@Composable @Composable
@ -706,70 +694,72 @@ private fun WalletRowCard(
onShowPhrase: () -> Unit, onShowPhrase: () -> Unit,
onShowKeys: () -> Unit, onShowKeys: () -> Unit,
) { ) {
OwCard( Card(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 6.dp) .padding(horizontal = 12.dp, vertical = 6.dp)
.then(if (isActive) Modifier else Modifier.clickable(enabled = !opening, onClick = onOpen)), .then(if (isActive) Modifier else Modifier.clickable(enabled = !opening, onClick = onOpen)),
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.surfaceVariant,
),
) { ) {
Row( Column(Modifier.padding(12.dp)) {
Modifier.fillMaxWidth(), Row(
horizontalArrangement = Arrangement.SpaceBetween, Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween,
) { verticalAlignment = Alignment.CenterVertically,
Text( ) {
walletRowLabel(row.name, row.walletFilename), Text(
style = MaterialTheme.typography.titleMedium, walletRowLabel(row.name, row.walletFilename),
color = OwColors.TextPrimary, style = MaterialTheme.typography.titleSmall,
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,
) )
opening -> OwPill(text = "Opening…", textColor = OwColors.TextSecondary) when {
else -> OwPill(text = "Tap to open", textColor = OwColors.TextSecondary) 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,
)
}
} }
} Spacer(Modifier.height(4.dp))
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(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( Text(
it, "file ${row.walletFilename}",
style = MaterialTheme.typography.labelSmall, style = MaterialTheme.typography.bodySmall,
color = OwColors.TextMuted, fontFamily = FontFamily.Monospace,
) )
Text(
"created ${walletRowDate(row.createdAt)}",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
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,
)
}
} }
} }
} }
@ -784,10 +774,10 @@ private fun WalletRowCard(
* wallet file. It is never logged, never persisted, and the caller drops it when * wallet file. It is never logged, never persisted, and the caller drops it when
* the screen goes. * the screen goes.
* *
* Submit is dead while the wallet is not running: the core verifies a * Submit is dead while the wallet child is not running: the core verifies a
* passphrase against a live daemon and refuses to seal an unverified one, so a * passphrase against a live daemon and refuses to seal an unverified one, so a
* tap there could only fail. When it *is* up — including `connecting`, whose RPC * tap there could only fail. When the child *is* up — including `connecting`,
* has not answered yet — the core restarts it onto the file with this * whose RPC has not answered yet — the core restarts it onto the file with this
* passphrase, which is exactly the fix. * passphrase, which is exactly the fix.
*/ */
@Composable @Composable
@ -801,74 +791,77 @@ private fun WalletPassphraseCard(
error: String?, error: String?,
onSubmit: () -> Unit, onSubmit: () -> Unit,
) { ) {
OwCard( Card(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp) .padding(horizontal = 12.dp, vertical = 8.dp)
.testTag("wallet-passphrase-card"), .testTag("wallet-passphrase-card"),
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.surfaceVariant,
),
) { ) {
OwSectionTitle("This wallet needs its passphrase") Column(Modifier.padding(12.dp)) {
Spacer(Modifier.height(6.dp)) Text("This wallet needs its passphrase", style = MaterialTheme.typography.titleSmall)
Text( Spacer(Modifier.height(4.dp))
"The wallet is pointed at ${filename ?: "a wallet file"} but this install " + Text(
"holds no passphrase that opens it — the wallet was created before the " + "The wallet child is pointed at ${filename ?: "a wallet file"} but this install " +
"passphrase was stored, or on another device. Type it once: the wallet " + "holds no passphrase that opens it — the wallet was created before the " +
"opens, and later starts reopen it on their own.", "passphrase was stored, or on another device. Type it once: the wallet " +
style = MaterialTheme.typography.bodySmall, "opens, and later starts reopen it on their own.",
color = OwColors.TextSecondary, style = MaterialTheme.typography.bodySmall,
)
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))
OwAlertBanner(
variant = OwAlertVariant.Info,
title = "The wallet is not running",
description = "Start it on the wallet screen, then come back.",
) )
}
error?.let {
Spacer(Modifier.height(8.dp)) Spacer(Modifier.height(8.dp))
OwAlertBanner( OutlinedTextField(
variant = OwAlertVariant.Error, value = typed,
title = "Could not open this wallet", onValueChange = onTyped,
description = it, 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(4.dp))
blockedReason?.let { 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)) Spacer(Modifier.height(8.dp))
OwAlertBanner( Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
variant = OwAlertVariant.Info, Button(
title = "Not ready to open", onClick = onSubmit,
description = it, enabled = childRunning &&
) walletPassphraseSubmitEnabled(filename, typed, inFlight),
modifier = Modifier.testTag("wallet-passphrase-submit"),
) { Text(if (inFlight) "Opening…" else "Open this wallet") }
}
} }
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"),
)
} }
} }
@ -887,57 +880,64 @@ private fun PrivateKeysCard(
warning: String, warning: String,
onDone: () -> Unit, onDone: () -> Unit,
) { ) {
OwCard( Card(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp) .padding(horizontal = 12.dp, vertical = 8.dp),
.testTag("wallet-private-keys-card"), colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.errorContainer,
),
) { ) {
OwSectionTitle("Private keys of the open wallet") Column(Modifier.padding(12.dp)) {
Spacer(Modifier.height(6.dp)) Text("Private keys of the open wallet", style = MaterialTheme.typography.titleSmall)
Text(warning, style = MaterialTheme.typography.bodySmall, color = OwColors.Danger) Spacer(Modifier.height(4.dp))
Spacer(Modifier.height(12.dp)) Text(warning, style = MaterialTheme.typography.bodySmall)
Label("VIEW KEY") Spacer(Modifier.height(8.dp))
// 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( Text(
"View-only wallet — no spend key.", "view key",
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.labelSmall,
color = OwColors.TextSecondary, color = MaterialTheme.colorScheme.onSurfaceVariant,
) )
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 @Composable
private fun ErrorText(text: String) { private fun ErrorText(text: String) {
val notOpen = text == WALLET_NOT_OPEN_TEXT Text(
OwAlertBanner( text,
variant = if (notOpen) OwAlertVariant.Info else OwAlertVariant.Error, style = MaterialTheme.typography.bodySmall,
title = if (notOpen) "No wallet open" else "Something went wrong", color = MaterialTheme.colorScheme.error,
description = text, modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp),
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
) )
} }

View file

@ -17,7 +17,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip 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.role import androidx.compose.ui.semantics.role
import androidx.compose.ui.semantics.selected import androidx.compose.ui.semantics.selected
@ -43,14 +42,6 @@ fun OwSegmentedControl(
onSelect: (Int) -> Unit, onSelect: (Int) -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
enabled: Boolean = true, 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<String?> = emptyList(),
) { ) {
Row( Row(
modifier = modifier modifier = modifier
@ -76,14 +67,12 @@ fun OwSegmentedControl(
animationSpec = tween(durationMillis = 160), animationSpec = tween(durationMillis = 160),
label = "segment-text", label = "segment-text",
) )
val tag = testTags.getOrNull(index)
Box( Box(
modifier = Modifier modifier = Modifier
.weight(1f) .weight(1f)
.height(36.dp) .height(36.dp)
.clip(RoundedCornerShape(9.dp)) .clip(RoundedCornerShape(9.dp))
.background(container) .background(container)
.then(if (tag != null) Modifier.testTag(tag) else Modifier)
.clickable(enabled = enabled && !selected) { onSelect(index) } .clickable(enabled = enabled && !selected) { onSelect(index) }
.semantics { .semantics {
role = Role.Tab role = Role.Tab

View file

@ -239,9 +239,7 @@ class ProfileDraftTest {
fun an_empty_address_says_nobody_can_pay() { fun an_empty_address_says_nobody_can_pay() {
val text = profileAddressNotice("") val text = profileAddressNotice("")
assertTrue(text.contains("clears the profile address")) assertTrue(text.contains("clears the profile address"))
// The consequence, not the process name: the copy no longer says assertTrue(text.contains("wallet child"))
// "wallet child" anywhere a user can read it.
assertTrue(text.contains("running wallet"))
assertTrue(text.contains("nobody can send you an invoice")) assertTrue(text.contains("nobody can send you an invoice"))
} }

View file

@ -207,8 +207,8 @@ class WalletChildStatusTextTest {
@Test @Test
fun stop_is_blocked_when_nothing_is_running() { fun stop_is_blocked_when_nothing_is_running() {
assertTrue(stopBlockedReason(input("off"))!!.contains("No wallet is running")) assertTrue(stopBlockedReason(input("off"))!!.contains("No wallet child"))
assertTrue(stopBlockedReason(input("exited"))!!.contains("No wallet is running")) assertTrue(stopBlockedReason(input("exited"))!!.contains("No wallet child"))
assertEquals(READING_CHILD_NOTICE, stopBlockedReason(null)) assertEquals(READING_CHILD_NOTICE, stopBlockedReason(null))
} }
@ -397,7 +397,7 @@ class WalletChildStatusTextTest {
"a screen reader is told the same as the eye", "a screen reader is told the same as the eye",
spoken.endsWith(walletChildLine(input)), spoken.endsWith(walletChildLine(input)),
) )
assertTrue("it is still a sentence", spoken.startsWith("The wallet is starting")) assertTrue("it is still a sentence", spoken.startsWith("The wallet child is up"))
} }
@Test @Test
@ -417,17 +417,14 @@ class WalletChildStatusTextTest {
} }
@Test @Test
fun the_on_device_banner_is_titled_and_says_what_it_costs() { fun the_preproduction_warning_is_a_sentence_a_user_can_act_on() {
// The banner's title is the plan's exact string; the body keeps every val warning = CUPRATE_PREPRODUCTION_WARNING
// honesty bound the old single-sentence warning carried. assertTrue("it names the software", warning.contains("Cuprate"))
assertEquals("Experimental On-Device Node (Cuprate)", CUPRATE_ON_DEVICE_TITLE) assertTrue("it quotes the user book", warning.contains("do NOT use cuprated"))
val body = CUPRATE_ON_DEVICE_BODY assertTrue("it names the parity gap", warning.contains("Cuprate issue #278"))
assertTrue("it names the software", body.contains("Cuprate")) assertTrue("it says mainnet is unvalidated", warning.contains("mainnet is unvalidated"))
assertTrue("it names the parity gap", body.contains("#278")) assertTrue("it is a sentence, not a glyph", warning.trim().endsWith("."))
assertTrue("it quotes the user book", body.contains("do NOT use cuprated")) assertTrue("it is long enough to be a sentence", warning.length > 80)
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 ---------------------------------------------------- // --- storage honesty ----------------------------------------------------
@ -522,103 +519,4 @@ class WalletChildStatusTextTest {
assertEquals("1.5 GiB", formatBytes(3L * 1024 * 1024 * 1024 / 2)) assertEquals("1.5 GiB", formatBytes(3L * 1024 * 1024 * 1024 / 2))
assertEquals("3.0 GiB", formatBytes(CHAIN_FREE_SPACE_FLOOR_BYTES)) 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,
)
}
} }

View file

@ -117,7 +117,7 @@ class WalletManagerTest {
@Test @Test
fun a_row_that_is_not_open_says_to_open_it() { fun a_row_that_is_not_open_says_to_open_it() {
val why = walletSecretsBlockedReason(isActive = false, walletReadable = readable) 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 @Test
@ -212,7 +212,7 @@ class WalletManagerTest {
walletPassphraseSubmitEnabled(activeFilename = null, typed = "pw", inFlight = false), walletPassphraseSubmitEnabled(activeFilename = null, typed = "pw", inFlight = false),
) )
val why = walletPassphraseBlockedReason(activeFilename = null, typed = "pw") val why = walletPassphraseBlockedReason(activeFilename = null, typed = "pw")
assertTrue("got '$why'", why != null && why.contains("No wallet file is open yet")) assertTrue("got '$why'", why != null && why.contains("not pointed at"))
// The two reasons are different fixes and must not read alike. // The two reasons are different fixes and must not read alike.
assertFalse(why == walletPassphraseBlockedReason(activeFilename = openFile, typed = "")) assertFalse(why == walletPassphraseBlockedReason(activeFilename = openFile, typed = ""))
} }
@ -225,7 +225,7 @@ class WalletManagerTest {
@Test @Test
fun nothing_typed_is_the_other_reason() { fun nothing_typed_is_the_other_reason() {
val why = walletPassphraseBlockedReason(activeFilename = openFile, typed = "") 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 ----------------------- // --- the daemon's own words never reach the screen -----------------------
@ -348,12 +348,7 @@ class WalletManagerTest {
walletOpen = false, walletOpen = false,
needsPassphrase = false, needsPassphrase = false,
) )
// The §4.1 replacement copy, verbatim: a live wallet with no file open assertTrue("got '$hint'", hint != null && hint.contains("No wallet is 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!!) assertNoRawRpc(hint!!)
} }
@ -468,7 +463,7 @@ class WalletManagerTest {
fun wallet_reads_reload_only_once_the_child_is_answering() { fun wallet_reads_reload_only_once_the_child_is_answering() {
// `walletBalance()` answers `"err"` — it does not throw — while the // `walletBalance()` answers `"err"` — it does not throw — while the
// child is still dialling, so reloading in that window is what pins the // child is still dialling, so reloading in that window is what pins the
// headline on `Balance unavailable`. Reload only when the child has answered. // headline on `balance —`. Reload only when the child has answered.
assertFalse(shouldReloadWalletReads(null)) assertFalse(shouldReloadWalletReads(null))
assertFalse(shouldReloadWalletReads("off")) assertFalse(shouldReloadWalletReads("off"))
assertFalse(shouldReloadWalletReads("connecting")) assertFalse(shouldReloadWalletReads("connecting"))