[#1350] No message included in transaction

- Closes #1350
This commit is contained in:
Honza Rychnovský 2024-05-03 10:15:59 +02:00 committed by GitHub
parent e2ddebe47c
commit 2828c25c21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 68 additions and 10 deletions

View File

@ -163,6 +163,7 @@ data class TransactionItemTextStyles(
val valueFirstPart: TextStyle,
val valueSecondPart: TextStyle,
val content: TextStyle,
val contentItalic: TextStyle,
val contentMedium: TextStyle,
val contentUnderline: TextStyle,
val contentLineThrough: TextStyle,
@ -336,6 +337,11 @@ val LocalExtendedTypography =
PrimaryTypography.bodySmall.copy(
fontSize = 13.sp
),
contentItalic =
PrimaryTypography.bodySmall.copy(
fontSize = 13.sp,
fontStyle = FontStyle.Italic
),
contentMedium =
PrimaryTypography.bodySmall.copy(
fontSize = 13.sp,

View File

@ -3,6 +3,7 @@ package co.electriccoin.zcash.ui.screen.account.history.fixture
import cash.z.ecc.android.sdk.fixture.TransactionOverviewFixture
import cash.z.ecc.android.sdk.model.Account
import cash.z.ecc.android.sdk.model.TransactionRecipient
import cash.z.ecc.android.sdk.type.AddressType
import co.electriccoin.zcash.ui.screen.account.ext.TransactionOverviewExt
import co.electriccoin.zcash.ui.screen.account.state.TransactionHistorySyncState
import kotlinx.collections.immutable.ImmutableList
@ -11,9 +12,21 @@ import kotlinx.collections.immutable.persistentListOf
internal object TransactionHistorySyncStateFixture {
val TRANSACTIONS =
persistentListOf(
TransactionOverviewExt(TransactionOverviewFixture.new(), TransactionRecipient.Account(Account.DEFAULT)),
TransactionOverviewExt(TransactionOverviewFixture.new(), TransactionRecipient.Account(Account(1))),
TransactionOverviewExt(TransactionOverviewFixture.new(), null),
TransactionOverviewExt(
TransactionOverviewFixture.new(),
TransactionRecipient.Account(Account.DEFAULT),
AddressType.Shielded
),
TransactionOverviewExt(
TransactionOverviewFixture.new(),
TransactionRecipient.Account(Account(1)),
AddressType.Transparent
),
TransactionOverviewExt(
TransactionOverviewFixture.new(),
null,
AddressType.Unified
),
)
val STATE = TransactionHistorySyncState.Syncing(TRANSACTIONS)

View File

@ -16,6 +16,7 @@ import cash.z.ecc.android.sdk.model.FiatCurrency
import cash.z.ecc.android.sdk.model.PercentDecimal
import cash.z.ecc.android.sdk.model.PersistableWallet
import cash.z.ecc.android.sdk.model.TransactionOverview
import cash.z.ecc.android.sdk.model.TransactionRecipient
import cash.z.ecc.android.sdk.model.WalletAddresses
import cash.z.ecc.android.sdk.model.WalletBalance
import cash.z.ecc.android.sdk.model.Zatoshi
@ -224,9 +225,24 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
}
.map {
if (it.isSentTransaction) {
TransactionOverviewExt(it, synchronizer.getRecipients(it).firstOrNull())
val recipient = synchronizer.getRecipients(it).firstOrNull()
TransactionOverviewExt(
overview = it,
recipient = recipient,
recipientAddressType =
if (recipient != null && (recipient is TransactionRecipient.Address)) {
synchronizer.validateAddress(recipient.addressValue)
} else {
null
}
)
} else {
TransactionOverviewExt(it, null)
// Note that recipients can only be queried for sent transactions
TransactionOverviewExt(
overview = it,
recipient = null,
recipientAddressType = null
)
}
}
if (status.isSyncing()) {

View File

@ -3,10 +3,12 @@ package co.electriccoin.zcash.ui.screen.account.ext
import cash.z.ecc.android.sdk.model.BlockHeight
import cash.z.ecc.android.sdk.model.TransactionOverview
import cash.z.ecc.android.sdk.model.TransactionRecipient
import cash.z.ecc.android.sdk.type.AddressType
data class TransactionOverviewExt(
val overview: TransactionOverview,
val recipient: TransactionRecipient?
val recipient: TransactionRecipient?,
val recipientAddressType: AddressType?
)
fun TransactionOverview.getSortHeight(networkHeight: BlockHeight): BlockHeight {

View File

@ -5,6 +5,7 @@ import cash.z.ecc.android.sdk.fixture.WalletFixture
import cash.z.ecc.android.sdk.model.TransactionOverview
import cash.z.ecc.android.sdk.model.TransactionRecipient
import cash.z.ecc.android.sdk.model.ZcashNetwork
import cash.z.ecc.android.sdk.type.AddressType
import co.electriccoin.zcash.ui.screen.account.model.TransactionUi
import co.electriccoin.zcash.ui.screen.account.model.TrxItemState
@ -16,6 +17,8 @@ object TransactionUiFixture {
WalletFixture.Alice.getAddresses(ZcashNetwork.Mainnet).sapling
)
val RECIPIENT_ADDRESS_TYPE: AddressType = AddressType.Shielded
val EXPANDABLE_STATE: TrxItemState = TrxItemState.COLLAPSED
val MESSAGES: List<String> = listOf("Thanks for the coffee", "It was great to meet you!")
@ -23,11 +26,13 @@ object TransactionUiFixture {
internal fun new(
overview: TransactionOverview = OVERVIEW,
recipient: TransactionRecipient = RECIPIENT,
recipientAddressType: AddressType = RECIPIENT_ADDRESS_TYPE,
expandableState: TrxItemState = EXPANDABLE_STATE,
messages: List<String> = MESSAGES,
) = TransactionUi(
overview = overview,
recipient = recipient,
recipientAddressType = recipientAddressType,
expandableState = expandableState,
messages = messages
)

View File

@ -2,11 +2,13 @@ package co.electriccoin.zcash.ui.screen.account.model
import cash.z.ecc.android.sdk.model.TransactionOverview
import cash.z.ecc.android.sdk.model.TransactionRecipient
import cash.z.ecc.android.sdk.type.AddressType
import co.electriccoin.zcash.ui.screen.account.ext.TransactionOverviewExt
data class TransactionUi(
val overview: TransactionOverview,
val recipient: TransactionRecipient?,
val recipientAddressType: AddressType?,
val expandableState: TrxItemState,
val messages: List<String>?
) {
@ -18,6 +20,7 @@ data class TransactionUi(
) = TransactionUi(
overview = data.overview,
recipient = data.recipient,
recipientAddressType = data.recipientAddressType,
expandableState = expandableState,
messages = messages
)

View File

@ -44,6 +44,7 @@ import cash.z.ecc.android.sdk.model.TransactionRecipient
import cash.z.ecc.android.sdk.model.TransactionState
import cash.z.ecc.android.sdk.model.Zatoshi
import cash.z.ecc.android.sdk.model.toZecString
import cash.z.ecc.android.sdk.type.AddressType
import co.electriccoin.zcash.ui.R
import co.electriccoin.zcash.ui.common.compose.SynchronizationStatus
import co.electriccoin.zcash.ui.common.model.WalletRestoringState
@ -556,6 +557,17 @@ private fun HistoryItemExpandedPart(
onAction = onAction
)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingDefault))
} else if (transaction.recipientAddressType == null ||
transaction.recipientAddressType == AddressType.Shielded
) {
Text(
text = stringResource(id = R.string.account_history_item_no_message),
style = ZcashTheme.extendedTypography.transactionItemStyles.contentItalic,
color = ZcashTheme.colors.textCommon,
modifier = Modifier.fillMaxWidth(EXPANDED_TRANSACTION_WIDTH_RATIO)
)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingDefault))
}
@ -601,8 +613,8 @@ private fun List<String>.deduplicateMemos(): List<String> {
return distinct()
}
const val EXPANDED_TRANSACTION_ID_WIDTH_RATIO = 0.75f
const val COLLAPSED_TRANSACTION_ID_WIDTH_RATIO = 0.5f
const val EXPANDED_TRANSACTION_WIDTH_RATIO = 0.75f
const val COLLAPSED_TRANSACTION_WIDTH_RATIO = 0.5f
@Composable
@Suppress("LongMethod")
@ -631,7 +643,7 @@ private fun HistoryItemTransactionIdPart(
color = ZcashTheme.colors.textCommon,
modifier =
Modifier
.fillMaxWidth(EXPANDED_TRANSACTION_ID_WIDTH_RATIO)
.fillMaxWidth(EXPANDED_TRANSACTION_WIDTH_RATIO)
.testTag(HistoryTag.TRANSACTION_ID)
)
@ -683,7 +695,7 @@ private fun HistoryItemTransactionIdPart(
overflow = TextOverflow.Ellipsis,
modifier =
Modifier
.fillMaxWidth(COLLAPSED_TRANSACTION_ID_WIDTH_RATIO)
.fillMaxWidth(COLLAPSED_TRANSACTION_WIDTH_RATIO)
.testTag(HistoryTag.TRANSACTION_ID)
)
}

View File

@ -13,6 +13,7 @@
<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>
<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>
<string name="account_history_item_transaction_fee">Transaction Fee</string>