fix(wallet): implement sort collectibles by date

Fixes #13550
This commit is contained in:
Dario Gabriel Lipicar 2024-02-15 09:59:34 -03:00 committed by dlipicar
parent 1315911587
commit 1860aa8240
4 changed files with 138 additions and 39 deletions

View File

@ -242,16 +242,6 @@ QtObject:
read = getOwnershipModel read = getOwnershipModel
notify = ownershipChanged notify = ownershipChanged
proc ownershipAddressesChanged*(self: CollectiblesEntry) {.signal.}
proc getOwnershipAddresses*(self: CollectiblesEntry): string {.slot.} =
if not self.hasOwnership():
return ""
return self.getOwnership().map(o => o.address).join(":")
QtProperty[string] ownershipAddresses:
read = getOwnershipAddresses
notify = ownershipAddressesChanged
proc communityIdChanged*(self: CollectiblesEntry) {.signal.} proc communityIdChanged*(self: CollectiblesEntry) {.signal.}
proc getCommunityID*(self: CollectiblesEntry): string {.slot.} = proc getCommunityID*(self: CollectiblesEntry): string {.slot.} =
if not self.hasCommunityData(): if not self.hasCommunityData():

View File

@ -24,7 +24,6 @@ type
CollectionSlug CollectionSlug
IsLoading IsLoading
Ownership Ownership
OwnershipAddresses
# Community-related roles # Community-related roles
CommunityId CommunityId
CommunityName CommunityName
@ -146,7 +145,6 @@ QtObject:
CollectibleRole.CollectionSlug.int:"collectionSlug", CollectibleRole.CollectionSlug.int:"collectionSlug",
CollectibleRole.IsLoading.int:"isLoading", CollectibleRole.IsLoading.int:"isLoading",
CollectibleRole.Ownership.int:"ownership", CollectibleRole.Ownership.int:"ownership",
CollectibleRole.OwnershipAddresses.int:"ownershipAddresses",
CollectibleRole.CommunityId.int:"communityId", CollectibleRole.CommunityId.int:"communityId",
CollectibleRole.CommunityName.int:"communityName", CollectibleRole.CommunityName.int:"communityName",
CollectibleRole.CommunityColor.int:"communityColor", CollectibleRole.CommunityColor.int:"communityColor",
@ -193,8 +191,6 @@ QtObject:
result = newQVariant(false) result = newQVariant(false)
of CollectibleRole.Ownership: of CollectibleRole.Ownership:
result = newQVariant(item.getOwnershipModel()) result = newQVariant(item.getOwnershipModel())
of CollectibleRole.OwnershipAddresses:
result = newQVariant(item.getOwnershipAddresses())
of CollectibleRole.CommunityId: of CollectibleRole.CommunityId:
result = newQVariant(item.getCommunityId()) result = newQVariant(item.getCommunityId())
of CollectibleRole.CommunityName: of CollectibleRole.CommunityName:
@ -222,7 +218,6 @@ QtObject:
of "collectionName": result = item.getCollectionName() of "collectionName": result = item.getCollectionName()
of "collectionSlug": result = item.getCollectionSlug() of "collectionSlug": result = item.getCollectionSlug()
of "isLoading": result = $false of "isLoading": result = $false
of "ownershipAddresses": result = item.getOwnershipAddresses()
of "communityId": result = item.getCommunityID() of "communityId": result = item.getCommunityID()
of "communityName": result = item.getCommunityName() of "communityName": result = item.getCommunityName()
of "communityColor": result = item.getCommunityColor() of "communityColor": result = item.getCommunityColor()

View File

