feat(wallet): an ancestor's wallet screen gathers a member's wallets and names who guards each (Phase 5)

Members' guarded wallets move under a Members' wallets sub-heading, one
header per person -- @alice, "2 wallets, guarded by 2 groups" -- that
opens their profile, with a card per wallet beneath it. Each card says
which group below guards it: "Guarded by #N", "Guarded by #M, below
#P" where it is further down than this group's own child, "Guarded by
this group", or, with no name this device can check, "Guarded by a
group below #P". An unlabelled wallet is headed by that line.

Fund and Spend now name the wallet as well as the person, so a screen
reader tells one member's several wallets apart. The spend form's
title, the proposal a signer reads and the transcript line name a
labelled member wallet the same way: @alice's guarded wallet "Savings".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5.5 committed 2026-10-24 12:04:08 +02:00
1 parent 695b3db84c
commit a49c3c1639
9 files changed
+230 -17

No files matched your search

@@ -667,6 +667,24 @@
<string name="key_on_another_device">Key on another device</string>
<string name="you_re_no_longer_in_s">You're no longer in %1$s. It still guards this wallet.</string>
<string name="guarded_by_s">Guarded by %1$s</string>
<string name="guarded_by_s_below_s">Guarded by %1$s, below %2$s</string>
<string name="this_group">this group</string>
<string name="a_group_below_s">a group below %1$s</string>
<string name="a_group_below_this_one">a group below this one</string>
<string name="members_wallets">Members' wallets</string>
<string name="s_comma_s">%1$s, %2$s</string>
<plurals name="n_wallets">
<item quantity="one">%1$d wallet</item>
<item quantity="other">%1$d wallets</item>
</plurals>
<plurals name="guarded_by_n_groups">
<item quantity="one">guarded by %1$d group</item>
<item quantity="other">guarded by %1$d groups</item>
</plurals>
<string name="fund_s_s_guarded_wallet_s">Fund %1$s's guarded wallet “%2$s”</string>
<string name="spend_from_s_s_guarded_wallet_s">Spend from %1$s's guarded wallet “%2$s”</string>
<string name="fund_s_s_wallet_guarded_by_s">Fund %1$s's wallet guarded by %2$s</string>
<string name="spend_from_s_s_wallet_guarded_by_s">Spend from %1$s's wallet guarded by %2$s</string>
<string name="discard">Discard</string>
<string name="discard_this_wallet_question">Discard this wallet?</string>
<string name="discarding_forgets_its_key">Its key is forgotten. No address of it was ever offered, so nothing can have been paid to it.</string>
@@ -1303,7 +1303,7 @@ object FrostSigningManager {
content = when (val guardian = checked.spender as? GroupSpend.Spender.Guardian) {
null -> "The group signed a transaction sending ${checked.amountSent.sat} sats, "
else -> "The group signed a transaction sending ${checked.amountSent.sat} sats from " +
"${guardian.name ?: "a subgroup"}'s guarded wallet, "
"${com.machankura.bennu.compose.text.ProposedSpend.guardedWallet(guardian.name, guardian.label)}, "
} + "with ${checked.fee.sat} sats in fees. It took ${session.threshold} of " +
"${session.participantCount} members.",
actor = session.coordinatorPublicKey
@@ -139,7 +139,10 @@ object GuardianManager {
/** The ancestor as the spender of a spend from this wallet, signing as [thresholdPublicKey] -- null to only build one. */
fun spender(thresholdPublicKey: HexKey? = null): GroupSpend.Spender.Guardian =
GroupSpend.Spender.Guardian(position = position, lineage = lineage, thresholdPublicKey = thresholdPublicKey, name = displayName)
GroupSpend.Spender.Guardian(position = position, lineage = lineage, thresholdPublicKey = thresholdPublicKey, name = displayName, label = label)
/** A member's label for it, where they gave one; null for a subgroup's. */
val label: String? get() = (subject as? GuardedSubject.Member)?.label
/** How a spend from it names it: a subgroup's founding name, or `@` and a member's. */
val displayName: String?
@@ -20,24 +20,33 @@ object ProposedSpend {
// device derived it -- never the proposer's word for it.
label = when (val guardian = spend.spender as? GroupSpend.Spender.Guardian) {
null -> spend.fundings.singleOrNull()?.takeIf { spend.payments.size == 1 }
?.let { "Fund ${nameOf(it)}'s guarded wallet" }
?.let { "Fund ${walletOf(it)}" }
?: "Spend from the group's wallet"
else -> "Spend from ${guardian.name ?: "a subgroup"}'s guarded wallet"
else -> "Spend from ${guardedWallet(guardian.name, guardian.label)}"
},
detail = when (val payment = spend.payments.singleOrNull()) {
null -> "Send ${spend.amountSent.grouped()} sats to ${spend.payments.size} addresses" + when (val funding = spend.fundings.singleOrNull()) {
null -> if (spend.fundings.isEmpty()) "" else
", ${Satoshi(spend.fundings.sumOf { spend.tx.txOut[it.outputIndex].amount.sat }).grouped()} of them to ${spend.fundings.size} guarded wallets"
else -> ", ${spend.tx.txOut[funding.outputIndex].amount.grouped()} of them to ${nameOf(funding)}'s guarded wallet"
else -> ", ${spend.tx.txOut[funding.outputIndex].amount.grouped()} of them to ${walletOf(funding)}"
}
else -> when (val funding = spend.fundings.singleOrNull()) {
null -> "Send ${payment.txOut.amount.grouped()} sats to ${addressOf(payment.txOut.publicKeyScript, chain)}"
else -> "Send ${payment.txOut.amount.grouped()} sats to ${nameOf(funding)}'s guarded wallet, address ${funding.derived.index}"
else -> "Send ${payment.txOut.amount.grouped()} sats to ${walletOf(funding)}, address ${funding.derived.index}"
}
}
)
private fun nameOf(funding: GroupSpend.Funding): String = funding.wallet.displayName ?: "a subgroup"
private fun walletOf(funding: GroupSpend.Funding): String = guardedWallet(funding.wallet.displayName, funding.wallet.label)
/**
* A guarded wallet in a sentence: *#Translation's guarded wallet*, *@alice's
* guarded wallet* -- and, for a member's wallet with a label, *@alice's
* guarded wallet “Savings”*, since one person can have several and a signer
* should know which is being spent from. `docs/member-wallet-guarding-group.md`, Phase 5.
*/
fun guardedWallet(name: String?, label: String?): String =
"${name ?: "a subgroup"}'s guarded wallet" + (label?.let { " “$it”" } ?: "")
/** The address [script] pays, or the script itself where it has no address. */
fun addressOf(script: ByteVector, chain: Chain): String =
@@ -15,6 +15,8 @@ import androidx.compose.ui.text.font.FontFamily
import bennu.composeapp.generated.resources.address_s
import bennu.composeapp.generated.resources.finding_an_address_in_s_s_wallet
import bennu.composeapp.generated.resources.fund_s_s_guarded_wallet
import bennu.composeapp.generated.resources.fund_s_s_guarded_wallet_s
import bennu.composeapp.generated.resources.spend_from_s_s_guarded_wallet_s
import bennu.composeapp.generated.resources.sends_s_sats_to_s_s_guarded_wallet_with_a_fee_of_s_sats
import bennu.composeapp.generated.resources.this_group_can_spend_these_coins_again
import bennu.composeapp.generated.resources.to
@@ -171,8 +173,11 @@ fun GroupSendScreen(
val funded = ready?.funding?.wallet
Text(
text = when {
// A member's label says which of their wallets.
guardian?.label != null -> stringResource(Res.string.spend_from_s_s_guarded_wallet_s, guardian.name ?: stringResource(Res.string.a_subgroup), guardian.label)
guardian != null -> stringResource(Res.string.spend_from_s_s_guarded_wallet, guardian.name ?: stringResource(Res.string.a_subgroup))
funded != null -> stringResource(Res.string.fund_s_s_guarded_wallet, funded.displayName ?: stringResource(Res.string.a_subgroup))
funded != null -> funded.label?.let { label -> stringResource(Res.string.fund_s_s_guarded_wallet_s, funded.displayName ?: stringResource(Res.string.a_subgroup), label) }
?: stringResource(Res.string.fund_s_s_guarded_wallet, funded.displayName ?: stringResource(Res.string.a_subgroup))
else -> stringResource(Res.string.send_from_the_group_s_wallet)
},
maxLines = 1,
@@ -1,5 +1,26 @@
package com.machankura.bennu.compose.ui.composable
import bennu.composeapp.generated.resources.a_group_below_s
import bennu.composeapp.generated.resources.a_group_below_this_one
import bennu.composeapp.generated.resources.fund_s_s_guarded_wallet_s
import bennu.composeapp.generated.resources.fund_s_s_wallet_guarded_by_s
import bennu.composeapp.generated.resources.guarded_by_n_groups
import bennu.composeapp.generated.resources.guarded_by_s
import bennu.composeapp.generated.resources.guarded_by_s_below_s
import bennu.composeapp.generated.resources.members_wallets
import bennu.composeapp.generated.resources.n_wallets
import bennu.composeapp.generated.resources.s_comma_s
import bennu.composeapp.generated.resources.spend_from_s_s_guarded_wallet_s
import bennu.composeapp.generated.resources.spend_from_s_s_wallet_guarded_by_s
import bennu.composeapp.generated.resources.this_group
import androidx.compose.foundation.clickable
import androidx.compose.material3.minimumInteractiveComponentSize
import androidx.compose.ui.unit.dp
import com.machankura.bennu.compose.ui.composable.navigation.routes.ProfilePreviewRoute
import com.machankura.bennu.compose.ui.composable.widgets.profile.ProfileAvatar
import com.machankura.bennu.compose.ui.view.state.PersonGuardedWallets
import com.machankura.bennu.compose.ui.view.state.byPerson
import org.jetbrains.compose.resources.pluralStringResource
import bennu.composeapp.generated.resources.this_group_s_delay_in_this_wallet
import bennu.composeapp.generated.resources.a_group_above_this_one
import bennu.composeapp.generated.resources.guardian_after
@@ -222,6 +243,11 @@ fun GroupWalletScreen(
)
)
}
// A member's wallets are gathered under them, and their header opens them:
// a person is someone to look at, not a room to go into.
val toPerson = { publicKey: HexKey ->
onNavigateToRoute(ProfilePreviewRoute(activeUserPublicKey = activeUserPublicKey, profilePublicKey = publicKey))
}
val onShare = { shareable: GuardianManager.Shareable ->
groupWalletViewModel.share(shareable, onShared = { notify(shared) }, onFailure = { notify(couldNotShare) })
}
@@ -327,6 +353,7 @@ fun GroupWalletScreen(
onSpend = if (state.canSign && wallets != null) toGuardianSpend else null,
// A group with no wallet of its own has nothing to fund with.
onFund = null,
onOpenPerson = toPerson,
)
}
}
@@ -371,6 +398,7 @@ fun GroupWalletScreen(
onShare = onShare,
onSpend = if (state.canSign && state.canWatch) toGuardianSpend else null,
onFund = if (state.canSign && state.canWatch) toGuardianFund else null,
onOpenPerson = toPerson,
)
}
}
@@ -472,6 +500,7 @@ private fun OpenWallet(
onShare: (GuardianManager.Shareable) -> Unit,
onSpend: ((GuardedWalletRow) -> Unit)?,
onFund: ((GuardedWalletRow) -> Unit)?,
onOpenPerson: (HexKey) -> Unit,
) {
val clipboardManager = LocalClipboardManager.current
val addressCopied = stringResource(Res.string.address_copied)
@@ -638,6 +667,7 @@ private fun OpenWallet(
onShare = onShare,
onSpend = onSpend,
onFund = onFund,
onOpenPerson = onOpenPerson,
)
}
}
@@ -696,6 +726,7 @@ private fun LazyListScope.guardianItems(
onShare: (GuardianManager.Shareable) -> Unit,
onSpend: ((GuardedWalletRow) -> Unit)?,
onFund: ((GuardedWalletRow) -> Unit)?,
onOpenPerson: (HexKey) -> Unit,
) {
if (guardedWallets.isNotEmpty()) {
item {
@@ -708,9 +739,33 @@ private fun LazyListScope.guardianItems(
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
items(guardedWallets, key = { "guarded-" + it.wallet.statement.id }) { row ->
// Subgroups' wallets, each a room; then members', gathered by person, so
// that one member's wallets under different groups below read as one
// person's. docs/member-wallet-guarding-group.md, D6.
val subgroups = guardedWallets.filter { it.wallet.subject is GuardianManager.GuardedSubject.Subgroup }
items(subgroups, key = { "guarded-" + it.wallet.statement.id }) { row ->
GuardedWalletCard(row = row, onSpend = onSpend, onFund = onFund)
}
val people = guardedWallets.byPerson()
if (people.isNotEmpty()) {
item {
Text(text = stringResource(Res.string.members_wallets), style = MaterialTheme.typography.titleSmall)
}
people.forEach { person ->
item(key = "person-" + person.ownerPublicKey) {
PersonHeader(person = person, onOpen = { onOpenPerson(person.ownerPublicKey) })
}
items(person.rows, key = { "guarded-" + it.wallet.statement.id }) { row ->
GuardedWalletCard(
row = row,
onSpend = onSpend,
onFund = onFund,
// Under the header, so the cards read as the person's.
modifier = Modifier.padding(start = MaterialTheme.spacing.containerPadding),
)
}
}
}
}
if (shareable.isNotEmpty()) {
@@ -777,13 +832,23 @@ private fun GuardedWalletCard(
row: GuardedWalletRow,
onSpend: ((GuardedWalletRow) -> Unit)?,
onFund: ((GuardedWalletRow) -> Unit)?,
modifier: Modifier = Modifier,
) {
val name = guardedName(row.wallet.subject)
OutlinedCard(modifier = Modifier.fillMaxWidth()) {
val member = row.wallet.subject as? GuardianManager.GuardedSubject.Member
val guardedBy = member?.let { guardedByLine(row.wallet, it) }
// A member's card sits under their header, so it is named by its label --
// or, with none, by the group that guards it, which still tells two of one
// person's wallets apart.
val headline = when {
member == null -> name
else -> member.label ?: guardedBy.orEmpty()
}
OutlinedCard(modifier = modifier.fillMaxWidth()) {
ListItem(
leadingContent = { Icon(Icons.Default.AccountBalanceWallet, contentDescription = Decorative) },
// Two lines, since the name is what says which wallet the buttons act on.
headlineContent = { Text(name, maxLines = 2, overflow = TextOverflow.Ellipsis) },
headlineContent = { Text(headline, maxLines = 2, overflow = TextOverflow.Ellipsis) },
supportingContent = {
val reach = row.withinReach?.let { stringResource(Res.string.s_sats_within_this_group_s_reach, it.grouped()) }
val arriving = row.arriving?.takeIf { it.sat > 0 }?.let { stringResource(Res.string.s_sats_arriving, it.grouped()) }
@@ -792,10 +857,10 @@ private fun GuardedWalletCard(
arriving == null -> reach
else -> stringResource(Res.string.s_dot_s, reach, arriving)
}
// A member's label says which of their wallets it is.
val label = (row.wallet.subject as? GuardianManager.GuardedSubject.Member)?.label
Column {
Text(label?.let { stringResource(Res.string.s_dot_s, it, amounts) } ?: amounts)
// Which group below guards it, where the headline does not say.
if (member?.label != null && guardedBy != null) Text(guardedBy)
Text(amounts)
// This group's own leaf, which two of its descendants can have
// set differently. docs/guardian-delay.md.
Text(stringResource(Res.string.this_group_s_delay_in_this_wallet, delayText(row.wallet.delay, row.wallet.chain)))
@@ -803,8 +868,18 @@ private fun GuardedWalletCard(
},
)
if (onFund != null || onSpend != null) {
val fundLabel = stringResource(Res.string.fund_s_s_guarded_wallet, name)
val spendLabel = stringResource(Res.string.spend_from_s_s_guarded_wallet, name)
// Each names its wallet and not only its person: one member can have
// several here, and a screen reader hears every one's *Fund* alike.
val fundLabel = when {
member == null -> stringResource(Res.string.fund_s_s_guarded_wallet, name)
member.label != null -> stringResource(Res.string.fund_s_s_guarded_wallet_s, name, member.label)
else -> stringResource(Res.string.fund_s_s_wallet_guarded_by_s, name, guardianPhrase(row.wallet, member))
}
val spendLabel = when {
member == null -> stringResource(Res.string.spend_from_s_s_guarded_wallet, name)
member.label != null -> stringResource(Res.string.spend_from_s_s_guarded_wallet_s, name, member.label)
else -> stringResource(Res.string.spend_from_s_s_wallet_guarded_by_s, name, guardianPhrase(row.wallet, member))
}
FlowRow(
modifier = Modifier.fillMaxWidth().padding(
start = MaterialTheme.spacing.containerPadding,
@@ -830,6 +905,51 @@ private fun GuardedWalletCard(
}
}
/**
* One member, heading their wallets in an ancestor's list: how many this group
* guards, and under how many groups below it -- the summary that shows a person
* with wallets in more than one branch. Opens their profile.
*/
@Composable
private fun PersonHeader(person: PersonGuardedWallets, onOpen: () -> Unit) {
val name = stringResource(Res.string.at_s, person.ownerName ?: person.ownerPublicKey.take(8))
val wallets = pluralStringResource(Res.plurals.n_wallets, person.rows.size, person.rows.size)
val groups = pluralStringResource(Res.plurals.guarded_by_n_groups, person.guardianCount, person.guardianCount)
ListItem(
modifier = Modifier.clickable(onClick = onOpen).minimumInteractiveComponentSize(),
// 40dp is the avatar's size, a dimension: M3's list item leading avatar.
leadingContent = { ProfileAvatar(size = 40.dp, publicKey = person.ownerPublicKey, picture = null, name = person.ownerName) },
headlineContent = { Text(name, maxLines = 1, overflow = TextOverflow.Ellipsis) },
supportingContent = { Text(stringResource(Res.string.s_comma_s, wallets, groups)) },
)
}
/**
* The group that directly guards a member's wallet, as a phrase inside a
* sentence: *this group*, its name, or -- with no name this device can check --
* where it sits, *a group below #P*. `docs/member-wallet-guarding-group.md`, D2.
*/
@Composable
internal fun guardianPhrase(wallet: GuardianManager.GuardedWallet, member: GuardianManager.GuardedSubject.Member): String = when {
wallet.isGuardedHere -> stringResource(Res.string.this_group)
member.guardianName != null -> member.guardianName
member.branchName != null -> stringResource(Res.string.a_group_below_s, member.branchName)
else -> stringResource(Res.string.a_group_below_this_one)
}
/**
* *Guarded by #N*, or *Guarded by #M, below #P* where the group is further down
* than this one's own child -- the branch, so wallets from one part of the tree
* read as being from there. `docs/member-wallet-guarding-group.md`, D6.
*/
@Composable
internal fun guardedByLine(wallet: GuardianManager.GuardedWallet, member: GuardianManager.GuardedSubject.Member): String =
if (wallet.position >= 2 && member.guardianName != null && member.branchName != null) {
stringResource(Res.string.guarded_by_s_below_s, member.guardianName, member.branchName)
} else {
stringResource(Res.string.guarded_by_s, guardianPhrase(wallet, member))
}
/**
* A guarded wallet as an ancestor's list names it: a subgroup by the name its
* parent certified -- `#Translation` -- and a member by their profile's name --
@@ -102,6 +102,8 @@ object GroupSpend {
val thresholdPublicKey: HexKey? = null,
/** The guarded wallet's founding name, for the words a spend is shown in. */
val name: String? = null,
/** A member's label for the wallet, where they gave one: one person can have several. */
val label: String? = null,
) : Spender
}
@@ -235,6 +235,6 @@ class MemberWalletGuardianJvmTest {
assertEquals(walletId, funded.wallet.descendantChatRoomId)
assertEquals(target.pubkeyScript, checked.tx.txOut[funded.outputIndex].publicKeyScript)
val summary = com.machankura.bennu.compose.text.ProposedSpend.summarize(checked.copy(fundings = reading.fundings), chain)
assertEquals("Fund @alice's guarded wallet", summary.label)
assertEquals("Fund @alice's guarded wallet “Savings”", summary.label)
}
}
@@ -1,6 +1,9 @@
package com.machankura.bennu.compose.ui.composable
import com.machankura.bennu.compose.managers.GuardianDerivation
import com.machankura.bennu.compose.managers.LineageExample
import com.machankura.bennu.compose.managers.LineageExample.heldBy
import com.machankura.bennu.compose.ui.composable.navigation.routes.ProfilePreviewRoute
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.CompositionLocalProvider
@@ -171,4 +174,57 @@ class GuardedWalletCardJvmTest {
onNodeWithContentDescription("Fund Savings's guarded wallet").assertIsDisplayed()
onNodeWithContentDescription("Spend from Savings's guarded wallet").assertIsDisplayed()
}
// ---- Members' wallets by person: docs/member-wallet-guarding-group.md, Phase 5
/** R's wallet screen, guarding Alice's Savings (under M, below P) and Rent (under N). */
private fun atR(vararg guarded: GuardianManager.GuardedWallet): GroupWalletUIState.Loaded =
loaded("Savings").copy(guardedWallets = guarded.map { GuardedWalletRow(it, walletState = null) })
private val savings = heldBy(LineageExample.r, LineageExample.savings, LineageExample.savingsGuardians, label = "Savings", guardianName = "#M", branchName = "#P")
private val rent = heldBy(LineageExample.r, LineageExample.rent, LineageExample.rentGuardians, label = "Rent", guardianName = "#N", branchName = "#N")
@Test
fun `a member's two wallets under two groups are one header, each card naming its group`() = render(atR(savings, rent)) {
onNodeWithText("Members' wallets").assertIsDisplayed()
onNodeWithText("@alice").assertIsDisplayed()
onNodeWithText("2 wallets, guarded by 2 groups").assertIsDisplayed()
onNodeWithText("Rent").assertIsDisplayed()
onNodeWithText("Guarded by #N").assertIsDisplayed()
onNodeWithText("Savings").assertIsDisplayed()
onNodeWithText("Guarded by #M, below #P").assertIsDisplayed()
}
@Test
fun `an unlabelled wallet is named by the group that guards it`() =
render(atR(heldBy(LineageExample.r, LineageExample.savings, LineageExample.savingsGuardians, branchName = "#P"))) {
// No name this device can check for M: where it sits instead.
onNodeWithText("Guarded by a group below #P").assertIsDisplayed()
onNodeWithText("1 wallet, guarded by 1 group").assertIsDisplayed()
}
@Test
fun `each of a member's buttons names its wallet`() = render(atR(savings, rent, heldBy(LineageExample.r, "9".repeat(64), LineageExample.rentGuardians, guardianName = "#N", branchName = "#N"))) {
onNodeWithContentDescription("Fund @alice's guarded wallet “Savings”").assertIsDisplayed()
onNodeWithContentDescription("Spend from @alice's guarded wallet “Savings”").assertIsDisplayed()
onNodeWithContentDescription("Fund @alice's guarded wallet “Rent”").assertIsDisplayed()
onNodeWithContentDescription("Spend from @alice's guarded wallet “Rent”").assertIsDisplayed()
onNodeWithContentDescription("Fund @alice's wallet guarded by #N").assertIsDisplayed()
onNodeWithContentDescription("Spend from @alice's wallet guarded by #N").assertIsDisplayed()
}
@Test
fun `a wallet this group guards directly says so`() =
render(atR(heldBy(LineageExample.m, LineageExample.savings, LineageExample.savingsGuardians, label = "Savings", guardianName = "#M"))) {
onNodeWithText("Guarded by this group").assertIsDisplayed()
}
@Test
fun `the header opens the member's profile`() {
var opened: Route? = null
render(atR(savings), onRoute = { opened = it }) {
onNodeWithText("@alice").performClick()
}
assertEquals(ProfilePreviewRoute(activeUserPublicKey = "a".repeat(64), profilePublicKey = LineageExample.alice), opened)
}
}