From 3f5de5887cbc1590bef2e5d1b066dfedb2d6040d Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Sat, 24 Oct 2026 13:16:29 +0200 Subject: [PATCH] refactor(wallet): every profile can watch, so the cannot-watch branches go (Phase 3) The wallets are non-null wherever a screen is reached with an identity, and with them go GroupWalletAddressesUIState.CannotWatch, the CANNOT_WATCH refusal, canWatch on both wallet states and the new-member-wallet view model, and the two strings that explained it. An nsec profile can now ask for a member wallet. The profile screen keeps a nullable wallets, for previews and tests. Co-Authored-By: Claude Opus 5.5 --- .../composeResources/values/strings.xml | 2 -- .../compose/managers/MemberWalletManager.kt | 3 --- .../ui/composable/ActiveProfileScreen.kt | 4 ++-- .../compose/ui/composable/GroupSendScreen.kt | 2 +- .../composable/GroupWalletAddressesScreen.kt | 13 +--------- .../ui/composable/GroupWalletScreen.kt | 17 ++++--------- .../compose/ui/composable/MemberSendScreen.kt | 2 +- .../ui/composable/MemberWalletScreen.kt | 13 ++-------- .../ui/composable/NewMemberWalletScreen.kt | 4 ---- .../ui/composable/navigation/BennuNavHost.kt | 18 +++++++++----- .../ui/view/model/GroupSendViewModel.kt | 6 ++--- .../model/GroupWalletAddressesViewModel.kt | 8 ++----- .../ui/view/model/GroupWalletViewModel.kt | 20 ++++++---------- .../ui/view/model/MemberSendViewModel.kt | 7 +++--- .../ui/view/model/MemberWalletViewModel.kt | 9 ++++--- .../ui/view/model/MemberWalletsViewModel.kt | 4 ++-- .../ui/view/model/NewMemberWalletViewModel.kt | 8 +------ .../view/state/GroupWalletAddressesUIState.kt | 6 ----- .../ui/view/state/GroupWalletUIState.kt | 5 +--- .../ui/view/state/MemberWalletUIState.kt | 4 +--- .../ui/composable/GroupSendScreenJvmTest.kt | 7 +++++- .../ui/composable/GuardedWalletCardJvmTest.kt | 8 +++++-- .../view/model/GroupSendViewModelJvmTest.kt | 24 ++++++++++++++----- .../GroupWalletAddressesViewModelJvmTest.kt | 12 ++-------- .../view/model/GroupWalletViewModelJvmTest.kt | 19 +++++++++++---- .../model/NewMemberWalletViewModelJvmTest.kt | 2 +- 26 files changed, 94 insertions(+), 133 deletions(-) diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml index 586f6b55..141c0383 100644 --- a/composeApp/src/commonMain/composeResources/values/strings.xml +++ b/composeApp/src/commonMain/composeResources/values/strings.xml @@ -506,7 +506,6 @@ Address %1$s was just paid Finding the group's coins… Nothing has been sent to this wallet yet. - This profile has no wallet of its own to watch the chain with, so the balance and the next address can't be shown here. Coins Change Received @@ -638,7 +637,6 @@ Asked. A member who holds the group's key will answer when their device next reads the room. This group's guardian keys can't be read by this version of the app. Guarded wallets for members aren't offered on this network yet. - This profile has no wallet of its own to watch the chain with, so it couldn't see its own coins. %1$s would refuse this request: it was asked before the group said it guards members' wallets. Asking again makes a new one. %1$s has changed its delay since you asked. Asking again makes a new request at the new delay. %1$s has stopped guarding members' wallets, so this request won't be signed. You can discard it. diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/MemberWalletManager.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/MemberWalletManager.kt index bbb4de52..632be5c3 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/MemberWalletManager.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/MemberWalletManager.kt @@ -153,9 +153,6 @@ object MemberWalletManager { /** Member wallets are not offered on this network yet: `GroupWalletRollout.offersMemberWalletsOn`. */ NOT_ON_THIS_NETWORK, - /** The profile has no Electrum client, so it could not see its own coins. Read by the screen, not here. */ - CANNOT_WATCH, - /** * The group has not said it guards members' wallets: no policy, as far as * this device knows. `docs/member-wallet-delay.md`, D8. diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ActiveProfileScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ActiveProfileScreen.kt index 6c153fa9..59ea8af4 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ActiveProfileScreen.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ActiveProfileScreen.kt @@ -105,8 +105,8 @@ fun ActiveProfileScreen( // pending route for every kind. signOut: SignOutDependencies? = null, // The member's guarded wallets (docs/member-guarded-wallets.md). The no-op - // repository lists none, for previews and tests; null wallets is a profile - // that cannot watch the chain, whose rows show no balance. + // repository lists none, and null wallets watch nothing: both for previews + // and tests, which compose the screen without an identity. memberWalletRepository: MemberWalletRepository = MemberWalletRepository.NO_OP, wallets: GroupOnchainWallets? = null, ) { diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupSendScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupSendScreen.kt index c8d69d99..6b01498f 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupSendScreen.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupSendScreen.kt @@ -133,7 +133,7 @@ fun GroupSendScreen( initialGroupSendUIState: GroupSendUIState = GroupSendUIState.Loading, chatRepository: ChatRepository, frostSigningRepository: FrostSigningRepository, - wallets: GroupOnchainWallets?, + wallets: GroupOnchainWallets, guardedChatRoomId: String? = null, fundChatRoomId: String? = null, onNavigateToRouteAndPopUpInclusive: (Route) -> Unit, diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupWalletAddressesScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupWalletAddressesScreen.kt index 32ad5341..78ace7c5 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupWalletAddressesScreen.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupWalletAddressesScreen.kt @@ -13,7 +13,6 @@ import androidx.compose.foundation.lazy.items import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ContentCopy -import androidx.compose.material.icons.filled.Visibility import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton @@ -51,11 +50,9 @@ import bennu.composeapp.generated.resources.not_used_yet import bennu.composeapp.generated.resources.paid_s_sats import bennu.composeapp.generated.resources.paid_spent_since import bennu.composeapp.generated.resources.show_as_a_qr_code -import bennu.composeapp.generated.resources.this_profile_cannot_watch_the_chain import com.machankura.bennu.compose.repository.ChatRepository import com.machankura.bennu.compose.text.grouped import com.machankura.bennu.compose.ui.composable.widgets.Decorative -import com.machankura.bennu.compose.ui.composable.widgets.EmptyState import com.machankura.bennu.compose.ui.composable.widgets.ErrorState import com.machankura.bennu.compose.ui.composable.widgets.LoadingDataIndicator import com.machankura.bennu.compose.ui.composable.widgets.LocalSnackbarHostState @@ -97,7 +94,7 @@ fun GroupWalletAddressesScreen( chain: Chain, initialUIState: GroupWalletAddressesUIState = GroupWalletAddressesUIState.Loading, chatRepository: ChatRepository, - wallets: GroupOnchainWallets?, + wallets: GroupOnchainWallets, onNavigateBack: () -> Unit, ) { val addressesViewModel: GroupWalletAddressesViewModel = viewModel( @@ -148,14 +145,6 @@ fun GroupWalletAddressesScreen( LoadingDataIndicator(modifier = Modifier.fillMaxWidth().padding(padding)) } - GroupWalletAddressesUIState.CannotWatch -> { - EmptyState( - modifier = Modifier.padding(padding).readableContent(), - message = stringResource(Res.string.this_profile_cannot_watch_the_chain), - icon = Icons.Default.Visibility, - ) - } - is GroupWalletAddressesUIState.Loaded -> { val receive = state.receive if (receive == null) { diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupWalletScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupWalletScreen.kt index 87101dbb..253a4a9f 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupWalletScreen.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupWalletScreen.kt @@ -139,7 +139,6 @@ import bennu.composeapp.generated.resources.s_dot_s import bennu.composeapp.generated.resources.s_sats import bennu.composeapp.generated.resources.s_sats_on_the_way import bennu.composeapp.generated.resources.this_group_has_not_opened_a_wallet -import bennu.composeapp.generated.resources.this_profile_cannot_watch_the_chain import bennu.composeapp.generated.resources.waiting_for_a_confirmation import bennu.composeapp.generated.resources.watch_only_descriptors_copied import com.machankura.bennu.compose.managers.GroupWalletDerivation @@ -190,7 +189,7 @@ fun GroupWalletScreen( initialGroupWalletUIState: GroupWalletUIState = GroupWalletUIState.Loading, chatRepository: ChatRepository, frostSigningRepository: FrostSigningRepository, - wallets: GroupOnchainWallets?, + wallets: GroupOnchainWallets, watcher: GroupTransactionWatcher? = null, onNavigateToRoute: (Route) -> Unit, onNavigateBack: () -> Unit, @@ -367,7 +366,7 @@ fun GroupWalletScreen( notify = notify, // Behind both gates: a share to propose with, and a node to // see the coins with -- a spend built blind is not one. - onSend = if (state.canSign && state.canWatch) { + onSend = if (state.canSign) { { onNavigateToRoute( GroupSendRoute( @@ -397,8 +396,8 @@ fun GroupWalletScreen( } else null, isPending = groupWalletViewModel.isActionPending.value, onShare = onShare, - onSpend = if (state.canSign && state.canWatch) toGuardianSpend else null, - onFund = if (state.canSign && state.canWatch) toGuardianFund else null, + onSpend = if (state.canSign) toGuardianSpend else null, + onFund = if (state.canSign) toGuardianFund else null, onOpenPerson = toPerson, ) } @@ -539,14 +538,6 @@ private fun OpenWallet( } when { - !state.canWatch -> item { - Text( - text = stringResource(Res.string.this_profile_cannot_watch_the_chain), - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - } - walletState?.receiveAddress == null -> item { LoadingDataIndicator( fillScreen = false, diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/MemberSendScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/MemberSendScreen.kt index d45bdd7c..36c2fab8 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/MemberSendScreen.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/MemberSendScreen.kt @@ -66,7 +66,7 @@ fun MemberSendScreen( chain: Chain, initialUIState: MemberSendUIState = MemberSendUIState.Loading, memberWalletRepository: MemberWalletRepository, - wallets: GroupOnchainWallets?, + wallets: GroupOnchainWallets, onNavigateBack: () -> Unit, ) { val viewModel: MemberSendViewModel = viewModel( diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/MemberWalletScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/MemberWalletScreen.kt index 58bb4f6a..9108a61f 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/MemberWalletScreen.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/MemberWalletScreen.kt @@ -78,7 +78,6 @@ import bennu.composeapp.generated.resources.s_took_s_sats_in_s import bennu.composeapp.generated.resources.show_key import bennu.composeapp.generated.resources.taken_by_guardians import bennu.composeapp.generated.resources.the_key_of_this_wallet_is_on_another_device -import bennu.composeapp.generated.resources.this_profile_cannot_watch_its_own_coins import bennu.composeapp.generated.resources.waiting_for_someone_in_s_to_put_it_to_the_group import bennu.composeapp.generated.resources.whoever_holds_these_descriptors_holds_the_coins import bennu.composeapp.generated.resources.you_re_no_longer_in_s @@ -123,7 +122,7 @@ fun MemberWalletScreen( walletId: String, initialUIState: MemberWalletUIState = MemberWalletUIState.Loading, memberWalletRepository: MemberWalletRepository, - wallets: GroupOnchainWallets?, + wallets: GroupOnchainWallets, /** The send form for this wallet, or null where there is none to offer. */ onSend: ((walletId: String) -> Unit)? = null, onNavigateBack: () -> Unit, @@ -254,19 +253,11 @@ fun MemberWalletScreen( } } - onSend?.takeIf { wallet.state == WalletState.OPEN && state.canWatch }?.let { send -> + onSend?.takeIf { wallet.state == WalletState.OPEN }?.let { send -> item { SendButton(onClick = { send(wallet.walletId) }) } } when { - !state.canWatch -> item { - Text( - stringResource(Res.string.this_profile_cannot_watch_its_own_coins), - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - } - walletState?.receiveAddress == null -> item { LoadingDataIndicator(fillScreen = false, text = stringResource(Res.string.finding_your_coins)) } diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/NewMemberWalletScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/NewMemberWalletScreen.kt index be392384..133814d3 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/NewMemberWalletScreen.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/NewMemberWalletScreen.kt @@ -55,7 +55,6 @@ import bennu.composeapp.generated.resources.s_can_take_any_coin_without_asking_y import bennu.composeapp.generated.resources.this_device_does_not_know_what_this_group_signs_with import bennu.composeapp.generated.resources.this_group_s_guardian_keys_can_t_be_read_to_guard_a_wallet import bennu.composeapp.generated.resources.this_profile_cannot_sign_a_request -import bennu.composeapp.generated.resources.this_profile_cannot_watch_its_own_coins import bennu.composeapp.generated.resources.none_of_your_groups_guards_members_wallets_yet import com.machankura.bennu.compose.managers.MemberWalletManager import com.machankura.bennu.compose.repository.MemberWalletRepository @@ -90,7 +89,6 @@ fun NewMemberWalletScreen( activeUserPublicKey: HexKey, chatRoomId: String?, chain: Chain, - canWatch: Boolean, initialUIState: NewMemberWalletUIState = NewMemberWalletUIState.Loading, memberWalletRepository: MemberWalletRepository, onNavigateBack: () -> Unit, @@ -100,7 +98,6 @@ fun NewMemberWalletScreen( activeUserPublicKey = activeUserPublicKey, chatRoomId = chatRoomId, chain = chain, - canWatch = canWatch, initialUIState = initialUIState, memberWalletRepository = memberWalletRepository, ) @@ -245,7 +242,6 @@ private fun refusalText(refusal: MemberWalletManager.Refusal): String = stringRe MemberWalletManager.Refusal.KEY_UNKNOWN -> Res.string.this_device_does_not_know_what_this_group_signs_with MemberWalletManager.Refusal.GUARDIANS_UNREADABLE -> Res.string.this_group_s_guardian_keys_can_t_be_read_to_guard_a_wallet MemberWalletManager.Refusal.NOT_ON_THIS_NETWORK -> Res.string.member_wallets_are_not_offered_on_this_network - MemberWalletManager.Refusal.CANNOT_WATCH -> Res.string.this_profile_cannot_watch_its_own_coins MemberWalletManager.Refusal.NOT_OFFERED -> Res.string.this_group_doesn_t_guard_members_wallets MemberWalletManager.Refusal.CLOSED -> Res.string.this_group_has_stopped_guarding_members_wallets } diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/BennuNavHost.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/BennuNavHost.kt index 0fba90df..ea659322 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/BennuNavHost.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/navigation/BennuNavHost.kt @@ -1160,6 +1160,9 @@ fun BennuNavHost( } composable { backStackEntry -> val route = backStackEntry.toRoute() + // Null only with no identity, for the frame between a profile + // switch and the startup screen: there is no chain to show yet. + val wallets = groupOnchainWallets ?: return@composable GroupWalletScreen( activeUserPublicKey = route.activeUserPublicKey, @@ -1167,7 +1170,7 @@ fun BennuNavHost( chain = NodeParamsManager.chain, chatRepository = databaseChatRepository, frostSigningRepository = databaseFrostSigningRepository, - wallets = groupOnchainWallets, + wallets = wallets, watcher = groupTransactionWatcher, onNavigateToRoute = { actionRoute -> navController.navigate(route = actionRoute) @@ -1179,12 +1182,13 @@ fun BennuNavHost( } composable { backStackEntry -> val route = backStackEntry.toRoute() + val wallets = groupOnchainWallets ?: return@composable MemberWalletScreen( activeUserPublicKey = route.activeUserPublicKey, walletId = route.walletId, memberWalletRepository = databaseMemberWalletRepository, - wallets = groupOnchainWallets, + wallets = wallets, onSend = { walletId -> navController.navigate(route = MemberSendRoute(activeUserPublicKey = route.activeUserPublicKey, walletId = walletId)) }, @@ -1195,13 +1199,14 @@ fun BennuNavHost( } composable { backStackEntry -> val route = backStackEntry.toRoute() + val wallets = groupOnchainWallets ?: return@composable MemberSendScreen( activeUserPublicKey = route.activeUserPublicKey, walletId = route.walletId, chain = NodeParamsManager.chain, memberWalletRepository = databaseMemberWalletRepository, - wallets = groupOnchainWallets, + wallets = wallets, onNavigateBack = { navController.popBackStack() } @@ -1231,7 +1236,6 @@ fun BennuNavHost( activeUserPublicKey = route.activeUserPublicKey, chatRoomId = route.chatRoomId, chain = NodeParamsManager.chain, - canWatch = groupOnchainWallets != null, memberWalletRepository = databaseMemberWalletRepository, onNavigateBack = { navController.popBackStack() @@ -1240,12 +1244,13 @@ fun BennuNavHost( } composable { backStackEntry -> val route = backStackEntry.toRoute() + val wallets = groupOnchainWallets ?: return@composable GroupWalletAddressesScreen( chatRoomId = route.chatRoomId, chain = NodeParamsManager.chain, chatRepository = databaseChatRepository, - wallets = groupOnchainWallets, + wallets = wallets, onNavigateBack = { navController.popBackStack() } @@ -1253,6 +1258,7 @@ fun BennuNavHost( } composable { backStackEntry -> val route = backStackEntry.toRoute() + val wallets = groupOnchainWallets ?: return@composable GroupSendScreen( activeUserPublicKey = route.activeUserPublicKey, @@ -1260,7 +1266,7 @@ fun BennuNavHost( chain = NodeParamsManager.chain, chatRepository = databaseChatRepository, frostSigningRepository = databaseFrostSigningRepository, - wallets = groupOnchainWallets, + wallets = wallets, guardedChatRoomId = route.guardedChatRoomId, fundChatRoomId = route.fundChatRoomId, onNavigateToRouteAndPopUpInclusive = { signingRoute -> diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupSendViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupSendViewModel.kt index 65c2b098..5768a52a 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupSendViewModel.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupSendViewModel.kt @@ -53,7 +53,7 @@ class GroupSendViewModel( initialGroupSendUIState: GroupSendUIState, val chatRepository: ChatRepository, val frostSigningRepository: FrostSigningRepository, - private val wallets: GroupOnchainWallets?, + private val wallets: GroupOnchainWallets, /** The descendant whose guarded wallet this form spends from, or null for the room's own. */ val guardedChatRoomId: String? = null, /** The descendant whose guarded wallet this form pays, or null for a payment to a typed address. */ @@ -103,7 +103,7 @@ class GroupSendViewModel( else -> GroupWallet(GroupSignedEvent.fromEvent(guarded.statement, chatRoomId = guarded.descendantChatRoomId), guarded.account) } val canSign = localChatRoom.chatRoom.mlsGroupState != null && chatRepository.canSign(chatRoomId) - if (wallet == null || !canSign || wallets == null || (fundChatRoomId != null && funded == null)) { + if (wallet == null || !canSign || (fundChatRoomId != null && funded == null)) { groupSendUIState = GroupSendUIState.Unavailable return@launch } @@ -284,7 +284,7 @@ class GroupSendViewModel( initialGroupSendUIState: GroupSendUIState = GroupSendUIState.Loading, chatRepository: ChatRepository, frostSigningRepository: FrostSigningRepository, - wallets: GroupOnchainWallets?, + wallets: GroupOnchainWallets, guardedChatRoomId: String? = null, fundChatRoomId: String? = null, ): ViewModelProvider.Factory = viewModelFactory { diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletAddressesViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletAddressesViewModel.kt index b40ce5e3..50d49331 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletAddressesViewModel.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletAddressesViewModel.kt @@ -29,7 +29,7 @@ class GroupWalletAddressesViewModel( val chain: Chain, initialUIState: GroupWalletAddressesUIState, val chatRepository: ChatRepository, - private val wallets: GroupOnchainWallets?, + private val wallets: GroupOnchainWallets, ): ViewModel() { var uiState: GroupWalletAddressesUIState by mutableStateOf(initialUIState) private set @@ -62,10 +62,6 @@ class GroupWalletAddressesViewModel( uiState = GroupWalletAddressesUIState.Error("This group has not opened a wallet") return@launch } - if (wallets == null) { - uiState = GroupWalletAddressesUIState.CannotWatch - return@launch - } uiState = GroupWalletAddressesUIState.Loaded(receive = null) wallets.walletFor(wallet.account).state.collect { state -> @@ -91,7 +87,7 @@ class GroupWalletAddressesViewModel( chain: Chain, initialUIState: GroupWalletAddressesUIState = GroupWalletAddressesUIState.Loading, chatRepository: ChatRepository, - wallets: GroupOnchainWallets?, + wallets: GroupOnchainWallets, ): ViewModelProvider.Factory = viewModelFactory { initializer { GroupWalletAddressesViewModel( diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletViewModel.kt index 9e6fabfe..218234e9 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletViewModel.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletViewModel.kt @@ -48,8 +48,8 @@ import kotlinx.coroutines.withContext * coins are a watch, because a payment arriving while the screen is open is the * one moment somebody is looking at it. * - * [wallets] is null for a profile with no node of its own -- an nsec or an npub - * -- which can see that the group keeps a wallet, and cannot see the chain. + * [wallets] watch on the identity's Electrum client: its node's, or for an nsec + * or npub profile one of its own (docs/standalone-electrum.md). */ class GroupWalletViewModel( val activeUserPublicKey: HexKey, @@ -58,7 +58,7 @@ class GroupWalletViewModel( initialGroupWalletUIState: GroupWalletUIState, val chatRepository: ChatRepository, val frostSigningRepository: FrostSigningRepository, - private val wallets: GroupOnchainWallets?, + private val wallets: GroupOnchainWallets, private val watcher: GroupTransactionWatcher? = null, ): ViewModel() { private val logger = Logger.withTag(TAG) @@ -121,7 +121,6 @@ class GroupWalletViewModel( localChatRoom = localChatRoom, wallet = wallet, walletState = null, - canWatch = wallets != null, canSign = canSign, guardedWallets = guardedRows, shareable = shareable, @@ -132,7 +131,7 @@ class GroupWalletViewModel( // The chain, the room's spends and the wallets it guards, as one // state: any of them changing redraws the screen, and none may // overwrite another. - val chainState = wallets?.walletFor(wallet.account)?.state ?: flowOf(null) + val chainState = wallets.walletFor(wallet.account).state noticeGuardianSpends(wallet.account) watching = viewModelScope.launch(Dispatchers.IO) { combine( @@ -148,10 +147,6 @@ class GroupWalletViewModel( } } - /** - * Each guarded wallet with what the chain says of it, on the identity's own - * Electrum client -- or with nothing, for a profile that cannot watch. - */ /** * What this device calls each of [guardians]' rooms, for the ones it holds: * the wallet screen lists each guardian with its own delay, and a room id is @@ -163,9 +158,9 @@ class GroupWalletViewModel( chatRepository.getChatRoomByIdentifier(guardian.chatRoomId)?.chatRoom?.subject?.let { guardian.chatRoomId to it } }.toMap() + /** Each guarded wallet with what the chain says of it, on the identity's Electrum client. */ private suspend fun guardedStates(guarded: List): Flow> { - val wallets = wallets - if (wallets == null || guarded.isEmpty()) return flowOf(guarded.map { GuardedWalletRow(it, walletState = null) }) + if (guarded.isEmpty()) return flowOf(emptyList()) val states = guarded.map { wallet -> wallets.walletFor(wallet.account).state.map { GuardedWalletRow(wallet, it) } } return combine(states) { it.toList() } @@ -179,7 +174,6 @@ class GroupWalletViewModel( * has none -- the group's only notice, since nobody in it signed them. */ private suspend fun noticeGuardianSpends(account: GroupWalletDerivation.Account) { - val wallets = wallets ?: return if (!account.isGuarded) return val onchain = wallets.walletFor(account) @@ -329,7 +323,7 @@ class GroupWalletViewModel( initialGroupWalletUIState: GroupWalletUIState = GroupWalletUIState.Loading, chatRepository: ChatRepository, frostSigningRepository: FrostSigningRepository, - wallets: GroupOnchainWallets?, + wallets: GroupOnchainWallets, watcher: GroupTransactionWatcher? = null, ): ViewModelProvider.Factory = viewModelFactory { initializer { diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/MemberSendViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/MemberSendViewModel.kt index 751e64b9..109c603a 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/MemberSendViewModel.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/MemberSendViewModel.kt @@ -47,7 +47,7 @@ class MemberSendViewModel( val chain: Chain, initialUIState: MemberSendUIState, private val memberWalletRepository: MemberWalletRepository, - private val wallets: GroupOnchainWallets?, + private val wallets: GroupOnchainWallets, ) : ViewModel() { private val logger = Logger.withTag(TAG) @@ -70,7 +70,7 @@ class MemberSendViewModel( uiState = MemberSendUIState.Error("Couldn't find this wallet") return@launch } - if (wallet.state != MemberWalletManager.WalletState.OPEN || wallets == null) { + if (wallet.state != MemberWalletManager.WalletState.OPEN) { uiState = MemberSendUIState.Unavailable return@launch } @@ -151,7 +151,6 @@ class MemberSendViewModel( /** Signs what the form describes and hands it to Electrum. [onSent] when it went, [onFailure] when it did not. */ fun send(onSent: () -> Unit, onFailure: () -> Unit) { val built = preview() as? GroupSpendBuilder.Result.Built ?: return - val wallets = wallets ?: return if (isActionPending.value) return isActionPending.value = true @@ -178,7 +177,7 @@ class MemberSendViewModel( chain: Chain, initialUIState: MemberSendUIState = MemberSendUIState.Loading, memberWalletRepository: MemberWalletRepository, - wallets: GroupOnchainWallets?, + wallets: GroupOnchainWallets, ): ViewModelProvider.Factory = viewModelFactory { initializer { MemberSendViewModel(ownerPublicKey, walletId, chain, initialUIState, memberWalletRepository, wallets) } } diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/MemberWalletViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/MemberWalletViewModel.kt index dbf2b8c0..89c55956 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/MemberWalletViewModel.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/MemberWalletViewModel.kt @@ -38,7 +38,7 @@ class MemberWalletViewModel( walletId: String, initialUIState: MemberWalletUIState, private val memberWalletRepository: MemberWalletRepository, - private val wallets: GroupOnchainWallets?, + private val wallets: GroupOnchainWallets, ) : ViewModel() { private val logger = Logger.withTag(TAG) @@ -68,11 +68,11 @@ class MemberWalletViewModel( uiState = MemberWalletUIState.Error("Couldn't find this wallet") return@launch } - val loaded = MemberWalletUIState.Loaded(wallet = wallet, canWatch = wallets != null) + val loaded = MemberWalletUIState.Loaded(wallet = wallet) uiState = loaded watching?.cancel() - if (!wallet.isCertified || wallets == null) return@launch + if (!wallet.isCertified) return@launch watching = viewModelScope.launch(Dispatchers.IO) { var taken = emptyList() combine( @@ -103,7 +103,6 @@ class MemberWalletViewModel( * record for the next one that does. */ private suspend fun follow(spends: List) { - val wallets = wallets ?: return spends.filter { it.confirmedAt == null && it.replacedByTxid == null }.forEach { spend -> val tx = runCatching { Transaction.read(spend.signedTransaction) }.getOrNull() ?: return@forEach val confirmations = wallets.confirmationsOf(tx) @@ -151,7 +150,7 @@ class MemberWalletViewModel( walletId: String, initialUIState: MemberWalletUIState = MemberWalletUIState.Loading, memberWalletRepository: MemberWalletRepository, - wallets: GroupOnchainWallets?, + wallets: GroupOnchainWallets, ): ViewModelProvider.Factory = viewModelFactory { initializer { MemberWalletViewModel(ownerPublicKey, walletId, initialUIState, memberWalletRepository, wallets) } } diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/MemberWalletsViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/MemberWalletsViewModel.kt index a6d97d86..ab169281 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/MemberWalletsViewModel.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/MemberWalletsViewModel.kt @@ -21,8 +21,8 @@ import kotlinx.coroutines.launch /** * A member's guarded wallets, as their profile lists them: each one's state, - * and -- for the ones a group has certified, on a profile that can watch the - * chain -- its balance. + * and -- for the ones a group has certified -- its balance. [wallets] is null + * only where the profile is composed without an identity: previews and tests. */ class MemberWalletsViewModel( private val ownerPublicKey: HexKey, diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/NewMemberWalletViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/NewMemberWalletViewModel.kt index b84d07b8..c902c4dc 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/NewMemberWalletViewModel.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/NewMemberWalletViewModel.kt @@ -27,15 +27,11 @@ import kotlinx.coroutines.withContext * the button is drawn and again inside `MemberWalletManager.request`, the way * the subgroup picker refuses: the screen keeps a member out of a dead end, the * manager keeps a bug out of the room. - * - * [canWatch] is whether this profile has an Electrum client: one without could - * not see its own coins, so it is not offered a wallet it cannot see (D3). */ class NewMemberWalletViewModel( val activeUserPublicKey: HexKey, private val chatRoomId: String?, private val chain: Chain, - private val canWatch: Boolean, initialUIState: NewMemberWalletUIState, private val memberWalletRepository: MemberWalletRepository, ) : ViewModel() { @@ -84,7 +80,6 @@ class NewMemberWalletViewModel( private suspend fun refusal(chatRoomId: String): MemberWalletManager.Refusal? = memberWalletRepository.refusal(chatRoomId, chain) - ?: if (!canWatch) MemberWalletManager.Refusal.CANNOT_WATCH else null fun askForGroupKey() { val chosen = uiState as? NewMemberWalletUIState.Chosen ?: return @@ -127,12 +122,11 @@ class NewMemberWalletViewModel( activeUserPublicKey: HexKey, chatRoomId: String?, chain: Chain, - canWatch: Boolean, initialUIState: NewMemberWalletUIState = NewMemberWalletUIState.Loading, memberWalletRepository: MemberWalletRepository, ): ViewModelProvider.Factory = viewModelFactory { initializer { - NewMemberWalletViewModel(activeUserPublicKey, chatRoomId, chain, canWatch, initialUIState, memberWalletRepository) + NewMemberWalletViewModel(activeUserPublicKey, chatRoomId, chain, initialUIState, memberWalletRepository) } } } diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/GroupWalletAddressesUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/GroupWalletAddressesUIState.kt index e175f29c..42b9445e 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/GroupWalletAddressesUIState.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/GroupWalletAddressesUIState.kt @@ -16,12 +16,6 @@ sealed interface GroupWalletAddressesUIState { val change: List = emptyList(), ): GroupWalletAddressesUIState - /** - * A profile with no node of its own -- an nsec or an npub -- which knows the - * group keeps a wallet and cannot see which of its addresses are used. - */ - data object CannotWatch: GroupWalletAddressesUIState - data class Error( val message: String ): GroupWalletAddressesUIState diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/GroupWalletUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/GroupWalletUIState.kt index b6b227b2..f3ccab3f 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/GroupWalletUIState.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/GroupWalletUIState.kt @@ -51,15 +51,12 @@ sealed interface GroupWalletUIState { /** * An open wallet. * - * [walletState] is null in two different situations, told apart by - * [canWatch]: before Electrum's first answer, and for a profile with no node - * to watch the chain with at all. + * [walletState] is null before Electrum's first answer. */ data class Loaded( val localChatRoom: LocalChatRoom, val wallet: GroupWallet, val walletState: GroupWalletState?, - val canWatch: Boolean, val canSign: Boolean, /** The room's spends, newest first. */ val spends: List = emptyList(), diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/MemberWalletUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/MemberWalletUIState.kt index ea2ddb31..94df027b 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/MemberWalletUIState.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/MemberWalletUIState.kt @@ -12,10 +12,8 @@ sealed interface MemberWalletUIState { data class Loaded( val wallet: MemberWalletManager.MemberWalletRow, - /** Null before Electrum's first answer, for a wallet no group has certified, and for a profile that cannot watch the chain. */ + /** Null before Electrum's first answer, and for a wallet no group has certified. */ val walletState: GroupWalletState? = null, - /** Whether this profile has an Electrum client to watch the chain with. */ - val canWatch: Boolean, /** What the wallet's guardians took from it, read off the chain: never stored, found again on each look. */ val taken: List = emptyList(), /** The spends the member signed from it, newest first. */ diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/composable/GroupSendScreenJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/composable/GroupSendScreenJvmTest.kt index d6c1de2c..2692d023 100644 --- a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/composable/GroupSendScreenJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/composable/GroupSendScreenJvmTest.kt @@ -1,5 +1,9 @@ package com.machankura.bennu.compose.ui.composable +import com.machankura.bennu.compose.wallet.GroupOnchainWallets +import com.machankura.bennu.compose.wallet.FakeElectrum +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.CoroutineScope import com.machankura.bennu.compose.managers.GuardianDerivation import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize @@ -200,7 +204,8 @@ class GroupSendScreenJvmTest { initialGroupSendUIState = ready(chain).let { if (funded) it.copy(funding = funding(chain)) else it }, chatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY, frostSigningRepository = FrostSigningRepository.NO_OP_FROST_SIGNING_REPOSITORY, - wallets = null, + // Never asked: the state is given, so nothing is watched. + wallets = GroupOnchainWallets(FakeElectrum(), CoroutineScope(SupervisorJob())), onNavigateToRouteAndPopUpInclusive = {}, onNavigateBack = {}, ) diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/composable/GuardedWalletCardJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/composable/GuardedWalletCardJvmTest.kt index 3a71f282..550613b3 100644 --- a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/composable/GuardedWalletCardJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/composable/GuardedWalletCardJvmTest.kt @@ -1,5 +1,9 @@ package com.machankura.bennu.compose.ui.composable +import com.machankura.bennu.compose.wallet.GroupOnchainWallets +import com.machankura.bennu.compose.wallet.FakeElectrum +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.CoroutineScope import com.machankura.bennu.compose.managers.GuardianDerivation import com.machankura.bennu.compose.managers.LineageExample import com.machankura.bennu.compose.managers.LineageExample.heldBy @@ -110,7 +114,6 @@ class GuardedWalletCardJvmTest { localChatRoom = room, wallet = wallet, walletState = holding(own, 100_000, height = 100, tip = 200), - canWatch = true, canSign = true, guardedWallets = listOf(GuardedWalletRow(guarded, holding(descendant, 50_000, height = 0, tip = 200))), ) @@ -130,7 +133,8 @@ class GuardedWalletCardJvmTest { initialGroupWalletUIState = state, chatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY, frostSigningRepository = FrostSigningRepository.NO_OP_FROST_SIGNING_REPOSITORY, - wallets = null, + // Never asked: the state is given, so nothing is watched. + wallets = GroupOnchainWallets(FakeElectrum(), CoroutineScope(SupervisorJob())), onNavigateToRoute = onRoute, onNavigateBack = {}, ) diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupSendViewModelJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupSendViewModelJvmTest.kt index bd9cc020..0f957a28 100644 --- a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupSendViewModelJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupSendViewModelJvmTest.kt @@ -1,5 +1,10 @@ package com.machankura.bennu.compose.ui.view.model +import com.machankura.bennu.compose.wallet.GroupOnchainWallets +import com.machankura.bennu.compose.wallet.FakeElectrum +import kotlinx.coroutines.cancel +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.CoroutineScope import androidx.compose.foundation.text.input.setTextAndPlaceCursorAtEnd import com.machankura.bennu.compose.database.model.ChatRoom import com.machankura.bennu.compose.database.model.FrostSigningSession @@ -63,8 +68,15 @@ class GroupSendViewModelJvmTest { @BeforeTest fun setUp() = Dispatchers.setMain(UnconfinedTestDispatcher()) + /** A chain with nothing on it: what is under test here is the form, not the coins. */ + private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default) + private val wallets = GroupOnchainWallets(FakeElectrum(), scope) + @AfterTest - fun tearDown() = Dispatchers.resetMain() + fun tearDown() { + scope.cancel() + Dispatchers.resetMain() + } private val chatRoomId = "d4c3b2a1".repeat(8) private val localChatRoom = LocalChatRoom( @@ -113,13 +125,13 @@ class GroupSendViewModelJvmTest { chat: ChatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY, signing: FrostSigningRepository = RecordingSigning(), chain: Chain = Chain.Regtest, - ) = GroupSendViewModel("a".repeat(64), chatRoomId, chain, initial, chat, signing, wallets = null) + ) = GroupSendViewModel("a".repeat(64), chatRoomId, chain, initial, chat, signing, wallets = wallets) @Test - fun `a profile with no node is not offered the form`() { + fun `a member with no share is not offered the form`() { val chat = object : ChatRepository by ChatRepository.NO_OP_CHAT_REPOSITORY { override suspend fun getChatRoomByIdentifier(identifier: String) = localChatRoom - override suspend fun canSign(chatRoomId: String) = true + override suspend fun canSign(chatRoomId: String) = false override suspend fun groupWallet(chatRoomId: String, chain: Chain) = wallet } val model = viewModel(GroupSendUIState.Loading, chat).apply { initiate() } @@ -345,13 +357,13 @@ class GroupSendViewModelJvmTest { override suspend fun groupWallet(chatRoomId: String, chain: Chain) = wallet override suspend fun guardedWallets(chatRoomId: String): List { asked++; return emptyList() } } - val both = GroupSendViewModel("a".repeat(64), chatRoomId, Chain.Regtest, GroupSendUIState.Loading, chat, RecordingSigning(), wallets = null, + val both = GroupSendViewModel("a".repeat(64), chatRoomId, Chain.Regtest, GroupSendUIState.Loading, chat, RecordingSigning(), wallets = wallets, guardedChatRoomId = descendantRoomId, fundChatRoomId = descendantRoomId).apply { initiate() } runBlocking { withTimeout(5_000) { while (both.groupSendUIState == GroupSendUIState.Loading) delay(10) } } assertEquals(GroupSendUIState.Unavailable, both.groupSendUIState) assertEquals(0, asked, "refused before either wallet is looked for") - val unknown = GroupSendViewModel("a".repeat(64), chatRoomId, Chain.Regtest, GroupSendUIState.Loading, chat, RecordingSigning(), wallets = null, + val unknown = GroupSendViewModel("a".repeat(64), chatRoomId, Chain.Regtest, GroupSendUIState.Loading, chat, RecordingSigning(), wallets = wallets, fundChatRoomId = descendantRoomId).apply { initiate() } runBlocking { withTimeout(5_000) { while (unknown.groupSendUIState == GroupSendUIState.Loading) delay(10) } } assertEquals(GroupSendUIState.Unavailable, unknown.groupSendUIState) diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletAddressesViewModelJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletAddressesViewModelJvmTest.kt index 8da5153d..941f7dfa 100644 --- a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletAddressesViewModelJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletAddressesViewModelJvmTest.kt @@ -73,7 +73,7 @@ class GroupWalletAddressesViewModelJvmTest { override suspend fun groupWallet(chatRoomId: String, chain: Chain): GroupWallet? = opened } - private fun viewModel(opened: GroupWallet?, wallets: GroupOnchainWallets?) = + private fun viewModel(opened: GroupWallet?, wallets: GroupOnchainWallets = GroupOnchainWallets(FakeElectrum(), scope)) = GroupWalletAddressesViewModel( chatRoomId = chatRoomId, chain = Chain.Regtest, @@ -94,15 +94,7 @@ class GroupWalletAddressesViewModelJvmTest { @Test fun `a room with no wallet has no addresses to list`() { - assertIs(viewModel(opened = null, wallets = null).until { it != GroupWalletAddressesUIState.Loading }) - } - - @Test - fun `a profile with no node is told it cannot watch rather than shown nothing`() { - assertEquals( - GroupWalletAddressesUIState.CannotWatch, - viewModel(opened = wallet, wallets = null).until { it != GroupWalletAddressesUIState.Loading }, - ) + assertIs(viewModel(opened = null).until { it != GroupWalletAddressesUIState.Loading }) } @Test diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletViewModelJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletViewModelJvmTest.kt index 096be9ac..6e3d81c4 100644 --- a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletViewModelJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupWalletViewModelJvmTest.kt @@ -1,5 +1,10 @@ package com.machankura.bennu.compose.ui.view.model +import com.machankura.bennu.compose.wallet.GroupOnchainWallets +import com.machankura.bennu.compose.wallet.FakeElectrum +import kotlinx.coroutines.cancel +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.CoroutineScope import kotlin.test.assertTrue import com.machankura.bennu.compose.nostr.subgroup.WalletPolicyReading import com.machankura.bennu.compose.nostr.subgroup.SubgroupWalletPolicy @@ -49,8 +54,14 @@ class GroupWalletViewModelJvmTest { @BeforeTest fun setUp() = Dispatchers.setMain(UnconfinedTestDispatcher()) + /** A chain with nothing on it: the wallet screen's rules, not its coins. */ + private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default) + @AfterTest - fun tearDown() = Dispatchers.resetMain() + fun tearDown() { + scope.cancel() + Dispatchers.resetMain() + } private val chatRoomId = "d4c3b2a1".repeat(8) private val me = "a".repeat(64) @@ -118,7 +129,7 @@ class GroupWalletViewModelJvmTest { initialGroupWalletUIState = GroupWalletUIState.Loading, chatRepository = chat, frostSigningRepository = signing, - wallets = null, + wallets = GroupOnchainWallets(FakeElectrum(), scope), ) private fun GroupWalletViewModel.settled(): GroupWalletUIState = runBlocking { @@ -146,12 +157,10 @@ class GroupWalletViewModelJvmTest { } @Test - fun `an open wallet on a profile with no node is shown, and says it cannot watch`() { + fun `an open wallet is shown`() { val state = assertIs(viewModel(repository(opened = wallet)).apply { initiate() }.settled()) assertEquals(wallet, state.wallet) - assertFalse(state.canWatch) - assertNull(state.walletState) } @Test diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/NewMemberWalletViewModelJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/NewMemberWalletViewModelJvmTest.kt index 3479f48c..dcb7da8b 100644 --- a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/NewMemberWalletViewModelJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/NewMemberWalletViewModelJvmTest.kt @@ -57,7 +57,7 @@ class NewMemberWalletViewModelJvmTest { } private fun picking(groups: Map): NewMemberWalletUIState.Picking { - val viewModel = NewMemberWalletViewModel(me, null, Chain.Regtest, canWatch = true, NewMemberWalletUIState.Loading, repository(groups)) + val viewModel = NewMemberWalletViewModel(me, null, Chain.Regtest, NewMemberWalletUIState.Loading, repository(groups)) viewModel.initiate() runBlocking { withTimeout(5_000) { while (viewModel.uiState == NewMemberWalletUIState.Loading) delay(10) } } return assertIs(viewModel.uiState)