chore(CommunityPermissions): Use enum for token category, keep string labels in UI only

Closes: #9556
This commit is contained in:
Michał Cieślak 2023-02-15 22:45:37 +01:00 committed by Michał
parent bb23131f0e
commit c05334c327
7 changed files with 165 additions and 71 deletions

View File

@ -1,5 +1,7 @@
import QtQuick 2.0 import QtQuick 2.0
import AppLayouts.Chat.controls.community 1.0
ListModel { ListModel {
Component.onCompleted: Component.onCompleted:
append([ append([
@ -8,35 +10,35 @@ ListModel {
iconSource: ModelsData.assets.socks, iconSource: ModelsData.assets.socks,
name: "Unisocks", name: "Unisocks",
shortName: "SOCKS", shortName: "SOCKS",
category: "Community assets" category: TokenCategories.Category.Community
}, },
{ {
key: "zrx", key: "zrx",
iconSource: ModelsData.assets.zrx, iconSource: ModelsData.assets.zrx,
name: "Ox", name: "Ox",
shortName: "ZRX", shortName: "ZRX",
category: "Listed assets" category: TokenCategories.Category.Own
}, },
{ {
key: "1inch", key: "1inch",
iconSource: ModelsData.assets.inch, iconSource: ModelsData.assets.inch,
name: "1inch", name: "1inch",
shortName: "1INCH", shortName: "1INCH",
category: "Listed assets" category: TokenCategories.Category.Own
}, },
{ {
key: "Aave", key: "Aave",
iconSource: ModelsData.assets.aave, iconSource: ModelsData.assets.aave,
name: "Aave", name: "Aave",
shortName: "AAVE", shortName: "AAVE",
category: "Listed assets" category: TokenCategories.Category.Own
}, },
{ {
key: "Amp", key: "Amp",
iconSource: ModelsData.assets.amp, iconSource: ModelsData.assets.amp,
name: "Amp", name: "Amp",
shortName: "AMP", shortName: "AMP",
category: "Listed assets" category: TokenCategories.Category.Own
} }
]) ])
} }

View File

@ -1,4 +1,6 @@
import QtQuick 2.0 import QtQuick 2.15
import AppLayouts.Chat.controls.community 1.0
ListModel { ListModel {
Component.onCompleted: Component.onCompleted:
@ -7,13 +9,13 @@ ListModel {
key: "Anniversary", key: "Anniversary",
iconSource: ModelsData.collectibles.anniversary, iconSource: ModelsData.collectibles.anniversary,
name: "Anniversary", name: "Anniversary",
category: "Community collectibles" category: TokenCategories.Category.Community
}, },
{ {
key: "CryptoKitties", key: "CryptoKitties",
iconSource: ModelsData.collectibles.cryptoKitties, iconSource: ModelsData.collectibles.cryptoKitties,
name: "CryptoKitties", name: "CryptoKitties",
category: "Your collectibles", category: TokenCategories.Category.Own,
subItems: [ subItems: [
{ {
key: "Kitty1", key: "Kitty1",
@ -63,13 +65,13 @@ ListModel {
key: "SuperRare", key: "SuperRare",
iconSource: ModelsData.collectibles.superRare, iconSource: ModelsData.collectibles.superRare,
name: "SuperRare", name: "SuperRare",
category: "Your collectibles" category: TokenCategories.Category.Own
}, },
{ {
key: "Custom", key: "Custom",
iconSource: ModelsData.collectibles.custom, iconSource: ModelsData.collectibles.custom,
name: "Custom Collectible", name: "Custom Collectible",
category: "All collectibles" category: TokenCategories.Category.General
} }
]) ])
} }

View File

@ -99,6 +99,20 @@ Item {
searcher.text.toLowerCase()) searcher.text.toLowerCase())
} }
} }
proxyRoles: ExpressionRole {
name: "categoryLabel"
function getCategoryLabelForType(category, type) {
if (type === ExtendedDropdownContent.Type.Assets)
return TokenCategories.getCategoryLabelForAsset(category)
return TokenCategories.getCategoryLabelForCollectible(category)
}
expression: getCategoryLabelForType(model.category, root.type)
}
} }
} }

