Fix search: use resolveDetailed() for proper timeout handling

The search bar was using resolve() which lets
NamecoinLookupException.ServersUnreachable propagate as an exception,
causing 'servers unreachable' to appear immediately instead of waiting
for the actual lookup to complete.

Switch to resolveDetailed() which catches exceptions internally and
returns typed outcomes (Success/NameNotFound/NoNostrField/
ServersUnreachable/InvalidIdentifier/Timeout). The search screen now
shows Loading for the full duration of the attempt (up to 20s) and
only shows the error after all servers have actually been tried.
This commit is contained in:
M
2026-03-24 07:55:30 +11:00
committed by m
parent a7c4842d60
commit 21133c34c0
@@ -173,22 +173,29 @@ fun SearchScreen(
var namecoinState by remember { mutableStateOf<NamecoinResolveState?>(null) }
// Resolve Namecoin identifiers with cancellation of stale lookups
// Resolve Namecoin identifiers with cancellation of stale lookups.
// Uses resolveDetailed() which returns typed outcomes instead of throwing,
// so we get proper NotFound/Expired/ServersUnreachable states.
LaunchedEffect(displayText, namecoinEnabled) {
if (!namecoinEnabled || !isNamecoinQuery || namecoinService == null) {
namecoinState = null
return@LaunchedEffect
}
namecoinState = NamecoinResolveState.Loading
try {
val result = namecoinService.resolve(displayText.trim())
namecoinState = if (result != null) {
NamecoinResolveState.Resolved(result)
} else {
val outcome = namecoinService.resolveDetailed(displayText.trim())
namecoinState = when (outcome) {
is NamecoinResolveOutcome.Success ->
NamecoinResolveState.Resolved(outcome.result)
is NamecoinResolveOutcome.NameNotFound ->
NamecoinResolveState.NotFound
}
} catch (e: Exception) {
namecoinState = NamecoinResolveState.Error(e.message ?: "Resolution failed")
is NamecoinResolveOutcome.NoNostrField ->
NamecoinResolveState.Error("Name exists but has no Nostr pubkey")
is NamecoinResolveOutcome.ServersUnreachable ->
NamecoinResolveState.Error("ElectrumX servers unreachable — check your connection or try again")
is NamecoinResolveOutcome.InvalidIdentifier ->
NamecoinResolveState.Error("Invalid Namecoin identifier")
is NamecoinResolveOutcome.Timeout ->
NamecoinResolveState.Error("Resolution timed out — servers may be slow, try again")
}
}