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:
+3
-4
@@ -73,10 +73,9 @@ fun WalletScreen(
|
|||||||
nav: INav,
|
nav: INav,
|
||||||
) {
|
) {
|
||||||
val walletViewModel: WalletViewModel = viewModel()
|
val walletViewModel: WalletViewModel = viewModel()
|
||||||
|
walletViewModel.init(accountViewModel.account)
|
||||||
|
|
||||||
LaunchedEffect(accountViewModel) {
|
val hasWallet by walletViewModel.hasWalletSetup.collectAsState()
|
||||||
walletViewModel.init(accountViewModel.account)
|
|
||||||
}
|
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
@@ -93,7 +92,7 @@ fun WalletScreen(
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
) { padding ->
|
) { padding ->
|
||||||
if (!walletViewModel.hasWalletSetup()) {
|
if (!hasWallet) {
|
||||||
NoWalletSetup(
|
NoWalletSetup(
|
||||||
modifier = Modifier.padding(padding),
|
modifier = Modifier.padding(padding),
|
||||||
nav = nav,
|
nav = nav,
|
||||||
|
|||||||
+7
-1
@@ -73,6 +73,9 @@ sealed class ReceiveState {
|
|||||||
class WalletViewModel : ViewModel() {
|
class WalletViewModel : ViewModel() {
|
||||||
private var account: Account? = null
|
private var account: Account? = null
|
||||||
|
|
||||||
|
private val _hasWalletSetup = MutableStateFlow(false)
|
||||||
|
val hasWalletSetup = _hasWalletSetup.asStateFlow()
|
||||||
|
|
||||||
private val _balanceSats = MutableStateFlow<Long?>(null)
|
private val _balanceSats = MutableStateFlow<Long?>(null)
|
||||||
val balanceSats = _balanceSats.asStateFlow()
|
val balanceSats = _balanceSats.asStateFlow()
|
||||||
|
|
||||||
@@ -96,9 +99,12 @@ class WalletViewModel : ViewModel() {
|
|||||||
|
|
||||||
fun init(account: Account) {
|
fun init(account: Account) {
|
||||||
this.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() {
|
fun fetchBalance() {
|
||||||
val acc = account ?: return
|
val acc = account ?: return
|
||||||
|
|||||||
Reference in New Issue
Block a user