View File

@ -93,7 +93,7 @@ StatusListView {
model.subItems) model.subItems)
} }
section.property: root.searchMode ? "" : "category" section.property: root.searchMode ? "" : "categoryLabel"
section.criteria: ViewSection.FullString section.criteria: ViewSection.FullString
section.delegate: Item { section.delegate: Item {

View File

@ -0,0 +1,35 @@
pragma Singleton
import QtQml 2.15
QtObject {
enum Category {
Community, Own, General
}
function getCategoryLabelForAsset(category) {
switch (category) {
case TokenCategories.Category.Community:
return qsTr("Community assets")
case TokenCategories.Category.Own:
return qsTr("Your assets")
case TokenCategories.Category.General:
return qsTr("All assets")
}
return ""
}
function getCategoryLabelForCollectible(category) {
switch (category) {
case TokenCategories.Category.Community:
return qsTr("Community collectibles")
case TokenCategories.Category.Own:
return qsTr("Your collectibles")
case TokenCategories.Category.General:
return qsTr("All collectibles")
}
return ""
}
}

View File

@ -4,3 +4,4 @@ HoldingTypes 1.0 HoldingTypes.qml
HoldingsDropdown 1.0 HoldingsDropdown.qml HoldingsDropdown 1.0 HoldingsDropdown.qml
InDropdown 1.0 InDropdown.qml InDropdown 1.0 InDropdown.qml
PermissionItem 1.0 PermissionItem.qml PermissionItem 1.0 PermissionItem.qml
singleton TokenCategories 1.0 TokenCategories.qml

View File

@ -1,5 +1,7 @@
import QtQuick 2.0 import QtQuick 2.0
import AppLayouts.Chat.controls.community 1.0
QtObject { QtObject {
id: root id: root
@ -18,70 +20,108 @@ QtObject {
// TODO: Replace to real data, now dummy model // TODO: Replace to real data, now dummy model
property var assetsModel: ListModel { property var assetsModel: ListModel {
ListElement {key: "socks"; iconSource: "qrc:imports/assets/png/tokens/SOCKS.png"; name: "Unisocks"; shortName: "SOCKS"; category: "Community assets"} Component.onCompleted: {
ListElement {key: "zrx"; iconSource: "qrc:imports/assets/png/tokens/ZRX.png"; name: "Ox"; shortName: "ZRX"; category: "Listed assets"} append([
ListElement {key: "1inch"; iconSource: "qrc:imports/assets/png/tokens/CUSTOM-TOKEN.png"; name: "1inch"; shortName: "ZRX"; category: "Listed assets"} {
ListElement {key: "Aave"; iconSource: "qrc:imports/assets/png/tokens/CUSTOM-TOKEN.png"; name: "Aave"; shortName: "AAVE"; category: "Listed assets"} key: "socks",
ListElement {key: "Amp"; iconSource: "qrc:imports/assets/png/tokens/CUSTOM-TOKEN.png"; name: "Amp"; shortName: "AMP"; category: "Listed assets"} iconSource: "qrc:imports/assets/png/tokens/SOCKS.png",
name: "Unisocks",
shortName: "SOCKS",
category: TokenCategories.Category.Community
},
{
key: "zrx",
iconSource: "qrc:imports/assets/png/tokens/ZRX.png",
name: "Ox",
shortName: "ZRX",
category: TokenCategories.Category.Own
},
{
key: "1inch",
iconSource: "qrc:imports/assets/png/tokens/CUSTOM-TOKEN.png",
name: "1inch",
shortName: "ZRX",
category: TokenCategories.Category.Own
},
{
key: "Aave",
iconSource: "qrc:imports/assets/png/tokens/CUSTOM-TOKEN.png",
name: "Aave",
shortName: "AAVE",
category: TokenCategories.Category.Own
},
{
key: "Amp",
iconSource: "qrc:imports/assets/png/tokens/CUSTOM-TOKEN.png",
name: "Amp",
shortName: "AMP",
category: TokenCategories.Category.Own
}
])
}
} }
// TODO: Replace to real data, now dummy model // TODO: Replace to real data, now dummy model
property var collectiblesModel: ListModel { property var collectiblesModel: ListModel {
ListElement { Component.onCompleted: {
key: "Anniversary" append([
iconSource: "qrc:imports/assets/png/collectibles/Anniversary.png" {
name: "Anniversary" key: "Anniversary",
category: "Community collectibles" iconSource: "qrc:imports/assets/png/collectibles/Anniversary.png",
} name: "Anniversary",
ListElement { category: TokenCategories.Category.Community
key: "CryptoKitties" },
iconSource: "qrc:imports/assets/png/collectibles/CryptoKitties.png" {
name: "CryptoKitties" key: "CryptoKitties",
category: "Your collectibles" iconSource: "qrc:imports/assets/png/collectibles/CryptoKitties.png",
name: "CryptoKitties",
category: TokenCategories.Category.Own,
subItems: [ subItems: [
ListElement { {
key: "Kitty1" key: "Kitty1",
iconSource: "qrc:imports/assets/png/collectibles/Furbeard.png" iconSource: "qrc:imports/assets/png/collectibles/Furbeard.png",
imageSource: "qrc:imports/assets/png/collectibles/FurbeardBig.png" imageSource: "qrc:imports/assets/png/collectibles/FurbeardBig.png",
name: "Furbeard" name: "Furbeard"
}, },
ListElement { {
key: "Kitty2" key: "Kitty2",
iconSource: "qrc:imports/assets/png/collectibles/Magicat.png" iconSource: "qrc:imports/assets/png/collectibles/Magicat.png",
imageSource: "qrc:imports/assets/png/collectibles/MagicatBig.png" imageSource: "qrc:imports/assets/png/collectibles/MagicatBig.png",
name: "Magicat" name: "Magicat"
}, },
ListElement { {
key: "Kitty3" key: "Kitty3",
iconSource: "qrc:imports/assets/png/collectibles/HappyMeow.png" iconSource: "qrc:imports/assets/png/collectibles/HappyMeow.png",
imageSource: "qrc:imports/assets/png/collectibles/HappyMeowBig.png" imageSource: "qrc:imports/assets/png/collectibles/HappyMeowBig.png",
name: "Happy Meow" name: "Happy Meow"
}, },
ListElement { {
key: "Kitty4" key: "Kitty4",
iconSource: "qrc:imports/assets/png/collectibles/Furbeard.png" iconSource: "qrc:imports/assets/png/collectibles/Furbeard.png",
imageSource: "qrc:imports/assets/png/collectibles/FurbeardBig.png" imageSource: "qrc:imports/assets/png/collectibles/FurbeardBig.png",
name: "Furbeard-2" name: "Furbeard-2"
}, },
ListElement { {
key: "Kitty5" key: "Kitty5",
iconSource: "qrc:imports/assets/png/collectibles/Magicat.png" iconSource: "qrc:imports/assets/png/collectibles/Magicat.png",
imageSource: "qrc:imports/assets/png/collectibles/MagicatBig.png" imageSource: "qrc:imports/assets/png/collectibles/MagicatBig.png",
name: "Magicat-3" name: "Magicat-3"
} }
] ]
},
{
key: "SuperRare",
iconSource: "qrc:imports/assets/png/collectibles/SuperRare.png",
name: "SuperRare",
category: TokenCategories.Category.Own
},
{
key: "Custom",
iconSource: "qrc:imports/assets/png/collectibles/SNT.png",
name: "Custom Collectible",
category: TokenCategories.Category.General
} }
ListElement { ])
key: "SuperRare"
iconSource: "qrc:imports/assets/png/collectibles/SuperRare.png";
name: "SuperRare"
category: "Your collectibles"
}
ListElement {
key: "Custom"
iconSource: "qrc:imports/assets/png/collectibles/SNT.png"
name: "Custom Collectible"
category: "All collectibles"
} }
} }