feat(@esktop/wallet): Implemented filter by similar option (#12232)

This commit is contained in:
Cuteivist 2023-09-22 12:57:24 +02:00 committed by GitHub
parent 58ccb01b76
commit 5bf905b91d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 83 additions and 18 deletions

View File

@ -340,4 +340,22 @@ QtObject:
if tokenId > 0: if tokenId > 0:
result.tokenId = some(backend_activity.TokenId("0x" & stint.toHex(tokenId))) result.tokenId = some(backend_activity.TokenId("0x" & stint.toHex(tokenId)))
return result return result
# Fallback, use data from id
var parts = id.split("+")
if len(parts) == 3:
result.chainId = backend_activity.ChainId(parseInt(parts[0]))
result.address = some(eth.fromHex(eth.Address, parts[1]))
var tokenIdInt = u256(parseInt(parts[2]))
result.tokenId = some(backend_activity.TokenId("0x" & stint.toHex(tokenIdInt)))
return result return result
proc getUidForData*(self: Model, tokenId: string, tokenAddress: string, chainId: int): string {.slot.} =
for item in self.items:
if(cmpIgnoreCase(item.getTokenId().toString(), tokenId) == 0 and cmpIgnoreCase(item.getContractAddress(), tokenAddress) == 0):
return item.getId()
# Fallback, create uid from data, because it still might not be fetched
if chainId > 0 and len(tokenAddress) > 0 and len(tokenId) > 0:
return $chainId & "+" & tokenAddress & "+" & tokenId
return ""

View File

@ -163,8 +163,17 @@ Column {
delegate: ActivityFilterTagItem { delegate: ActivityFilterTagItem {
id: collectibleTag id: collectibleTag
property string uid: modelData property string uid: modelData
readonly property bool isValid: tagPrimaryLabel.text.length > 0 readonly property string name: activityFilterStore.collectiblesList.getName(uid)
tagPrimaryLabel.text: activityFilterStore.collectiblesList.getName(uid) readonly property bool isValid: name.length > 0
tagPrimaryLabel.text: {
if (!!name)
return name
// Fallback, get tokenId from uid
const data = uid.split("+")
if (data.length === 3)
return "#" + data[2]
return ""
}
iconAsset.icon: activityFilterStore.collectiblesList.getImageUrl(uid) iconAsset.icon: activityFilterStore.collectiblesList.getImageUrl(uid)
iconAsset.color: "transparent" iconAsset.color: "transparent"
onClosed: activityFilterStore.toggleCollectibles(uid) onClosed: activityFilterStore.toggleCollectibles(uid)
@ -174,7 +183,7 @@ Column {
target: activityFilterStore.collectiblesList target: activityFilterStore.collectiblesList
enabled: !collectibleTag.isValid enabled: !collectibleTag.isValid
function onIsFetchingChanged() { function onIsFetchingChanged() {
if (activityFilterStore.collectiblesList.isFetching) if (activityFilterStore.collectiblesList.isFetching || !activityFilterStore.collectiblesList.hasMore)
return return
collectibleTag.uid = "" collectibleTag.uid = ""
collectibleTag.uid = modelData collectibleTag.uid = modelData

View File

@ -10,6 +10,7 @@ QtObject {
property var transactionsList: walletSection.activityController.model property var transactionsList: walletSection.activityController.model
property bool autoUpdateFilter: true
property var activityController: walletSection.activityController property var activityController: walletSection.activityController
property bool filtersSet: selectedTime !== Constants.TransactionTimePeriod.All || property bool filtersSet: selectedTime !== Constants.TransactionTimePeriod.All ||
typeFilters.length !== 0 || typeFilters.length !== 0 ||
@ -153,16 +154,18 @@ QtObject {
? activityController.noLimitTimestamp ? activityController.noLimitTimestamp
: toTimestamp/1000 : toTimestamp/1000
activityController.setFilterTime(startTimestamp, endTimestamp) activityController.setFilterTime(startTimestamp, endTimestamp)
if (autoUpdateFilter)
activityController.updateFilter() activityController.updateFilter()
} }
// Type Filters // Type Filters
property var typeFilters: [] property var typeFilters: []
function toggleType(type, allFiltersCount) { function toggleType(type, allFiltersCount = 0) {
// update filters // update filters
typeFilters = d.toggleFilterState(typeFilters, type, allFiltersCount) typeFilters = d.toggleFilterState(typeFilters, type, allFiltersCount)
// Set backend values // Set backend values
activityController.setFilterType(JSON.stringify(typeFilters)) activityController.setFilterType(JSON.stringify(typeFilters))
if (autoUpdateFilter)
activityController.updateFilter() activityController.updateFilter()
} }
@ -173,6 +176,7 @@ QtObject {
statusFilters = d.toggleFilterState(statusFilters, status, allFiltersCount) statusFilters = d.toggleFilterState(statusFilters, status, allFiltersCount)
// Set backend values // Set backend values
activityController.setFilterStatus(JSON.stringify(statusFilters)) activityController.setFilterStatus(JSON.stringify(statusFilters))
if (autoUpdateFilter)
activityController.updateFilter() activityController.updateFilter()
} }
@ -184,17 +188,19 @@ QtObject {
tokensFilter = d.toggleFilterState(tokensFilter, symbol, tokensList.count) tokensFilter = d.toggleFilterState(tokensFilter, symbol, tokensList.count)
// Set backend values // Set backend values
activityController.setFilterAssets(JSON.stringify(tokensFilter), false) activityController.setFilterAssets(JSON.stringify(tokensFilter), false)
if (autoUpdateFilter)
activityController.updateFilter() activityController.updateFilter()
} }
// Collectibles Filters // Collectibles Filters
// To-do: Get list of collectibles with activity from backend
property var collectiblesList: walletSection.collectiblesController.model property var collectiblesList: walletSection.collectiblesController.model
property var collectiblesFilter: [] property var collectiblesFilter: []
function toggleCollectibles(uid) { function toggleCollectibles(uid) {
// update filters // update filters
collectiblesFilter = d.toggleFilterState(collectiblesFilter, uid, collectiblesList.count) collectiblesFilter = d.toggleFilterState(collectiblesFilter, uid, collectiblesList.count)
// set backend values
activityController.setFilterCollectibles(JSON.stringify(collectiblesFilter)) activityController.setFilterCollectibles(JSON.stringify(collectiblesFilter))
if (autoUpdateFilter)
activityController.updateFilter() activityController.updateFilter()
} }
@ -208,6 +214,7 @@ QtObject {
// update filters // update filters
recentsFilters = d.toggleFilterState(recentsFilters, address, recentsList.count) recentsFilters = d.toggleFilterState(recentsFilters, address, recentsList.count)
activityController.setFilterToAddresses(JSON.stringify(recentsFilters.concat(savedAddressFilters))) activityController.setFilterToAddresses(JSON.stringify(recentsFilters.concat(savedAddressFilters)))
if (autoUpdateFilter)
activityController.updateFilter() activityController.updateFilter()
} }
@ -236,6 +243,7 @@ QtObject {
savedAddressFilters = d.toggleFilterState(savedAddressFilters, address, savedAddressList.count) savedAddressFilters = d.toggleFilterState(savedAddressFilters, address, savedAddressList.count)
// Set backend values // Set backend values
activityController.setFilterToAddresses(JSON.stringify(recentsFilters.concat(savedAddressFilters))) activityController.setFilterToAddresses(JSON.stringify(recentsFilters.concat(savedAddressFilters)))
if (autoUpdateFilter)
activityController.updateFilter() activityController.updateFilter()
} }
@ -251,6 +259,7 @@ QtObject {
activityController.setFilterToAddresses(JSON.stringify(recentsFilters.concat(savedAddressFilters))) activityController.setFilterToAddresses(JSON.stringify(recentsFilters.concat(savedAddressFilters)))
activityController.setFilterCollectibles(JSON.stringify(collectiblesFilter)) activityController.setFilterCollectibles(JSON.stringify(collectiblesFilter))
if (autoUpdateFilter)
activityController.updateFilter() activityController.updateFilter()
} }

View File

@ -297,12 +297,12 @@ ColumnLayout {
property var transaction property var transaction
property var transactionDelegate property var transactionDelegate
function openMenu(delegate, mouse) { function openMenu(delegate, mouse, data) {
if (!delegate || !delegate.modelData) if (!delegate || !data)
return return
delegateMenu.transactionDelegate = delegate delegateMenu.transactionDelegate = delegate
delegateMenu.transaction = delegate.modelData delegateMenu.transaction = data
repeatTransactionAction.enabled = !overview.isWatchOnlyAccount && delegate.modelData.txType === TransactionDelegate.Send repeatTransactionAction.enabled = !overview.isWatchOnlyAccount && delegate.modelData.txType === TransactionDelegate.Send
popup(delegate, mouse.x, mouse.y) popup(delegate, mouse.x, mouse.y)
} }
@ -338,11 +338,40 @@ ColumnLayout {
} }
StatusAction { StatusAction {
id: filterAction id: filterAction
enabled: false
text: qsTr("Filter by similar") text: qsTr("Filter by similar")
icon.name: "filter" icon.name: "filter"
onTriggered: { onTriggered: {
// TODO apply filter const store = WalletStores.RootStore.currentActivityFiltersStore
const tx = delegateMenu.transaction
store.autoUpdateFilter = false
store.resetAllFilters()
const currentAddress = overview.mixedcaseAddress.toUpperCase()
store.toggleType(tx.txType)
// Contract deployment has always ETH symbol. Symbol doesn't affect this type
if (tx.txType !== Constants.TransactionType.ContractDeployment) {
const symbol = tx.symbol
if (!!symbol)
store.toggleToken(symbol)
const inSymbol = tx.inSymbol
if (!!inSymbol && inSymbol !== symbol)
store.toggleToken(inSymbol)
}
if (showAllAccounts || tx.txType !== Constants.TransactionType.Bridge) {
const recipient = tx.recipient.toUpperCase()
if (!!recipient && recipient !== currentAddress && !/0X0+$/.test(recipient))
store.toggleRecents(recipient)
}
if (tx.isNFT) {
const uid = store.collectiblesList.getUidForData(tx.tokenID, tx.tokenAddress, tx.chainId)
if (!!uid)
store.toggleCollectibles(uid)
}
store.autoUpdateFilter = true
store.applyAllFilters()
} }
} }
} }