Skip to content

Commit

Permalink
Show transaction filters in separate page
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelekol committed Oct 23, 2023
1 parent 8b2ada1 commit beba535
Show file tree
Hide file tree
Showing 17 changed files with 521 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class App : CoreApp(), WorkConfiguration.Provider, ImageLoaderFactory {
contactsRepository = contactsRepository
)

spamManager = SpamManager()
spamManager = SpamManager(localStorage)

startTasks()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ interface ILocalStorage {
val marketsTabEnabledFlow: StateFlow<Boolean>
var nonRecommendedAccountAlertDismissedAccounts: Set<String>
var personalSupportEnabled: Boolean
var hideUnknownTokens: Boolean
var hideStablecoinsNegligibleAmount: Boolean

fun getSwapProviderId(blockchainType: BlockchainType): String?
fun setSwapProviderId(blockchainType: BlockchainType, providerId: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class LocalStorageManager(
private val PERSONAL_SUPPORT_ENABLED = "personal_support_enabled"
private val APP_ID = "app_id"
private val APP_AUTO_LOCK_INTERVAL = "app_auto_lock_interval"
private val HIDE_UNKNOWN_TOKENS = "hide_unknown_tokens"
private val HIDE_STABLECOINS_NEGLIGIBLE_AMOUNT = "hide_stablecoins_negligible_amount"

private val gson by lazy { Gson() }

Expand Down Expand Up @@ -454,6 +456,18 @@ class LocalStorageManager(
preferences.edit().putBoolean(PERSONAL_SUPPORT_ENABLED, enabled).apply()
}

override var hideUnknownTokens: Boolean
get() = preferences.getBoolean(HIDE_UNKNOWN_TOKENS, true)
set(value) {
preferences.edit().putBoolean(HIDE_UNKNOWN_TOKENS, value).apply()
}

override var hideStablecoinsNegligibleAmount: Boolean
get() = preferences.getBoolean(HIDE_STABLECOINS_NEGLIGIBLE_AMOUNT, true)
set(value) {
preferences.edit().putBoolean(HIDE_STABLECOINS_NEGLIGIBLE_AMOUNT, value).apply()
}

private val _marketsTabEnabledFlow = MutableStateFlow(marketsTabEnabled)
override val marketsTabEnabledFlow = _marketsTabEnabledFlow.asStateFlow()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package io.horizontalsystems.bankwallet.core.managers

import io.horizontalsystems.bankwallet.core.ILocalStorage
import io.horizontalsystems.bankwallet.entities.TransactionValue
import io.horizontalsystems.bankwallet.entities.transactionrecords.evm.TransferEvent
import java.math.BigDecimal

class SpamManager {
class SpamManager(
private val localStorage: ILocalStorage
) {
private val stableCoinCodes = listOf("USDT", "USDC", "DAI", "BUSD", "EURS")
private val negligibleValue = BigDecimal("0.01")

var hideUnknownTokens = localStorage.hideUnknownTokens
private set
var hideStablecoinsDust = localStorage.hideStablecoinsNegligibleAmount
private set

fun isSpam(
incomingEvents: List<TransferEvent>,
outgoingEvents: List<TransferEvent>
Expand All @@ -26,16 +34,26 @@ class SpamManager {
eventValue.value <= BigDecimal.ZERO
}

else -> true
else -> hideUnknownTokens
}
}

private fun spamValue(coinCode: String, value: BigDecimal): Boolean {
return if (stableCoinCodes.contains(coinCode)) {
return if (hideStablecoinsDust && stableCoinCodes.contains(coinCode)) {
value < negligibleValue
} else {
value <= BigDecimal.ZERO
}
}

fun updateFilterHideUnknownTokens(hide: Boolean) {
localStorage.hideUnknownTokens = hide
hideUnknownTokens = hide
}

fun updateFilterHideStablecoinsDust(hide: Boolean) {
localStorage.hideStablecoinsNegligibleAmount = hide
hideStablecoinsDust = hide
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package io.horizontalsystems.bankwallet.modules.transactions

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.Icon
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.navGraphViewModels
import coil.compose.rememberAsyncImagePainter
import io.horizontalsystems.bankwallet.R
import io.horizontalsystems.bankwallet.core.BaseComposeFragment
import io.horizontalsystems.bankwallet.core.imageUrl
import io.horizontalsystems.bankwallet.ui.compose.ComposeAppTheme
import io.horizontalsystems.bankwallet.ui.compose.components.AppBar
import io.horizontalsystems.bankwallet.ui.compose.components.CellMultilineClear
import io.horizontalsystems.bankwallet.ui.compose.components.HsBackButton
import io.horizontalsystems.bankwallet.ui.compose.components.body_leah
import io.horizontalsystems.marketkit.models.Blockchain

class FilterBlockchainFragment : BaseComposeFragment() {

private val viewModel by navGraphViewModels<TransactionsViewModel>(R.id.mainFragment)

@Composable
override fun GetContent(navController: NavController) {
ComposeAppTheme {
FilterBlockchainScreen(navController, viewModel)
}
}
}


@Composable
fun FilterBlockchainScreen(navController: NavController, viewModel: TransactionsViewModel) {
val filterBlockchains by viewModel.filterBlockchainsLiveData.observeAsState()

ComposeAppTheme {
Surface(color = ComposeAppTheme.colors.tyler) {
Column {
AppBar(
title = stringResource(R.string.Transactions_Filter_ChooseBlockchain),
navigationIcon = {
HsBackButton(onClick = navController::popBackStack)
}
)
filterBlockchains?.let { blockchains ->
LazyColumn(
contentPadding = PaddingValues(bottom = 32.dp)
) {
items(blockchains) { filterItem ->
BlockchainCell(viewModel, filterItem, navController)
}
}
}
}
}
}
}

@Composable
private fun BlockchainCell(
viewModel: TransactionsViewModel,
filterItem: Filter<Blockchain?>,
navController: NavController
) {
CellMultilineClear(borderTop = true) {
Row(
modifier = Modifier
.fillMaxSize()
.clickable {
viewModel.onEnterFilterBlockchain(filterItem)
navController.popBackStack()
}
.padding(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
val blockchain = filterItem.item
if (blockchain != null) {
Image(
painter = rememberAsyncImagePainter(
model = blockchain.type.imageUrl,
error = painterResource(R.drawable.ic_platform_placeholder_32)
),
modifier = Modifier
.padding(end = 16.dp)
.size(32.dp),
contentDescription = null
)
body_leah(
modifier = Modifier
.padding(horizontal = 16.dp)
.weight(1f),
text = blockchain.name,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
} else {
Image(
painter = painterResource(R.drawable.icon_24_circle_coin),
modifier = Modifier
.padding(end = 16.dp)
.size(24.dp),
contentDescription = null
)
body_leah(text = stringResource(R.string.Transactions_Filter_AllBlockchains))
}
if (filterItem.selected) {
Spacer(modifier = Modifier.weight(1f))
Icon(
painter = painterResource(R.drawable.icon_20_check_1),
contentDescription = null,
tint = ComposeAppTheme.colors.jacob
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ interface ITransactionRecordRepository : Clearable {
fun setWalletAndBlockchain(transactionWallet: TransactionWallet?, blockchain: Blockchain?)
fun setTransactionType(transactionType: FilterTransactionType)
fun loadNext()
fun reload()
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ class TransactionAdapterWrapper(
subscribeForUpdates()
}

fun reload() {
unsubscribeFromUpdates()
transactionRecords.clear()
allLoaded = false
subscribeForUpdates()
}

fun setTransactionType(transactionType: FilterTransactionType) {
unsubscribeFromUpdates()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package io.horizontalsystems.bankwallet.modules.transactions

import io.horizontalsystems.bankwallet.core.managers.SpamManager
import io.horizontalsystems.bankwallet.entities.Wallet
import io.horizontalsystems.marketkit.models.Blockchain
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update

class TransactionFilterService {
class TransactionFilterService(
private val spamManager: SpamManager,
) {
private var transactionWallets: List<TransactionWallet?> = listOf(null)
var selectedWallet: TransactionWallet? = null
private set
Expand All @@ -17,6 +20,8 @@ class TransactionFilterService {

private val _resetEnabled = MutableStateFlow(false)
val resetEnabled = _resetEnabled.asStateFlow()
val filterHideUnknownTokens = spamManager.hideUnknownTokens
val filterHideStablecoinsDust = spamManager.hideStablecoinsDust

private var blockchains: List<Blockchain?> = listOf(null)

Expand Down Expand Up @@ -91,4 +96,12 @@ class TransactionFilterService {
|| selectedTransactionType != FilterTransactionType.All
}
}

fun setFilterHideUnknownTokens(hide: Boolean) {
spamManager.updateFilterHideUnknownTokens(hide)
}

fun setFilterHideStablecoinsDust(hide: Boolean) {
spamManager.updateFilterHideStablecoinsDust(hide)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ class TransactionRecordRepository(
}
}

override fun reload() {
adaptersMap.forEach { (_, transactionAdapterWrapper) ->
transactionAdapterWrapper.reload()
}
unsubscribeFromUpdates()
allLoaded.set(false)
loadItems(1)
subscribeForUpdates()
}

private fun unsubscribeFromUpdates() {
disposableUpdates?.dispose()
}
Expand Down
Loading

0 comments on commit beba535

Please sign in to comment.