android: Start wallet no longer looks like a no-op while Cuprate launches
All checks were successful
ci / test (pull_request) Successful in 5m34s
ci / sdk (pull_request) Successful in 1m22s
android-ci / android (pull_request) Successful in 10m48s
ci / fuzz (pull_request) Successful in 4m52s

Tapping Start held the SQLCipher mutex for the whole in-process Node::launch
and blocked the UniFFI tokio worker, so wallet_status stayed off with no
error. Drop the store lock until creds are needed, spawn_blocking the sync
start, and show that Start is in flight.

The APK still runs Cuprate testnet only; this does not add mainnet or prune.
This commit is contained in:
agent 2026-09-19 12:03:01 -04:00
commit 0acf89a0b4
No known key found for this signature in database
7 changed files with 103 additions and 34 deletions

View file

@ -40,6 +40,7 @@ import uniffi.onionwire_sdk.WalletChildStatus
import uniffi.onionwire_sdk.Wire
import uniffi.onionwire_sdk.decodeInvite
import java.io.File
import java.util.concurrent.atomic.AtomicBoolean
sealed interface Phase {
/** No identity unlocked. Nothing Tor-related is running. */
@ -618,6 +619,14 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
private val _walletChildError = MutableStateFlow<String?>(null)
val walletChildError: StateFlow<String?> = _walletChildError.asStateFlow()
/**
* Start is in flight. Core status stays `off` until Cuprate/`monerod` answers,
* so the screen must not wait on that snapshot to show that the tap landed.
*/
private val startInFlight = AtomicBoolean(false)
private val _walletChildStarting = MutableStateFlow(false)
val walletChildStarting: StateFlow<Boolean> = _walletChildStarting.asStateFlow()
/** The stored chain source + binary settings, for prefilling the editor. */
private val _chainSource = MutableStateFlow<ChainConfig?>(null)
val chainSource: StateFlow<ChainConfig?> = _chainSource.asStateFlow()
@ -795,25 +804,28 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
fun chainFreeBytes(): Long? = ChainStorage.freeBytes(home)
/**
* Spawns the child (and its daemon/SOCKS siblings) and returns what the core
* reached.
*
* The returned state is `connecting` at best on the first call — the wallet
* RPC does not answer the instant the process exists — and that is reported
* as-is. The spawn is synchronous inside the node and a `.onion` source
* waits up to 20s for its SOCKS listener, so this never runs on the main
* thread.
* 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.
*/
suspend fun startWalletChild(): Result<WalletChildStatus> {
fun startWalletChild() {
if (!startInFlight.compareAndSet(false, true)) return
_walletChildStarting.value = true
_walletChildError.value = null
val started = withContext(Dispatchers.IO) {
runCatching { requireWire().startWalletChild() }
viewModelScope.launch {
try {
val started = withContext(Dispatchers.IO) {
runCatching { requireWire().startWalletChild() }
}
started.fold(
onSuccess = { _walletChild.value = it },
onFailure = { _walletChildError.value = it.message ?: it.toString() },
)
} finally {
startInFlight.set(false)
_walletChildStarting.value = false
}
}
started.fold(
onSuccess = { _walletChild.value = it },
onFailure = { _walletChildError.value = it.message ?: it.toString() },
)
return started
}
/** Stops the child and its siblings. Idempotent in the core. */