feat(wallet): the group picker lists only groups that guard members' wallets, or may
"Choose a group to guard it" no longer lists a group that never opened to its members' wallets, or has closed: neither is a choice. A group whose key -- and so whose policy -- this device has not been told stays, with the button that asks, since the answer is how it learns the group is open; so do the refusals about the profile itself. The empty list now says how that changes: a group's signers can turn it on from its page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
52b17bbc36
commit
8871e47224
5 files changed
+100
-5
No files matched your search
@@ -620,7 +620,7 @@
|
||||
<string name="new_guarded_wallet">New guarded wallet</string>
|
||||
<string name="a_group">A group</string>
|
||||
<string name="choose_a_group_to_guard_it">Choose a group to guard it</string>
|
||||
<string name="you_are_in_no_groups_that_can_guard_a_wallet">You're in no groups that could guard a wallet for you.</string>
|
||||
<string name="none_of_your_groups_guards_members_wallets_yet">None of your groups guards members' wallets yet. A group's signers can turn it on from the group's page.</string>
|
||||
<string name="a_wallet_only_you_can_spend_from_guarded_by_s">A wallet only you can spend from, guarded by %1$s</string>
|
||||
<string name="s_can_take_any_coin_without_asking_you">%1$s can take any coin in it that has waited %2$s, without asking you.</string>
|
||||
<string name="s_and_the_group_above_it_can_take_any_coin_without_asking_you">%1$s can take any coin in it that has waited %2$s, and the group above it any coin that has waited %3$s, without asking you.</string>
|
||||
|
||||
+2
-2
@@ -56,7 +56,7 @@ import bennu.composeapp.generated.resources.this_device_does_not_know_what_this_
|
||||
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.you_are_in_no_groups_that_can_guard_a_wallet
|
||||
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
|
||||
import com.machankura.bennu.compose.ui.composable.widgets.Decorative
|
||||
@@ -138,7 +138,7 @@ fun NewMemberWalletScreen(
|
||||
is NewMemberWalletUIState.Picking -> if (state.groups.isEmpty()) {
|
||||
EmptyState(
|
||||
modifier = Modifier.padding(padding).readableContent(),
|
||||
message = stringResource(Res.string.you_are_in_no_groups_that_can_guard_a_wallet),
|
||||
message = stringResource(Res.string.none_of_your_groups_guards_members_wallets_yet),
|
||||
icon = Icons.Default.Groups,
|
||||
)
|
||||
} else {
|
||||
|
||||
+11
-1
@@ -52,7 +52,14 @@ class NewMemberWalletViewModel(
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
uiState = when (val chosen = chatRoomId) {
|
||||
null -> NewMemberWalletUIState.Picking(
|
||||
memberWalletRepository.groupsOf(activeUserPublicKey).map { GroupChoice(it, refusal(it.chatRoom.id)) }
|
||||
memberWalletRepository.groupsOf(activeUserPublicKey)
|
||||
.map { GroupChoice(it, refusal(it.chatRoom.id)) }
|
||||
// A group that has never opened to its members' wallets, or
|
||||
// has closed, is not a choice, so it is not on the list. A
|
||||
// group whose key -- and so whose policy -- this device has
|
||||
// not been told yet stays, with the button that asks: it may
|
||||
// well be open. docs/member-wallet-delay.md.
|
||||
.filter { it.refusal !in NOT_A_CHOICE }
|
||||
)
|
||||
else -> choose(chosen) ?: NewMemberWalletUIState.Error("Couldn't find the group")
|
||||
}
|
||||
@@ -108,6 +115,9 @@ class NewMemberWalletViewModel(
|
||||
}
|
||||
|
||||
companion object {
|
||||
/** Refusals that say a group is not guarding members' wallets, rather than that this device cannot ask yet. */
|
||||
private val NOT_A_CHOICE = setOf(MemberWalletManager.Refusal.NOT_OFFERED, MemberWalletManager.Refusal.CLOSED)
|
||||
|
||||
private const val TAG = "NewMemberWalletViewModel"
|
||||
|
||||
/** The longest label a request carries -- `MemberWalletRequestEvent.MAX_LABEL_LENGTH`. */
|
||||
|
||||
+5
-1
@@ -8,7 +8,11 @@ sealed interface NewMemberWalletUIState {
|
||||
|
||||
data class Error(val message: String) : NewMemberWalletUIState
|
||||
|
||||
/** No group chosen yet: every group this profile is in, each with why it cannot guard a wallet, if it cannot. */
|
||||
/**
|
||||
* No group chosen yet: every group this profile is in that guards members'
|
||||
* wallets, or may -- one whose key this device does not know yet -- each
|
||||
* with why it cannot guard a wallet now, if it cannot.
|
||||
*/
|
||||
data class Picking(val groups: List<GroupChoice>) : NewMemberWalletUIState
|
||||
|
||||
/**
|
||||
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package com.machankura.bennu.compose.ui.view.model
|
||||
|
||||
import com.machankura.bennu.compose.database.model.ChatRoom
|
||||
import com.machankura.bennu.compose.database.model.intermdiate.LocalChatRoom
|
||||
import com.machankura.bennu.compose.managers.MemberWalletManager.Refusal
|
||||
import com.machankura.bennu.compose.repository.MemberWalletRepository
|
||||
import com.machankura.bennu.compose.ui.view.state.NewMemberWalletUIState
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import fr.acinq.bitcoin.Chain
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.test.UnconfinedTestDispatcher
|
||||
import kotlinx.coroutines.test.resetMain
|
||||
import kotlinx.coroutines.test.setMain
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import kotlin.test.AfterTest
|
||||
import kotlin.test.BeforeTest
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertIs
|
||||
|
||||
/**
|
||||
* Which groups the *Choose a group to guard it* list offers --
|
||||
* `docs/member-wallet-delay.md`. Only a group that guards members' wallets, or
|
||||
* may: one whose key this device has not been told is kept, with the button
|
||||
* that asks, because the answer is how it would learn the group is open.
|
||||
*/
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class NewMemberWalletViewModelJvmTest {
|
||||
@BeforeTest
|
||||
fun setUp() = Dispatchers.setMain(UnconfinedTestDispatcher())
|
||||
|
||||
@AfterTest
|
||||
fun tearDown() = Dispatchers.resetMain()
|
||||
|
||||
private val me = "a".repeat(64)
|
||||
|
||||
private fun room(id: Char) = LocalChatRoom(
|
||||
chatRoom = ChatRoom(id = id.toString().repeat(64), userPublicKey = me, subject = "#$id", description = null, mlsGroupState = "state")
|
||||
)
|
||||
|
||||
/** One group per refusal, and one that can be asked. */
|
||||
private val refusals: Map<LocalChatRoom, Refusal?> = mapOf(
|
||||
room('1') to null,
|
||||
room('2') to Refusal.KEY_UNKNOWN,
|
||||
room('3') to Refusal.NOT_OFFERED,
|
||||
room('4') to Refusal.CLOSED,
|
||||
room('5') to Refusal.GUARDIANS_UNREADABLE,
|
||||
)
|
||||
|
||||
private fun repository(groups: Map<LocalChatRoom, Refusal?>) = object : MemberWalletRepository by MemberWalletRepository.NO_OP {
|
||||
override suspend fun groupsOf(ownerPublicKey: HexKey): List<LocalChatRoom> = groups.keys.toList()
|
||||
override suspend fun refusal(chatRoomId: String, chain: Chain): Refusal? =
|
||||
groups.entries.first { it.key.chatRoom.id == chatRoomId }.value
|
||||
}
|
||||
|
||||
private fun picking(groups: Map<LocalChatRoom, Refusal?>): NewMemberWalletUIState.Picking {
|
||||
val viewModel = NewMemberWalletViewModel(me, null, Chain.Regtest, canWatch = true, NewMemberWalletUIState.Loading, repository(groups))
|
||||
viewModel.initiate()
|
||||
runBlocking { withTimeout(5_000) { while (viewModel.uiState == NewMemberWalletUIState.Loading) delay(10) } }
|
||||
return assertIs<NewMemberWalletUIState.Picking>(viewModel.uiState)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a group that never opened, or has closed, is not on the list`() {
|
||||
val listed = picking(refusals).groups.associate { it.room.chatRoom.subject to it.refusal }
|
||||
|
||||
assertEquals(
|
||||
mapOf<String?, Refusal?>("#1" to null, "#2" to Refusal.KEY_UNKNOWN, "#5" to Refusal.GUARDIANS_UNREADABLE),
|
||||
listed,
|
||||
"an open group, one whose key is not known yet, and one this build cannot read stay, each with its reason",
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a member none of whose groups guards members' wallets sees an empty list`() {
|
||||
assertEquals(emptyList(), picking(mapOf(room('3') to Refusal.NOT_OFFERED, room('4') to Refusal.CLOSED)).groups)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user