@ -28,7 +28,18 @@ ListModel {
imageUrl: ModelsData.collectibles.cryptoPunks, imageUrl: ModelsData.collectibles.cryptoPunks,
isLoading: false, isLoading: false,
backgroundColor: "", backgroundColor: "",
ownershipAddresses: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240:0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8881" ownership: [
{
accountAddress: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240",
balance: 1,
txTimestamp: 1
},
{
accountAddress: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8881",
balance: 1,
txTimestamp: 2
},
]
}, },
{ {
uid: "pp23", uid: "pp23",
@ -42,7 +53,13 @@ ListModel {
imageUrl: "https://i.seadn.io/s/raw/files/ba2811bb5cd0bed67529d69fa92ef5aa.jpg?auto=format&dpr=1&w=1000", imageUrl: "https://i.seadn.io/s/raw/files/ba2811bb5cd0bed67529d69fa92ef5aa.jpg?auto=format&dpr=1&w=1000",
isLoading: false, isLoading: false,
backgroundColor: "", backgroundColor: "",
ownershipAddresses: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240" ownership: [
{
accountAddress: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240",
balance: 1,
txTimestamp: 3
},
]
}, },
{ {
uid: "34545656768", uid: "34545656768",
@ -56,7 +73,13 @@ ListModel {
imageUrl: ModelsData.collectibles.kitty1Big, imageUrl: ModelsData.collectibles.kitty1Big,
isLoading: true, isLoading: true,
backgroundColor: "", backgroundColor: "",
ownershipAddresses: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8881" ownership: [
{
accountAddress: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8881",
balance: 1,
txTimestamp: 3
},
]
}, },
{ {
uid: "123456", uid: "123456",
@ -70,7 +93,13 @@ ListModel {
imageUrl: ModelsData.collectibles.kitty2Big, imageUrl: ModelsData.collectibles.kitty2Big,
isLoading: false, isLoading: false,
backgroundColor: "", backgroundColor: "",
ownershipAddresses: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240" ownership: [
{
accountAddress: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240",
balance: 1,
txTimestamp: 6
},
]
}, },
{ {
uid: "12345645459537432", uid: "12345645459537432",
@ -84,7 +113,18 @@ ListModel {
imageUrl: ModelsData.collectibles.kitty3Big, imageUrl: ModelsData.collectibles.kitty3Big,
isLoading: false, isLoading: false,
backgroundColor: "", backgroundColor: "",
ownershipAddresses: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240:0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8881" ownership: [
{
accountAddress: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240",
balance: 1,
txTimestamp: 50
},
{
accountAddress: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8881",
balance: 1,
txTimestamp: 10
},
]
}, },
{ {
uid: "pp21", uid: "pp21",
@ -98,7 +138,13 @@ ListModel {
imageUrl: "https://i.seadn.io/s/raw/files/cfa559bb63e4378f17649c1e3b8f18fe.jpg?auto=format&dpr=1&w=1000", imageUrl: "https://i.seadn.io/s/raw/files/cfa559bb63e4378f17649c1e3b8f18fe.jpg?auto=format&dpr=1&w=1000",
isLoading: false, isLoading: false,
backgroundColor: "", backgroundColor: "",
ownershipAddresses: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8881" ownership: [
{
accountAddress: "0x7F47C2e98a4BBf5487E6fb082eC2D9Ab0E6d8881",
balance: 1,
txTimestamp: 16
},
]
}, },
{ {
uid: "lp#666a", uid: "lp#666a",
@ -112,7 +158,13 @@ ListModel {
imageUrl: "", imageUrl: "",
isLoading: false, isLoading: false,
backgroundColor: "pink", backgroundColor: "pink",
ownershipAddresses: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240" ownership: [
{
accountAddress: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240",
balance: 1,
txTimestamp: 19
},
]
}, },
] ]
@ -129,7 +181,13 @@ ListModel {
imageUrl: "https://i.seadn.io/gae/qPfQjj4P1w0xVQXAmQJLmQ4ZtLFAJU6oiH69Lsny82LFbipLAgXhHKrcLBx2U09SmRnzeHY0ygz-3NIb-JegE_hWrZquFeL-qUPXPdw", imageUrl: "https://i.seadn.io/gae/qPfQjj4P1w0xVQXAmQJLmQ4ZtLFAJU6oiH69Lsny82LFbipLAgXhHKrcLBx2U09SmRnzeHY0ygz-3NIb-JegE_hWrZquFeL-qUPXPdw",
isLoading: false, isLoading: false,
backgroundColor: "pink", backgroundColor: "pink",
ownershipAddresses: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240" ownership: [
{
accountAddress: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240",
balance: 1,
txTimestamp: 20
},
]
}, },
{ {
uid: "691", uid: "691",
@ -143,7 +201,13 @@ ListModel {
imageUrl: "https://assets.killabears.com/content/killabears/gif/691-e81f892696a8ae700e0dbc62eb072060679a2046d1ef5eb2671bdb1fad1f68e3.gif", imageUrl: "https://assets.killabears.com/content/killabears/gif/691-e81f892696a8ae700e0dbc62eb072060679a2046d1ef5eb2671bdb1fad1f68e3.gif",
isLoading: true, isLoading: true,
backgroundColor: "navy", backgroundColor: "navy",
ownershipAddresses: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240" ownership: [
{
accountAddress: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240",
balance: 1,
txTimestamp: 21
},
]
}, },
{ {
uid: "8876", uid: "8876",
@ -157,7 +221,13 @@ ListModel {
imageUrl: "https://assets.killabears.com/content/killabears/transparent-512/2385-86ba13cc6945ed0aea7c32a363a96be2f218898358745ae07b947452cb7e4e79.png", imageUrl: "https://assets.killabears.com/content/killabears/transparent-512/2385-86ba13cc6945ed0aea7c32a363a96be2f218898358745ae07b947452cb7e4e79.png",
isLoading: false, isLoading: false,
backgroundColor: "pink", backgroundColor: "pink",
ownershipAddresses: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240" ownership: [
{
accountAddress: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240",
balance: 1,
txTimestamp: 22
},
]
}, },
{ {
uid: "fp#3195", uid: "fp#3195",
@ -171,7 +241,13 @@ ListModel {
imageUrl: "https://i.seadn.io/s/raw/files/59ad1f2e3c5eb5d4b62c06e200076514.png", imageUrl: "https://i.seadn.io/s/raw/files/59ad1f2e3c5eb5d4b62c06e200076514.png",
isLoading: false, isLoading: false,
backgroundColor: "", backgroundColor: "",
ownershipAddresses: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240" ownership: [
{
accountAddress: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240",
balance: 1,
txTimestamp: 23
},
]
}, },
{ {
uid: "fp#4297", uid: "fp#4297",
@ -185,7 +261,13 @@ ListModel {
imageUrl: "https://i.seadn.io/gae/K4_vmYtXAqU6LTnGDliLtJZc4UPmf9jUlk09_FDbXvSKKyUARyyV9RQEgXdb5bjje5OE9j9ZryC5pzcwBwH7TDOIl8oq7D2tSJ7p", imageUrl: "https://i.seadn.io/gae/K4_vmYtXAqU6LTnGDliLtJZc4UPmf9jUlk09_FDbXvSKKyUARyyV9RQEgXdb5bjje5OE9j9ZryC5pzcwBwH7TDOIl8oq7D2tSJ7p",
isLoading: false, isLoading: false,
backgroundColor: "", backgroundColor: "",
ownershipAddresses: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240" ownership: [
{
accountAddress: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240",
balance: 1,
txTimestamp: 25
},
]
}, },
{ {
uid: "fp#909", uid: "fp#909",
@ -199,7 +281,13 @@ ListModel {
imageUrl: "https://i.seadn.io/gae/cR-Bjmb6DsrywCJMOqEBPkkrMHjbTzeRSAKIvLpd7i8ss6raYZ3-doh8oF2z8bJsnmfC1oR3kllz6UxMfFaYAKdXYzXlhfVsDHo6bg", imageUrl: "https://i.seadn.io/gae/cR-Bjmb6DsrywCJMOqEBPkkrMHjbTzeRSAKIvLpd7i8ss6raYZ3-doh8oF2z8bJsnmfC1oR3kllz6UxMfFaYAKdXYzXlhfVsDHo6bg",
isLoading: false, isLoading: false,
backgroundColor: "", backgroundColor: "",
ownershipAddresses: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240" ownership: [
{
accountAddress: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240",
balance: 1,
txTimestamp: 26
},
]
}, },
{ {
uid: "lb#666", uid: "lb#666",
@ -213,7 +301,13 @@ ListModel {
imageUrl: "", imageUrl: "",
isLoading: false, isLoading: false,
backgroundColor: "pink", backgroundColor: "pink",
ownershipAddresses: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240" ownership: [
{
accountAddress: "0x7F47C2e18a4BBf5487E6fb082eC2D9Ab0E6d7240",
balance: 1,
txTimestamp: 27
},
]
}, },
] ]

