fix: wallet screen showing "No wallet connected" on first open

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
This commit is contained in:
Claude
2026-03-14 14:30:38 +00:00
parent 120981f8c4
commit 2fd623a97d
2 changed files with 10 additions and 5 deletions
@@ -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,
@@ -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<Long?>(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