[#1418] Display all transaction messages

* [#1418] - Display all transaction messages as separate items

- Closes #1418
- Fix new line indent
- Mention functionality in the changelog
- Use plurals for title when displaying transaction history messages

---------

Co-authored-by: Serhii Ihnatiev <serhii.ihnatiev@ext.grandcentrix.net>
This commit is contained in:
Serhii Ihnatiev 2024-06-14 07:33:56 +02:00 committed by GitHub
parent cc07535f44
commit 34e741e3b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 55 additions and 26 deletions

View File

@ -41,6 +41,7 @@ directly impact users rather than highlighting other key architectural updates.*
### Changed
- The app dialog window has now a bit more rounded corners
- A few more minor UI improvements
- Display all messages within transaction history record when it is expanded
## [1.0 (650)] - 2024-05-07
@ -221,4 +222,4 @@ this screen, together with buttons for copying the address and sharing the addre
- New Wallet Recovery Seed screen (accessible from onboarding)
- Seed Recovery screen (accessible from Settings)
- Restore Seed screen for an existing wallet (accessible from onboarding)
- Restore Seed Birthday Height screen for an existing wallet (accessible from onboarding)
- Restore Seed Birthday Height screen for an existing wallet (accessible from onboarding)

View File

@ -31,6 +31,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.TextStyle
@ -65,7 +66,7 @@ import co.electriccoin.zcash.ui.screen.balances.BalancesTag
import co.electriccoin.zcash.ui.screen.balances.model.StatusAction
import co.electriccoin.zcash.ui.screen.send.view.DEFAULT_LESS_THAN_FEE
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toPersistentList
import kotlinx.collections.immutable.persistentListOf
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.Locale
@ -239,6 +240,23 @@ private fun ComposableHistoryListItemPreview() {
}
}
@Composable
@Preview("Multiple History List Items")
private fun ComposableHistoryListItemsPreview() {
ZcashTheme(forceDarkMode = false) {
BlankSurface {
HistoryItem(
onAction = {},
transaction =
TransactionUiFixture.new(
messages = persistentListOf("Message 1", "Message 2", "Message 3"),
expandableState = TrxItemState.EXPANDED
)
)
}
}
}
const val ADDRESS_IN_TITLE_WIDTH_RATIO = 0.5f
@Composable
@ -468,7 +486,10 @@ private fun HistoryItemCollapsedAddressPart(
color = ZcashTheme.colors.textDescription,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.fillMaxWidth(ADDRESS_IN_TITLE_WIDTH_RATIO).then(clickModifier)
modifier =
Modifier
.fillMaxWidth(ADDRESS_IN_TITLE_WIDTH_RATIO)
.then(clickModifier)
)
}
}
@ -544,6 +565,7 @@ private fun HistoryItemDatePart(
}
@Composable
@Suppress("LongMethod")
private fun HistoryItemExpandedPart(
onAction: (TrxItemAction) -> Unit,
transaction: TransactionUi,
@ -551,18 +573,32 @@ private fun HistoryItemExpandedPart(
) {
Column(modifier = modifier) {
if (transaction.messages.containsValidMemo()) {
Text(
text =
pluralStringResource(
id = R.plurals.account_history_item_message,
count = transaction.messages!!.size
),
style = ZcashTheme.extendedTypography.transactionItemStyles.contentMedium,
color = ZcashTheme.colors.textCommon
)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingSmall))
// Filter out identical messages on a multi-messages transaction that could be created, e.g., using
// YWallet, which tends to balance orchard and sapling pools, including by splitting a payment equally
// across both pools.
val uniqueMessages = transaction.messages!!.deduplicateMemos()
val uniqueMessages = transaction.messages.deduplicateMemos()
HistoryItemMessagePart(
messages = uniqueMessages.toPersistentList(),
state = transaction.overview.getExtendedState(),
onAction = onAction
)
uniqueMessages.forEach { message ->
HistoryItemMessagePart(
message = message,
state = transaction.overview.getExtendedState(),
onAction = onAction
)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingDefault))
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingDefault))
}
} else if (transaction.recipientAddressType == null ||
transaction.recipientAddressType == AddressType.Shielded
) {
@ -611,7 +647,7 @@ private fun HistoryItemExpandedPart(
}
private fun List<String>?.containsValidMemo(): Boolean {
return !isNullOrEmpty() && find { it.isNotEmpty() } != null
return !isNullOrEmpty() && any { it.isNotEmpty() }
}
private fun List<String>.deduplicateMemos(): List<String> {
@ -750,7 +786,7 @@ private fun HistoryItemTransactionFeePart(
@Composable
private fun HistoryItemMessagePart(
messages: ImmutableList<String>,
message: String,
state: TransactionExtendedState,
onAction: (TrxItemAction) -> Unit,
modifier: Modifier = Modifier,
@ -766,25 +802,14 @@ private fun HistoryItemMessagePart(
}
Column(modifier = modifier.then(Modifier.fillMaxWidth())) {
Text(
text = stringResource(id = R.string.account_history_item_message),
style = ZcashTheme.extendedTypography.transactionItemStyles.contentMedium,
color = ZcashTheme.colors.textCommon
)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingSmall))
Box(
modifier =
Modifier
.fillMaxWidth()
.border(width = 1.dp, color = ZcashTheme.colors.textFieldFrame)
) {
// TODO [#1315]: Proper more messages in transaction displaying
// TODO [#1315]: Note we display the first one only for now
// TODO [#1315]: https://github.com/Electric-Coin-Company/zashi-android/issues/1315
Text(
text = messages[0],
text = message,
style = textStyle,
color = textColor,
modifier = Modifier.padding(all = ZcashTheme.dimens.spacingMid)
@ -801,7 +826,7 @@ private fun HistoryItemMessagePart(
modifier =
Modifier
.clip(RoundedCornerShape(ZcashTheme.dimens.regularRippleEffectCorner))
.clickable { onAction(TrxItemAction.MessageClick(messages[0])) }
.clickable { onAction(TrxItemAction.MessageClick(message)) }
.padding(all = ZcashTheme.dimens.spacingTiny)
)
}

View File

@ -12,7 +12,10 @@
<string name="account_history_item_sent_prefix">-</string>
<string name="account_history_item_received_prefix">+</string>
<string name="account_history_item_tap_to_copy">Tap to copy</string>
<string name="account_history_item_message">Message</string>
n <plurals name="account_history_item_message">
<item quantity="one">Message</item>
<item quantity="other">Messages</item>
</plurals>
<string name="account_history_item_no_message">No message included in transaction</string>
<string name="account_history_item_collapse_transaction">Collapse transaction</string>
<string name="account_history_item_transaction_id">Transaction ID</string>