improve error handling for qr scanner

This commit is contained in:
2026-06-26 20:54:15 +07:00
parent 25ba03562a
commit 8c35134bba
3 changed files with 16 additions and 16 deletions

View File

@@ -94,17 +94,18 @@ fun ImportScreen() {
LaunchedEffect(qrScanResult.content) {
qrScanResult.content?.let { result ->
runCatching {
if (result.startsWith("nsec")) {
if (result.startsWith("nsec1")) {
Keys.parse(result)
} else if (result.startsWith("bunker://")) {
NostrConnectUri.parse(result)
} else {
throw IllegalArgumentException("Invalid secret: $result")
throw IllegalArgumentException("Unsupported secret format")
}
}.onSuccess {
secret = result
}.onFailure { e ->
snackbarHostState.showSnackbar("Invalid secret: ${e.message}")
}
.onSuccess { it -> secret = result }
.onFailure { e -> println("Failed to parse QR: ${e.message}") }
// Clear the nav state
qrScanResult.clear()
}

View File

@@ -109,14 +109,13 @@ fun NewChatScreen() {
LaunchedEffect(qrScanResult.content) {
qrScanResult.content?.let { result ->
// Verify the content
runCatching { PublicKey.parse(result) }
.onSuccess { pubkey ->
selectedReceivers.add(pubkey)
}
.onFailure { e ->
println("Failed to parse QR: ${e.message}")
}
runCatching {
PublicKey.parse(result)
}.onSuccess { pubkey ->
selectedReceivers.add(pubkey)
}.onFailure { e ->
snackbarHostState.showSnackbar("Invalid address: ${e.message}")
}
// Clear the nav state
qrScanResult.clear()
}

View File

@@ -98,12 +98,12 @@ fun ScanScreen() {
.border(2.dp, Color.White, RoundedCornerShape(12.dp))
)
Text(
modifier = Modifier
.align(Alignment.BottomCenter)
.padding(bottom = 64.dp),
text = "Scan a Nostr address",
style = MaterialTheme.typography.titleSmallEmphasized,
color = Color.White,
modifier = Modifier
.align(Alignment.BottomCenter)
.padding(bottom = 64.dp)
)
}
}