View File

@ -124,14 +124,27 @@ ColumnLayout {
readonly property var nwFilters: root.networkFilters.split(":") readonly property var nwFilters: root.networkFilters.split(":")
readonly property var addrFilters: root.addressFilters.split(":").map((addr) => addr.toLowerCase()) readonly property var addrFilters: root.addressFilters.split(":").map((addr) => addr.toLowerCase())
function containsAny(list, filterList) { function containsAnyAddress(ownership, filterList) {
for (let i = 0; i < list.length; i++) { for (let i = 0; i < ownership.count; i++) {
if (filterList.includes(list[i].toLowerCase())) { let accountAddress = ModelUtils.get(ownership, i, "accountAddress").toLowerCase()
if (filterList.includes(accountAddress)) {
return true return true
} }
} }
return false return false
} }
function getLatestTimestmap(ownership, filterList) {
let latest = 0
for (let i = 0; i < ownership.count; i++) {
let accountAddress = ModelUtils.get(ownership, i, "accountAddress").toLowerCase()
if (filterList.includes(accountAddress)) {
let txTimestamp = ModelUtils.get(ownership, i, "txTimestamp")
latest = Math.max(latest, txTimestamp)
}
}
return latest
}
} }
component CustomSFPM: SortFilterProxyModel { component CustomSFPM: SortFilterProxyModel {
@ -139,17 +152,24 @@ ColumnLayout {
property bool isCommunity property bool isCommunity
sourceModel: d.sourceModel sourceModel: d.sourceModel
proxyRoles: JoinRole { proxyRoles: [
name: "groupName" JoinRole {
roleNames: ["collectionName", "communityName"] name: "groupName"
} roleNames: ["collectionName", "communityName"]
},
FastExpressionRole {
name: "lastTxTimestamp"
expression: d.addrFilters, d.getLatestTimestmap(model.ownership, d.addrFilters)
expectedRoles: ["ownership"]
}
]
filters: [ filters: [
FastExpressionFilter { FastExpressionFilter {
expression: { expression: {
d.addrFilters d.addrFilters
return d.nwFilters.includes(model.chainId+"") && d.containsAny(model.ownershipAddresses.split(":"), d.addrFilters) return d.nwFilters.includes(model.chainId+"") && d.containsAnyAddress(model.ownership, d.addrFilters)
} }
expectedRoles: ["chainId", "ownershipAddresses"] expectedRoles: ["chainId", "ownership"]
}, },
FastExpressionFilter { FastExpressionFilter {
expression: { expression: {
@ -249,7 +269,7 @@ ColumnLayout {
id: cmbTokenOrder id: cmbTokenOrder
hasCustomOrderDefined: root.controller.hasSettings hasCustomOrderDefined: root.controller.hasSettings
model: [ model: [
{ value: SortOrderComboBox.TokenOrderDateAdded, text: qsTr("Date added"), icon: "calendar", sortRoleName: "dateAdded" }, // FIXME sortRoleName #12942 { value: SortOrderComboBox.TokenOrderDateAdded, text: qsTr("Date added"), icon: "calendar", sortRoleName: "lastTxTimestamp" }, // Custom SFPM role
{ value: SortOrderComboBox.TokenOrderAlpha, text: qsTr("Collectible name"), icon: "bold", sortRoleName: "name" }, { value: SortOrderComboBox.TokenOrderAlpha, text: qsTr("Collectible name"), icon: "bold", sortRoleName: "name" },
{ value: SortOrderComboBox.TokenOrderGroupName, text: qsTr("Collection/community name"), icon: "group", sortRoleName: "groupName" }, // Custom SFPM role communityName || collectionName { value: SortOrderComboBox.TokenOrderGroupName, text: qsTr("Collection/community name"), icon: "group", sortRoleName: "groupName" }, // Custom SFPM role communityName || collectionName
{ value: SortOrderComboBox.TokenOrderCustom, text: qsTr("Custom order"), icon: "exchange", sortRoleName: "" }, { value: SortOrderComboBox.TokenOrderCustom, text: qsTr("Custom order"), icon: "exchange", sortRoleName: "" },