From 81ea442eac566ff967e43ad341e2cb18aa347b4a Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Tue, 9 Jun 2026 10:28:52 +0700 Subject: [PATCH] fix --- .../su/reya/coop/screens/ImportScreen.kt | 10 +++++----- .../su/reya/coop/screens/NewIdentityScreen.kt | 4 ++-- .../su/reya/coop/screens/OnboardingScreen.kt | 3 ++- .../reya/coop/screens/UpdateProfileScreen.kt | 2 +- .../kotlin/su/reya/coop/NostrViewModel.kt | 20 +++++++++---------- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/composeApp/src/androidMain/kotlin/su/reya/coop/screens/ImportScreen.kt b/composeApp/src/androidMain/kotlin/su/reya/coop/screens/ImportScreen.kt index 39ad654..336f727 100644 --- a/composeApp/src/androidMain/kotlin/su/reya/coop/screens/ImportScreen.kt +++ b/composeApp/src/androidMain/kotlin/su/reya/coop/screens/ImportScreen.kt @@ -78,7 +78,7 @@ fun ImportScreen() { val scope = rememberCoroutineScope() - val isLoggedIn by viewModel.isLoggedIn.collectAsStateWithLifecycle(false) + val isBusy by viewModel.isBusy.collectAsStateWithLifecycle(false) var secret by remember { mutableStateOf("") } var pubkey by remember { mutableStateOf(null) } @@ -90,7 +90,7 @@ fun ImportScreen() { val profile = metadata?.asRecord() val displayName = profile?.displayName ?: profile?.name ?: pubkey?.short() ?: "Unknown" val picture = profile?.picture - + LaunchedEffect(qrScanResult.content) { qrScanResult.content?.let { result -> runCatching { @@ -205,7 +205,7 @@ fun ImportScreen() { BasicTextField( value = secret, onValueChange = { secret = it }, - enabled = !isLoggedIn, + enabled = !isBusy, modifier = Modifier.fillMaxWidth(), maxLines = 4, keyboardOptions = KeyboardOptions( @@ -258,9 +258,9 @@ fun ImportScreen() { modifier = Modifier .fillMaxWidth() .height(ButtonDefaults.MediumContainerHeight), - enabled = secret.isNotBlank() && !isLoggedIn, + enabled = secret.isNotBlank() && !isBusy, ) { - if (isLoggedIn) { + if (isBusy) { LoadingIndicator() } else { Text( diff --git a/composeApp/src/androidMain/kotlin/su/reya/coop/screens/NewIdentityScreen.kt b/composeApp/src/androidMain/kotlin/su/reya/coop/screens/NewIdentityScreen.kt index f6cd375..216e402 100644 --- a/composeApp/src/androidMain/kotlin/su/reya/coop/screens/NewIdentityScreen.kt +++ b/composeApp/src/androidMain/kotlin/su/reya/coop/screens/NewIdentityScreen.kt @@ -15,12 +15,12 @@ fun NewIdentityScreen() { val viewModel = LocalNostrViewModel.current val navigator = LocalNavigator.current val scope = rememberCoroutineScope() - val isLoggedIn by viewModel.isLoggedIn.collectAsStateWithLifecycle(false) + val isBusy by viewModel.isBusy.collectAsStateWithLifecycle(false) ProfileEditor( title = "Create a new identity", buttonLabel = "Continue", - isBusy = isLoggedIn, + isBusy = isBusy, onBack = { navigator.goBack() }, onConfirm = { name, bio, bytes, type -> scope.launch { diff --git a/composeApp/src/androidMain/kotlin/su/reya/coop/screens/OnboardingScreen.kt b/composeApp/src/androidMain/kotlin/su/reya/coop/screens/OnboardingScreen.kt index 17845be..ca55709 100644 --- a/composeApp/src/androidMain/kotlin/su/reya/coop/screens/OnboardingScreen.kt +++ b/composeApp/src/androidMain/kotlin/su/reya/coop/screens/OnboardingScreen.kt @@ -160,9 +160,10 @@ fun OnboardingScreen() { if (viewModel.isExternalSignerAvailable()) { try { viewModel.connectExternalSigner() - navigator.navigate(Screen.Home) } catch (e: Exception) { e.message?.let { snackbarHostState.showSnackbar(it) } + } finally { + navigator.navigate(Screen.Home) } } else { val result = snackbarHostState.showSnackbar( diff --git a/composeApp/src/androidMain/kotlin/su/reya/coop/screens/UpdateProfileScreen.kt b/composeApp/src/androidMain/kotlin/su/reya/coop/screens/UpdateProfileScreen.kt index 5bf03ae..276fb4c 100644 --- a/composeApp/src/androidMain/kotlin/su/reya/coop/screens/UpdateProfileScreen.kt +++ b/composeApp/src/androidMain/kotlin/su/reya/coop/screens/UpdateProfileScreen.kt @@ -18,7 +18,7 @@ fun UpdateProfileScreen() { val currentUser = viewModel.currentUser() ?: return val metadata by viewModel.getMetadata(currentUser).collectAsState(initial = null) - val isBusy by viewModel.isLoggedIn.collectAsStateWithLifecycle(false) + val isBusy by viewModel.isBusy.collectAsStateWithLifecycle(false) val profile = metadata?.asRecord() diff --git a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt index f55652f..0c40fe3 100644 --- a/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt +++ b/shared/src/commonMain/kotlin/su/reya/coop/NostrViewModel.kt @@ -53,8 +53,8 @@ class NostrViewModel( private val _signerRequired = MutableStateFlow(null) val signerRequired = _signerRequired.asStateFlow() - private val _isLoggedIn = MutableStateFlow(false) - val isLoggedIn = _isLoggedIn.asStateFlow() + private val _isBusy = MutableStateFlow(false) + val isBusy = _isBusy.asStateFlow() private val _isPartialProcessedGiftWrap = MutableStateFlow(false) val isPartialProcessedGiftWrap = _isPartialProcessedGiftWrap.asStateFlow() @@ -407,7 +407,7 @@ class NostrViewModel( picture: ByteArray? = null, contentType: String? = null ) { - _isLoggedIn.value = true + _isBusy.value = true try { val avatarUrl = picture?.let { blossomUpload(it, contentType ?: "image/jpeg") } val newMetadata = nostr.updateProfile(name, bio, avatarUrl) @@ -416,7 +416,7 @@ class NostrViewModel( } catch (e: Exception) { showError("Error: ${e.message}") } finally { - _isLoggedIn.value = false + _isBusy.value = false } } @@ -426,7 +426,7 @@ class NostrViewModel( picture: ByteArray?, contentType: String? = null ) { - _isLoggedIn.value = true + _isBusy.value = true val keys = Keys.generate() val secret = keys.secretKey().toBech32() @@ -439,7 +439,7 @@ class NostrViewModel( showError("Error: ${e.message}") } finally { secretStore.set("user_signer", secret) - _isLoggedIn.value = false + _isBusy.value = false _signerRequired.value = false } } @@ -486,7 +486,7 @@ class NostrViewModel( } suspend fun importIdentity(secret: String) { - _isLoggedIn.value = true + _isBusy.value = true try { val signer = createSigner(secret) nostr.setSigner(signer) @@ -495,13 +495,13 @@ class NostrViewModel( } finally { secretStore.set("user_signer", secret) _signerRequired.value = false - _isLoggedIn.value = false + _isBusy.value = false } } suspend fun connectExternalSigner() { val handler = externalSignerHandler ?: throw IllegalStateException("Signer not available") - _isLoggedIn.value = true + _isBusy.value = true try { val permissions = SignerPermissions.toJson( listOf( @@ -524,7 +524,7 @@ class NostrViewModel( showError("Error: ${e.message}") } finally { _signerRequired.value = false - _isLoggedIn.value = false + _isBusy.value = false } }