mirror of
https://github.com/status-im/status-desktop.git
synced 2025-02-10 05:36:23 +00:00
Fixing https://github.com/status-im/status-desktop/issues/9766 The main change is that the model will now provide the image type, on top of the image source. The image type can be either icon or image. Icons will be coloured with the same colour as the text.
96 lines
2.8 KiB
QML
96 lines
2.8 KiB
QML
import SortFilterProxyModel 0.2
|
|
|
|
import AppLayouts.Chat.helpers 1.0
|
|
import AppLayouts.Chat.panels.communities 1.0
|
|
import AppLayouts.Chat.controls.community 1.0
|
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
import utils 1.0
|
|
|
|
SortFilterProxyModel {
|
|
property var assetsModel
|
|
property var collectiblesModel
|
|
|
|
readonly property ModelChangeTracker _assetsChanges: ModelChangeTracker {
|
|
model: assetsModel
|
|
}
|
|
|
|
readonly property ModelChangeTracker _collectiblesChanges: ModelChangeTracker {
|
|
model: collectiblesModel
|
|
}
|
|
|
|
proxyRoles: [
|
|
ExpressionRole {
|
|
name: "text"
|
|
|
|
function getName(type, key) {
|
|
if (type === HoldingTypes.Type.Ens)
|
|
return key
|
|
|
|
const model = type === HoldingTypes.Type.Asset
|
|
? assetsModel
|
|
: collectiblesModel
|
|
const item = CommunityPermissionsHelpers.getTokenByKey(model, key)
|
|
|
|
return item ? item.shortName || item.name : ""
|
|
}
|
|
|
|
function getText(type, key, amount) {
|
|
const name = getName(type, key)
|
|
|
|
return CommunityPermissionsHelpers.setHoldingsTextFormat(
|
|
type, name, amount)
|
|
}
|
|
|
|
// Direct call for singleton function is not handled properly by
|
|
// SortFilterProxyModel that's why helper function is used instead.
|
|
expression: {
|
|
_assetsChanges.revision
|
|
_collectiblesChanges.revision
|
|
return getText(model.type, model.key, model.amount)
|
|
}
|
|
},
|
|
ExpressionRole {
|
|
name: "imageSource"
|
|
|
|
function getIcon(type, key) {
|
|
if (type === HoldingTypes.Type.Ens)
|
|
return "username"
|
|
|
|
const model = type === HoldingTypes.Type.Asset
|
|
? assetsModel : collectiblesModel
|
|
|
|
return CommunityPermissionsHelpers.getTokenIconByKey(model, key)
|
|
}
|
|
|
|
expression: {
|
|
_assetsChanges.revision
|
|
_collectiblesChanges.revision
|
|
return getIcon(model.type, model.key)
|
|
}
|
|
},
|
|
ExpressionRole {
|
|
name: "isIcon"
|
|
|
|
function isIconType(type) {
|
|
return type === HoldingTypes.Type.Ens
|
|
}
|
|
|
|
expression: {
|
|
_assetsChanges.revision
|
|
_collectiblesChanges.revision
|
|
return isIconType(model.type)
|
|
}
|
|
},
|
|
ExpressionRole {
|
|
name: "operator"
|
|
|
|
// Direct call for singleton enum is not handled properly by SortFilterProxyModel.
|
|
readonly property int none: OperatorsUtils.Operators.None
|
|
|
|
expression: none
|
|
}
|
|
]
|
|
}
|