From 8febbd1543dbd7c63f1a3723b4aabde9ecd0025c Mon Sep 17 00:00:00 2001 From: Oscar Mira Date: Mon, 4 Mar 2024 02:42:07 +0100 Subject: [PATCH] demo: display balance and enote count in address list --- .../monero/demo/data/model/WalletAddress.kt | 3 ++ .../im/molly/monero/demo/ui/AddressCard.kt | 42 +++++++++++++------ .../im/molly/monero/demo/ui/WalletScreen.kt | 2 +- .../molly/monero/demo/ui/WalletViewModel.kt | 1 + 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/demo/android/src/main/kotlin/im/molly/monero/demo/data/model/WalletAddress.kt b/demo/android/src/main/kotlin/im/molly/monero/demo/data/model/WalletAddress.kt index 89b98b3..9eff05b 100644 --- a/demo/android/src/main/kotlin/im/molly/monero/demo/data/model/WalletAddress.kt +++ b/demo/android/src/main/kotlin/im/molly/monero/demo/data/model/WalletAddress.kt @@ -1,9 +1,12 @@ package im.molly.monero.demo.data.model import im.molly.monero.AccountAddress +import im.molly.monero.Enote +import im.molly.monero.TimeLocked data class WalletAddress( val address: AccountAddress, + val enotes: List>, val used: Boolean, val isLastForAccount: Boolean, ) diff --git a/demo/android/src/main/kotlin/im/molly/monero/demo/ui/AddressCard.kt b/demo/android/src/main/kotlin/im/molly/monero/demo/ui/AddressCard.kt index fec4046..3ab5d3b 100644 --- a/demo/android/src/main/kotlin/im/molly/monero/demo/ui/AddressCard.kt +++ b/demo/android/src/main/kotlin/im/molly/monero/demo/ui/AddressCard.kt @@ -10,8 +10,10 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.draw.alpha import androidx.compose.ui.unit.dp +import im.molly.monero.calculateBalance import im.molly.monero.demo.data.model.WalletAddress import im.molly.monero.demo.ui.component.CopyableText +import im.molly.monero.toFormattedString @Composable fun AddressCardExpanded( @@ -25,29 +27,45 @@ fun AddressCardExpanded( .fillMaxWidth() .padding(horizontal = 16.dp, vertical = 8.dp) ) { + val enotesCount = walletAddress.enotes.count() + val unspentCount = walletAddress.enotes.count { !it.value.spent } + val totalAmount = walletAddress.enotes.calculateBalance().totalAmount + with(walletAddress.address) { - val used = walletAddress.used || isPrimaryAddress - if (isPrimaryAddress) { - Text( - text = "Account #$accountIndex Primary address", - style = MaterialTheme.typography.labelMedium, - ) + val addressText = if (isPrimaryAddress) { + "Account #$accountIndex Primary address" } else { - Text( - text = "Account #$accountIndex Subaddress #$subAddressIndex", - style = MaterialTheme.typography.labelMedium, - ) + "Account #$accountIndex Subaddress #$subAddressIndex" } + + val markedUsed = walletAddress.used || isPrimaryAddress + + Text( + text = addressText, + style = MaterialTheme.typography.bodyMedium, + ) + Text( + text = "Total Balance: ${totalAmount.toFormattedString(appendSymbol = true)}", + style = MaterialTheme.typography.bodySmall, + ) + Text( + text = "Total owned enotes: $enotesCount", + style = MaterialTheme.typography.bodySmall, + ) + Text( + text = "Unspent enotes: $unspentCount", + style = MaterialTheme.typography.bodySmall, + ) CopyableText( text = address, style = MaterialTheme.typography.bodyMedium, - modifier = if (used) Modifier.alpha(0.5f) else Modifier, + modifier = if (markedUsed) Modifier.alpha(0.5f) else Modifier, ) if (walletAddress.isLastForAccount) { TextButton(onClick = onCreateSubAddressClick) { Text( text = "Add subaddress", - style = MaterialTheme.typography.bodySmall, + style = MaterialTheme.typography.bodyMedium, ) } } diff --git a/demo/android/src/main/kotlin/im/molly/monero/demo/ui/WalletScreen.kt b/demo/android/src/main/kotlin/im/molly/monero/demo/ui/WalletScreen.kt index 25fa7bd..7d104ec 100644 --- a/demo/android/src/main/kotlin/im/molly/monero/demo/ui/WalletScreen.kt +++ b/demo/android/src/main/kotlin/im/molly/monero/demo/ui/WalletScreen.kt @@ -225,7 +225,7 @@ private fun WalletScreenLoaded( ) { Text( text = "Create new account", - style = MaterialTheme.typography.bodySmall, + style = MaterialTheme.typography.bodyMedium, ) } } diff --git a/demo/android/src/main/kotlin/im/molly/monero/demo/ui/WalletViewModel.kt b/demo/android/src/main/kotlin/im/molly/monero/demo/ui/WalletViewModel.kt index 65d2328..693234c 100644 --- a/demo/android/src/main/kotlin/im/molly/monero/demo/ui/WalletViewModel.kt +++ b/demo/android/src/main/kotlin/im/molly/monero/demo/ui/WalletViewModel.kt @@ -82,6 +82,7 @@ private fun walletUiState( account.addresses.map { address -> WalletAddress( address = address, + enotes = ledger.enoteSet.filter { it.value.owner == address }, used = address.isAddressUsed(ledger.transactions), isLastForAccount = address === account.addresses.last(), )