android: do not paint a connect refusal while the wallet is connecting
This commit is contained in:
parent
25e4c67181
commit
9eb054b10f
3 changed files with 65 additions and 7 deletions
|
|
@ -201,6 +201,34 @@ internal fun walletFailureText(raw: String?): String? {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `lastError` as the wallet screen should paint it, given the child's `state`.
|
||||||
|
*
|
||||||
|
* Defense in depth behind the core's own fix: the 2s probe dials a wallet RPC
|
||||||
|
* that may not have bound its port yet, and that transient refusal
|
||||||
|
* (`wallet connect:` / `wallet write:`) is not a fact about the wallet — the
|
||||||
|
* child is still `connecting` and the next tick usually clears it. Painting it
|
||||||
|
* red in that window tells the user a start that is going to succeed has
|
||||||
|
* failed.
|
||||||
|
*
|
||||||
|
* Only `connecting` is suppressed, and only for those two prefixes. The same
|
||||||
|
* string once the child is `exited` / `syncing` / `off` means it accepted a
|
||||||
|
* connection and then stopped answering, which is exactly what the user needs
|
||||||
|
* to see. This mirrors the core's `error_is_unreachable` predicate verbatim —
|
||||||
|
* a bare `Connection refused` from anything else is not matched.
|
||||||
|
*
|
||||||
|
* Everything else goes through [walletFailureText], unchanged.
|
||||||
|
*/
|
||||||
|
internal fun displayLastError(state: String, raw: String?): String? {
|
||||||
|
val text = raw?.trim().orEmpty()
|
||||||
|
if (text.isEmpty()) return null
|
||||||
|
val connecting = state.trim().equals("connecting", ignoreCase = true)
|
||||||
|
if (connecting && (text.startsWith("wallet connect:") || text.startsWith("wallet write:"))) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return walletFailureText(text)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the manager screen must ask for a wallet-file passphrase.
|
* Whether the manager screen must ask for a wallet-file passphrase.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1135,12 +1135,14 @@ private fun CuprateModeButton(
|
||||||
* `wallet_status().last_error`, which is the *daemon's* own words on the path
|
* `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
|
* 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
|
* wallet file`, and `parse_json_rpc` strips the envelope and keeps that bare
|
||||||
* sentence. The status line renders this field — `walletChildLine`, and through
|
* sentence. A probe that dialled a port the child had not bound yet can also
|
||||||
* it `walletChildStatusDescription` for the screen reader — so the filter
|
* land here (`wallet connect: Connection refused`) — [displayLastError] drops
|
||||||
* belongs here, at the seam where the SDK record becomes the Kotlin model,
|
* that one while the child is still `connecting`. The status line renders this
|
||||||
* rather than at one of the render sites. `walletFailureText` is idempotent on
|
* field — `walletChildLine`, and through it `walletChildStatusDescription` for
|
||||||
* its own replacement texts, so the second pass on the sticky error card is
|
* the screen reader — so the filter belongs here, at the seam where the SDK
|
||||||
* stable.
|
* 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(
|
internal fun WalletChildStatus.toInput(): WalletChildInput = WalletChildInput(
|
||||||
state = state,
|
state = state,
|
||||||
|
|
@ -1152,7 +1154,7 @@ internal fun WalletChildStatus.toInput(): WalletChildInput = WalletChildInput(
|
||||||
nodeState = nodeState,
|
nodeState = nodeState,
|
||||||
height = height,
|
height = height,
|
||||||
targetHeight = targetHeight,
|
targetHeight = targetHeight,
|
||||||
lastError = walletFailureText(lastError),
|
lastError = displayLastError(state, lastError),
|
||||||
)
|
)
|
||||||
|
|
||||||
/** Generate a QR bitmap for the given URI string. Returns null on encode failure. */
|
/** Generate a QR bitmap for the given URI string. Returns null on encode failure. */
|
||||||
|
|
|
||||||
|
|
@ -311,6 +311,34 @@ class WalletManagerTest {
|
||||||
assertNoRawRpc(WALLET_DAEMON_REFUSED_TEXT)
|
assertNoRawRpc(WALLET_DAEMON_REFUSED_TEXT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- a connect refusal while the child is coming up -----------------------
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun connecting_connect_refusal_is_not_shown() {
|
||||||
|
// The Rust half stops storing this string in the first place; this is
|
||||||
|
// the display seam's own belt: a probe that dialled a port the child
|
||||||
|
// has not bound yet says nothing about whether the wallet is broken.
|
||||||
|
val raw = "wallet connect: Connection refused (os error 111)"
|
||||||
|
assertNull(displayLastError("connecting", raw))
|
||||||
|
assertNull(displayLastError(" connecting ", "wallet write: Connection reset"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun a_connect_refusal_after_connecting_is_still_shown() {
|
||||||
|
// Past `connecting` the same string means the child accepted a
|
||||||
|
// connection once and then died. Hiding that would hide a real failure.
|
||||||
|
val raw = "wallet connect: Connection refused (os error 111)"
|
||||||
|
assertEquals(raw, displayLastError("exited", raw))
|
||||||
|
assertEquals(raw, displayLastError("syncing", raw))
|
||||||
|
assertEquals(raw, displayLastError("off", raw))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun display_last_error_still_rewrites_no_wallet_file() {
|
||||||
|
assertEquals(WALLET_NOT_OPEN_TEXT, displayLastError("connecting", "No wallet file"))
|
||||||
|
assertEquals(WALLET_NOT_OPEN_TEXT, displayLastError("syncing", "wallet rpc error -13"))
|
||||||
|
}
|
||||||
|
|
||||||
// --- "there is no wallet open", on the wallet screen ---------------------
|
// --- "there is no wallet open", on the wallet screen ---------------------
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue