chore: improve qr scan result handling (#27)
Reviewed-on: #27
This commit was merged in pull request #27.
This commit is contained in:
@@ -94,17 +94,18 @@ fun ImportScreen() {
|
|||||||
LaunchedEffect(qrScanResult.content) {
|
LaunchedEffect(qrScanResult.content) {
|
||||||
qrScanResult.content?.let { result ->
|
qrScanResult.content?.let { result ->
|
||||||
runCatching {
|
runCatching {
|
||||||
if (result.startsWith("nsec")) {
|
if (result.startsWith("nsec1")) {
|
||||||
Keys.parse(result)
|
Keys.parse(result)
|
||||||
} else if (result.startsWith("bunker://")) {
|
} else if (result.startsWith("bunker://")) {
|
||||||
NostrConnectUri.parse(result)
|
NostrConnectUri.parse(result)
|
||||||
} else {
|
} 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
|
// Clear the nav state
|
||||||
qrScanResult.clear()
|
qrScanResult.clear()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,14 +109,13 @@ fun NewChatScreen() {
|
|||||||
LaunchedEffect(qrScanResult.content) {
|
LaunchedEffect(qrScanResult.content) {
|
||||||
qrScanResult.content?.let { result ->
|
qrScanResult.content?.let { result ->
|
||||||
// Verify the content
|
// Verify the content
|
||||||
runCatching { PublicKey.parse(result) }
|
runCatching {
|
||||||
.onSuccess { pubkey ->
|
PublicKey.parse(result)
|
||||||
|
}.onSuccess { pubkey ->
|
||||||
selectedReceivers.add(pubkey)
|
selectedReceivers.add(pubkey)
|
||||||
|
}.onFailure { e ->
|
||||||
|
snackbarHostState.showSnackbar("Invalid address: ${e.message}")
|
||||||
}
|
}
|
||||||
.onFailure { e ->
|
|
||||||
println("Failed to parse QR: ${e.message}")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear the nav state
|
// Clear the nav state
|
||||||
qrScanResult.clear()
|
qrScanResult.clear()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,16 +5,15 @@ import androidx.compose.foundation.Canvas
|
|||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.SnackbarHost
|
import androidx.compose.material3.SnackbarHost
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TopAppBar
|
|
||||||
import androidx.compose.material3.TopAppBarDefaults
|
import androidx.compose.material3.TopAppBarDefaults
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@@ -44,10 +43,10 @@ fun ScanScreen() {
|
|||||||
Scaffold(
|
Scaffold(
|
||||||
snackbarHost = { SnackbarHost(snackbarHostState) },
|
snackbarHost = { SnackbarHost(snackbarHostState) },
|
||||||
topBar = {
|
topBar = {
|
||||||
TopAppBar(
|
CenterAlignedTopAppBar(
|
||||||
title = {
|
title = {
|
||||||
Text(
|
Text(
|
||||||
text = "Scan QR",
|
text = "Scan a Nostr Address",
|
||||||
style = MaterialTheme.typography.titleMediumEmphasized
|
style = MaterialTheme.typography.titleMediumEmphasized
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -97,14 +96,6 @@ fun ScanScreen() {
|
|||||||
.align(Alignment.Center)
|
.align(Alignment.Center)
|
||||||
.border(2.dp, Color.White, RoundedCornerShape(12.dp))
|
.border(2.dp, Color.White, RoundedCornerShape(12.dp))
|
||||||
)
|
)
|
||||||
Text(
|
|
||||||
text = "Scan a Nostr address",
|
|
||||||
style = MaterialTheme.typography.titleSmallEmphasized,
|
|
||||||
color = Color.White,
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.BottomCenter)
|
|
||||||
.padding(bottom = 64.dp)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user