Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1416] Shielded transaction UI #1573

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this application adheres to [Semantic Versioning](https://semver.org/spec/v2
- Choose server screen has been redesigned
- Settings and Advanced Settings screens have been redesigned
- Android `compileSdkVersion` and `targetSdkVersion` have been updated to version 35
- Shielded transactions are properly indicated in transaction history

## [1.1.7 (718)] - 2024-09-06

Expand Down
1 change: 1 addition & 0 deletions docs/whatsNew/WHATS_NEW_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ directly impact users rather than highlighting other key architectural updates.*
- The Choose server screen now provides a new search for the three fastest servers feature
- Android 15 (Android SDK API level 35) support for 16 KB memory page size has been added
- Coinbase Onramp integration button has been added to the Advanced Settings screen
- Shielded transactions are properly indicated in transaction history

### Changed
- Choose server screen has been redesigned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private fun ComposableHistoryListItemsPreview() {
const val ADDRESS_IN_TITLE_WIDTH_RATIO = 0.5f

@Composable
@Suppress("LongMethod")
@Suppress("LongMethod", "CyclomaticComplexMethod")
private fun HistoryItem(
transaction: TransactionUi,
isHideBalances: Boolean,
Expand Down Expand Up @@ -359,6 +359,27 @@ private fun HistoryItem(
textColor = ZcashTheme.colors.historyRedColor
textStyle = ZcashTheme.extendedTypography.transactionItemStyles.titleFailed
}

TransactionExtendedState.SHIELDED -> {
typeText = stringResource(id = R.string.account_history_item_shielded_funds)
typeIcon = ImageVector.vectorResource(R.drawable.ic_trx_shielded_funds)
textColor = MaterialTheme.colorScheme.onBackground
textStyle = ZcashTheme.extendedTypography.transactionItemStyles.titleRegular
}

TransactionExtendedState.SHIELDING -> {
typeText = stringResource(id = R.string.account_history_item_shielding_funds)
typeIcon = ImageVector.vectorResource(R.drawable.ic_trx_shielded_funds)
textColor = ZcashTheme.colors.textDescription
textStyle = ZcashTheme.extendedTypography.transactionItemStyles.titleRunning
}

TransactionExtendedState.SHIELDING_FAILED -> {
typeText = stringResource(id = R.string.account_history_item_shielding_failed)
typeIcon = ImageVector.vectorResource(R.drawable.ic_trx_shielded_funds)
textColor = ZcashTheme.colors.historyRedColor
textStyle = ZcashTheme.extendedTypography.transactionItemStyles.titleFailed
}
}

Row(
Expand Down Expand Up @@ -556,7 +577,7 @@ private fun HistoryItemCollapsedAddressPart(
)
}
}
} else {
} else if (!transaction.overview.isShielding) {
Icon(
imageVector = ImageVector.vectorResource(R.drawable.ic_trx_shielded),
contentDescription = stringResource(id = R.string.account_history_item_shielded)
Expand Down Expand Up @@ -636,7 +657,7 @@ private fun HistoryItemExpandedPart(
modifier: Modifier = Modifier
) {
Column(modifier = modifier) {
if (transaction.messages.containsValidMemo()) {
if (transaction.overview.isShielding.not() && transaction.messages.containsValidMemo()) {
Text(
text =
pluralStringResource(
Expand All @@ -662,8 +683,8 @@ private fun HistoryItemExpandedPart(
)
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingDefault))
}
} else if (transaction.recipientAddressType == null ||
transaction.recipientAddressType == AddressType.Shielded
} else if (transaction.overview.isShielding.not() &&
(transaction.recipientAddressType == null || transaction.recipientAddressType == AddressType.Shielded)
) {
Text(
text = stringResource(id = R.string.account_history_item_no_message),
Expand Down Expand Up @@ -929,41 +950,41 @@ internal enum class TransactionExtendedState {
SEND_FAILED,
RECEIVED,
RECEIVING,
RECEIVE_FAILED;
RECEIVE_FAILED,
SHIELDED,
SHIELDING,
SHIELDING_FAILED;

fun isFailed(): Boolean = this == SEND_FAILED || this == RECEIVE_FAILED
fun isShielding() = this in listOf(SHIELDED, RECEIVE_FAILED, SHIELDING_FAILED)

fun isSendType(): Boolean = this == SENDING || this == SENT || this == SEND_FAILED
fun isFailed(): Boolean = this in listOf(SEND_FAILED, RECEIVE_FAILED, SHIELDING_FAILED)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good improvement.


fun isSendType(): Boolean = this in listOf(SENDING, SENT, SEND_FAILED, SHIELDED, SHIELDING_FAILED, SHIELDING)
}

private fun TransactionOverview.getExtendedState(): TransactionExtendedState {
return when (transactionState) {
TransactionState.Expired -> {
if (isSentTransaction) {
TransactionExtendedState.SEND_FAILED
} else {
TransactionExtendedState.RECEIVE_FAILED
TransactionState.Expired ->
when {
isShielding -> TransactionExtendedState.SHIELDING_FAILED
isSentTransaction -> TransactionExtendedState.SEND_FAILED
else -> TransactionExtendedState.RECEIVE_FAILED
}
}

TransactionState.Confirmed -> {
if (isSentTransaction) {
TransactionExtendedState.SENT
} else {
TransactionExtendedState.RECEIVED
TransactionState.Confirmed ->
when {
isShielding -> TransactionExtendedState.SHIELDED
isSentTransaction -> TransactionExtendedState.SENT
else -> TransactionExtendedState.RECEIVED
}
}

TransactionState.Pending -> {
if (isSentTransaction) {
TransactionExtendedState.SENDING
} else {
TransactionExtendedState.RECEIVING
TransactionState.Pending ->
when {
isShielding -> TransactionExtendedState.SHIELDING
isSentTransaction -> TransactionExtendedState.SENDING
else -> TransactionExtendedState.RECEIVING
}
}

else -> {
error("Unexpected transaction state found while calculating its extended state.")
}
else -> error("Unexpected transaction state found while calculating its extended state.")
}
}
16 changes: 16 additions & 0 deletions ui-lib/src/main/res/ui/account/drawable/ic_trx_shielded_funds.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="19dp"
android:height="18dp"
android:viewportWidth="19"
android:viewportHeight="18">
<group>
<clip-path
android:pathData="M5.979,0l12.774,8.126l-5.979,9.399l-12.774,-8.126z"/>
<path
android:pathData="M16.174,6.853C16.209,6.649 16.121,6.451 15.944,6.339L10.325,2.764C10.215,2.694 10.087,2.672 9.949,2.703C9.811,2.734 9.704,2.808 9.634,2.918C9.565,3.027 9.537,3.164 9.573,3.293C9.601,3.418 9.678,3.538 9.788,3.608L14.04,6.313L4.548,6.367L2.102,6.375C1.84,6.433 1.659,6.698 1.721,6.974C1.782,7.25 2.049,7.408 2.32,7.355L15.792,7.249C15.985,7.206 16.145,7.047 16.174,6.853Z"
android:fillColor="#000000"/>
<path
android:pathData="M17.028,10.56C17,10.436 16.923,10.315 16.813,10.245C16.703,10.176 16.567,10.148 16.437,10.184L2.962,10.276C2.769,10.319 2.609,10.478 2.58,10.673C2.545,10.876 2.633,11.074 2.801,11.181L8.421,14.756C8.53,14.826 8.667,14.853 8.797,14.817C8.921,14.79 9.041,14.712 9.111,14.602C9.181,14.493 9.208,14.356 9.172,14.227C9.145,14.102 9.067,13.982 8.957,13.912L4.815,11.277L16.652,11.151C16.914,11.092 17.094,10.828 17.033,10.552L17.028,10.56Z"
android:fillColor="#000000"/>
</group>
</vector>
3 changes: 3 additions & 0 deletions ui-lib/src/main/res/ui/account/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<string name="account_history_empty">No transaction history</string>

<string name="account_history_item_sent">Sent</string>
<string name="account_history_item_shielded_funds">Shielded Funds</string>
<string name="account_history_item_shielding_funds">Shielding Funds...</string>
<string name="account_history_item_shielding_failed">Shielding Failed...</string>
<string name="account_history_item_received">Received</string>
<string name="account_history_item_sending">Sending…</string>
<string name="account_history_item_receiving">Receiving…</string>
Expand Down