From 2fd623a97d3c0f3bc2751f63e62c3c31933b4da4 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Mar 2026 14:30:38 +0000 Subject: [PATCH] fix: wallet screen showing "No wallet connected" on first open MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The WalletViewModel.init() was called inside LaunchedEffect (async), but hasWalletSetup() was checked synchronously during the first composition frame—before init had run. Moved init to run synchronously during composition and made hasWalletSetup a reactive StateFlow so the UI updates when wallet state changes. https://claude.ai/code/session_01JFogiwyR4CPVP8cRznqahJ --- .../amethyst/ui/screen/loggedIn/wallet/WalletScreen.kt | 7 +++---- .../amethyst/ui/screen/loggedIn/wallet/WalletViewModel.kt | 8 +++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/wallet/WalletScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/wallet/WalletScreen.kt index ef0d94800..8ef787815 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/wallet/WalletScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/wallet/WalletScreen.kt @@ -73,10 +73,9 @@ fun WalletScreen( nav: INav, ) { val walletViewModel: WalletViewModel = viewModel() + walletViewModel.init(accountViewModel.account) - LaunchedEffect(accountViewModel) { - walletViewModel.init(accountViewModel.account) - } + val hasWallet by walletViewModel.hasWalletSetup.collectAsState() Scaffold( topBar = { @@ -93,7 +92,7 @@ fun WalletScreen( ) }, ) { padding -> - if (!walletViewModel.hasWalletSetup()) { + if (!hasWallet) { NoWalletSetup( modifier = Modifier.padding(padding), nav = nav, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/wallet/WalletViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/wallet/WalletViewModel.kt index 69a584025..ff670665d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/wallet/WalletViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/wallet/WalletViewModel.kt @@ -73,6 +73,9 @@ sealed class ReceiveState { class WalletViewModel : ViewModel() { private var account: Account? = null + private val _hasWalletSetup = MutableStateFlow(false) + val hasWalletSetup = _hasWalletSetup.asStateFlow() + private val _balanceSats = MutableStateFlow(null) val balanceSats = _balanceSats.asStateFlow() @@ -96,9 +99,12 @@ class WalletViewModel : ViewModel() { fun init(account: Account) { this.account = account + _hasWalletSetup.value = account.nip47SignerState?.hasWalletConnectSetup() == true } - fun hasWalletSetup(): Boolean = account?.nip47SignerState?.hasWalletConnectSetup() == true + fun refreshWalletSetup() { + _hasWalletSetup.value = account?.nip47SignerState?.hasWalletConnectSetup() == true + } fun fetchBalance() { val acc = account ?: return