Skip to content

Commit

Permalink
Hide transactions amount on balance hide
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelekol committed Oct 6, 2023
1 parent 08c471b commit b0089b2
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TokenBalanceModule {
balanceService,
BalanceViewItemFactory(),
tokenTransactionsService,
TransactionViewItemFactory(App.evmLabelManager, App.contactsRepository),
TransactionViewItemFactory(App.evmLabelManager, App.contactsRepository, App.balanceHiddenManager),
App.balanceHiddenManager,
App.connectivityManager
) as T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.horizontalsystems.bankwallet.modules.transactions

import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.core.App
import io.horizontalsystems.bankwallet.core.managers.BalanceHiddenManager
import io.horizontalsystems.bankwallet.core.managers.EvmLabelManager
import io.horizontalsystems.bankwallet.core.providers.Translator
import io.horizontalsystems.bankwallet.entities.CurrencyValue
Expand Down Expand Up @@ -42,11 +43,24 @@ import java.util.Date

class TransactionViewItemFactory(
private val evmLabelManager: EvmLabelManager,
private val contactsRepository: ContactsRepository
private val contactsRepository: ContactsRepository,
private val balanceHiddenManager: BalanceHiddenManager,
) {

private val cache = mutableMapOf<String, Map<Long, TransactionViewItem>>()

fun updateCache() {
cache.forEach { (recordUid, map) ->
map.forEach { (createdAt, viewItem) ->
cache[recordUid] = mapOf(
createdAt to viewItem.copy(
showAmount = !balanceHiddenManager.balanceHidden,
)
)
}
}
}

fun convertToViewItemCached(transactionItem: TransactionItem): TransactionViewItem {
cache[transactionItem.record.uid]?.get(transactionItem.createdAt)?.let {
return it
Expand All @@ -66,6 +80,7 @@ class TransactionViewItemFactory(
is TransactionValue.NftValue -> {
TransactionViewItem.Icon.Regular(nftMetadata[value.nftUid]?.previewImageUrl, R.drawable.icon_24_nft_placeholder, rectangle = true)
}

is TransactionValue.CoinValue,
is TransactionValue.RawValue,
is TransactionValue.TokenValue -> {
Expand All @@ -92,6 +107,7 @@ class TransactionViewItemFactory(
frontUrl = nftMetadata[primaryValue.nftUid]?.previewImageUrl
frontPlaceHolder = R.drawable.icon_24_nft_placeholder
}

is TransactionValue.CoinValue,
is TransactionValue.RawValue,
is TransactionValue.TokenValue -> {
Expand All @@ -113,6 +129,7 @@ class TransactionViewItemFactory(
backUrl = nftMetadata[secondaryValue.nftUid]?.previewImageUrl
backPlaceHolder = R.drawable.icon_24_nft_placeholder
}

is TransactionValue.CoinValue,
is TransactionValue.RawValue,
is TransactionValue.TokenValue -> {
Expand Down Expand Up @@ -142,12 +159,15 @@ class TransactionViewItemFactory(
incomingValues.size == 1 && outgoingValues.isEmpty() -> {
singleValueIconType(incomingValues[0], nftMetadata)
}

incomingValues.isEmpty() && outgoingValues.size == 1 -> {
singleValueIconType(outgoingValues[0], nftMetadata)
}

incomingValues.size == 1 && outgoingValues.size == 1 -> {
doubleValueIconType(incomingValues[0], outgoingValues[0], nftMetadata)
}

else -> {
TransactionViewItem.Icon.Platform(blockchainType)
}
Expand Down Expand Up @@ -185,26 +205,30 @@ class TransactionViewItemFactory(
progress,
icon
)

is BinanceChainOutgoingTransactionRecord -> createViewItemFromBinanceChainOutgoingTransactionRecord(
record,
transactionItem.currencyValue,
progress,
icon
)

is BitcoinIncomingTransactionRecord -> createViewItemFromBitcoinIncomingTransactionRecord(
record,
transactionItem.currencyValue,
progress,
lastBlockTimestamp,
icon
)

is BitcoinOutgoingTransactionRecord -> createViewItemFromBitcoinOutgoingTransactionRecord(
record,
transactionItem.currencyValue,
progress,
lastBlockTimestamp,
icon
)

is ContractCallTransactionRecord -> {
val (incomingValues, outgoingValues) = EvmTransactionRecord.combined(record.incomingEvents, record.outgoingEvents)
createViewItemFromContractCallTransactionRecord(
Expand All @@ -221,6 +245,7 @@ class TransactionViewItemFactory(
nftMetadata = transactionItem.nftMetadata
)
}

is ExternalContractCallTransactionRecord -> {
val (incomingValues, outgoingValues) = EvmTransactionRecord.combined(record.incomingEvents, record.outgoingEvents)
createViewItemFromExternalContractCallTransactionRecord(
Expand Down Expand Up @@ -384,6 +409,7 @@ class TransactionViewItemFactory(
icon = icon
)
}

else -> throw IllegalArgumentException("Undefined record type ${record.javaClass.name}")
}
}
Expand All @@ -405,6 +431,7 @@ class TransactionViewItemFactory(
subtitle = Translator.getString(R.string.Transactions_Unknown_Description),
primaryValue = primaryValue,
secondaryValue = secondaryValue,
showAmount = !balanceHiddenManager.balanceHidden,
date = Date(record.timestamp * 1000),
icon = icon ?: iconType(record.blockchainType, incomingValues, outgoingValues, mutableMapOf())
)
Expand All @@ -431,6 +458,7 @@ class TransactionViewItemFactory(
subtitle = record.to?.let { to -> Translator.getString(R.string.Transactions_To, mapped(to, record.blockchainType)) } ?: "",
primaryValue = primaryValue,
secondaryValue = secondaryValue,
showAmount = !balanceHiddenManager.balanceHidden,
date = Date(record.timestamp * 1000),
sentToSelf = record.sentToSelf,
icon = icon ?: singleValueIconType(record.value, nftMetadata)
Expand All @@ -454,6 +482,7 @@ class TransactionViewItemFactory(
subtitle = record.from?.let { from -> Translator.getString(R.string.Transactions_From, mapped(from, record.blockchainType)) } ?: "",
primaryValue = primaryValue,
secondaryValue = secondaryValue,
showAmount = !balanceHiddenManager.balanceHidden,
date = Date(record.timestamp * 1000),
icon = icon ?: singleValueIconType(record.value)
)
Expand Down Expand Up @@ -484,6 +513,7 @@ class TransactionViewItemFactory(
subtitle = mapped(record.exchangeAddress, record.blockchainType),
primaryValue = primaryValue,
secondaryValue = secondaryValue,
showAmount = !balanceHiddenManager.balanceHidden,
date = Date(record.timestamp * 1000),
icon = icon ?: doubleValueIconType(record.valueOut, record.valueIn)
)
Expand All @@ -504,6 +534,7 @@ class TransactionViewItemFactory(
subtitle = mapped(record.exchangeAddress, record.blockchainType),
primaryValue = primaryValue,
secondaryValue = secondaryValue,
showAmount = !balanceHiddenManager.balanceHidden,
date = Date(record.timestamp * 1000),
icon = icon ?: doubleValueIconType(record.valueOut, record.valueIn)
)
Expand Down Expand Up @@ -574,6 +605,7 @@ class TransactionViewItemFactory(
subtitle = Translator.getString(R.string.Transactions_To, mapped(to, blockchainType)),
primaryValue = primaryValue,
secondaryValue = secondaryValue,
showAmount = !balanceHiddenManager.balanceHidden,
date = Date(timestamp * 1000),
sentToSelf = sentToSelf,
icon = icon ?: singleValueIconType(value, nftMetadata)
Expand Down Expand Up @@ -612,6 +644,7 @@ class TransactionViewItemFactory(
),
primaryValue = primaryValue,
secondaryValue = secondaryValue,
showAmount = !balanceHiddenManager.balanceHidden,
date = Date(timestamp * 1000),
icon = icon ?: singleValueIconType(value)
)
Expand Down Expand Up @@ -657,6 +690,7 @@ class TransactionViewItemFactory(
subtitle = mapped(contractAddress, blockchainType),
primaryValue = primaryValue,
secondaryValue = secondaryValue,
showAmount = !balanceHiddenManager.balanceHidden,
date = Date(timestamp * 1000),
icon = icon ?: iconType(blockchainType, incomingValues, outgoingValues, nftMetadata)
)
Expand Down Expand Up @@ -707,6 +741,7 @@ class TransactionViewItemFactory(
subtitle = subTitle,
primaryValue = primaryValue,
secondaryValue = secondaryValue,
showAmount = !balanceHiddenManager.balanceHidden,
date = Date(timestamp * 1000),
icon = icon ?: iconType(blockchainType, incomingValues, outgoingValues, nftMetadata)
)
Expand Down Expand Up @@ -750,6 +785,7 @@ class TransactionViewItemFactory(
subtitle = subtitle,
primaryValue = primaryValue,
secondaryValue = secondaryValue,
showAmount = !balanceHiddenManager.balanceHidden,
date = Date(record.timestamp * 1000),
sentToSelf = record.sentToSelf,
doubleSpend = record.conflictingHash != null,
Expand Down Expand Up @@ -791,6 +827,7 @@ class TransactionViewItemFactory(
subtitle = subtitle,
primaryValue = primaryValue,
secondaryValue = secondaryValue,
showAmount = !balanceHiddenManager.balanceHidden,
date = Date(record.timestamp * 1000),
sentToSelf = false,
doubleSpend = record.conflictingHash != null,
Expand Down Expand Up @@ -822,6 +859,7 @@ class TransactionViewItemFactory(
subtitle = Translator.getString(R.string.Transactions_To, mapped(record.to, record.blockchainType)),
primaryValue = primaryValue,
secondaryValue = secondaryValue,
showAmount = !balanceHiddenManager.balanceHidden,
date = Date(record.timestamp * 1000),
sentToSelf = record.sentToSelf,
icon = icon ?: singleValueIconType(record.value)
Expand Down Expand Up @@ -849,6 +887,7 @@ class TransactionViewItemFactory(
),
primaryValue = primaryValue,
secondaryValue = secondaryValue,
showAmount = !balanceHiddenManager.balanceHidden,
date = Date(record.timestamp * 1000),
icon = icon ?: singleValueIconType(record.value)
)
Expand Down Expand Up @@ -885,6 +924,7 @@ class TransactionViewItemFactory(
subtitle = mapped(spender, blockchainType),
primaryValue = primaryValue,
secondaryValue = secondaryValue,
showAmount = !balanceHiddenManager.balanceHidden,
date = Date(timestamp * 1000),
icon = icon ?: singleValueIconType(value)
)
Expand All @@ -900,6 +940,7 @@ class TransactionViewItemFactory(
val text = nftMetadata[value.nftUid]?.name ?: value.tokenName?.let { "$it #${value.nftUid.tokenId}" } ?: "#${value.nftUid.tokenId}"
getColoredValue(text, ColorName.Grey)
}

is TransactionValue.CoinValue,
is TransactionValue.RawValue,
is TransactionValue.TokenValue -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ object TransactionsModule {
TransactionFilterService(),
NftMetadataService(App.nftMetadataManager)
),
TransactionViewItemFactory(App.evmLabelManager, App.contactsRepository)
TransactionViewItemFactory(App.evmLabelManager, App.contactsRepository, App.balanceHiddenManager),
App.balanceHiddenManager
) as T
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,18 @@ fun TransactionCell(item: TransactionViewItem, position: SectionItemPosition, on
maxLines = 1,
)
Spacer(Modifier.weight(1f))
item.primaryValue?.let { coloredValue ->
Text(
text = coloredValue.value,
style = ComposeAppTheme.typography.body,
color = coloredValue.color.compose(),
overflow = TextOverflow.Ellipsis,
maxLines = 1,
)
if (item.showAmount) {
item.primaryValue?.let { coloredValue ->
Text(
text = coloredValue.value,
style = ComposeAppTheme.typography.body,
color = coloredValue.color.compose(),
overflow = TextOverflow.Ellipsis,
maxLines = 1,
)
}
}

if (item.doubleSpend) {
Image(
modifier = Modifier.padding(start = 6.dp),
Expand Down Expand Up @@ -399,13 +402,15 @@ fun TransactionCell(item: TransactionViewItem, position: SectionItemPosition, on
.padding(end = 8.dp),
maxLines = 2,
)
item.secondaryValue?.let { coloredValue ->
Text(
text = coloredValue.value,
style = ComposeAppTheme.typography.subhead2,
color = coloredValue.color.compose(),
maxLines = 1,
)
if (item.showAmount) {
item.secondaryValue?.let { coloredValue ->
Text(
text = coloredValue.value,
style = ComposeAppTheme.typography.subhead2,
color = coloredValue.color.compose(),
maxLines = 1,
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TransactionsService(
private val transactionAdapterManager: TransactionAdapterManager,
private val walletManager: IWalletManager,
private val transactionFilterService: TransactionFilterService,
private val nftMetadataService: NftMetadataService
private val nftMetadataService: NftMetadataService,
) : Clearable {
val filterResetEnabled by transactionFilterService::resetEnabled

Expand Down Expand Up @@ -274,6 +274,10 @@ class TransactionsService(

private val executorService = Executors.newCachedThreadPool()

fun refreshList() {
itemsSubject.onNext(transactionItems)
}

fun setFilterType(f: FilterTransactionType) {
executorService.submit {
typesSubject.onNext(Pair(transactionFilterService.getFilterTypes(), f))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package io.horizontalsystems.bankwallet.modules.transactions

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.core.managers.BalanceHiddenManager
import io.horizontalsystems.bankwallet.core.providers.Translator
import io.horizontalsystems.bankwallet.core.subscribeIO
import io.horizontalsystems.bankwallet.entities.CurrencyValue
Expand All @@ -16,12 +18,15 @@ import io.horizontalsystems.core.helpers.DateHelper
import io.horizontalsystems.marketkit.models.Blockchain
import io.horizontalsystems.marketkit.models.BlockchainType
import io.reactivex.disposables.CompositeDisposable
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.Calendar
import java.util.Date

class TransactionsViewModel(
private val service: TransactionsService,
private val transactionViewItem2Factory: TransactionViewItemFactory
private val transactionViewItem2Factory: TransactionViewItemFactory,
private val balanceHiddenManager: BalanceHiddenManager
) : ViewModel() {

var tmpItemToShow: TransactionItem? = null
Expand Down Expand Up @@ -90,6 +95,13 @@ class TransactionsViewModel(
.let {
disposables.add(it)
}

viewModelScope.launch(Dispatchers.IO) {
balanceHiddenManager.balanceHiddenFlow.collect {
transactionViewItem2Factory.updateCache()
service.refreshList()
}
}
}

fun setFilterTransactionType(filterType: FilterTransactionType) {
Expand Down Expand Up @@ -142,6 +154,7 @@ data class TransactionViewItem(
val primaryValue: ColoredValue?,
val secondaryValue: ColoredValue?,
val date: Date,
val showAmount: Boolean = true,
val sentToSelf: Boolean = false,
val doubleSpend: Boolean = false,
val locked: Boolean? = null,
Expand Down

0 comments on commit b0089b2

Please sign in to comment.