2023-02-13 10:40:13 +00:00
|
|
|
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
|
|
|
|
|
2023-02-17 13:36:58 +00:00
|
|
|
readonly property ModelChangeTracker _assetsChanges: ModelChangeTracker {
|
|
|
|
model: assetsModel
|
|
|
|
}
|
|
|
|
|
|
|
|
readonly property ModelChangeTracker _collectiblesChanges: ModelChangeTracker {
|
|
|
|
model: collectiblesModel
|
|
|
|
}
|
|
|
|
|
2023-02-13 10:40:13 +00:00
|
|
|
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)
|
|
|
|
|
2023-02-17 13:36:58 +00:00
|
|
|
return item ? item.shortName || item.name : ""
|
2023-02-13 10:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2023-02-17 13:36:58 +00:00
|
|
|
expression: {
|
|
|
|
_assetsChanges.revision
|
|
|
|
_collectiblesChanges.revision
|
2023-02-28 12:44:46 +00:00
|
|
|
return getText(model.type, model.key, model.amount)
|
2023-02-17 13:36:58 +00:00
|
|
|
}
|
2023-02-13 10:40:13 +00:00
|
|
|
},
|
|
|
|
ExpressionRole {
|
|
|
|
name: "imageSource"
|
|
|
|
|
|
|
|
function getIcon(type, key) {
|
|
|
|
if (type === HoldingTypes.Type.Ens)
|
2023-03-27 11:51:58 +00:00
|
|
|
return "username"
|
2023-02-13 10:40:13 +00:00
|
|
|
|
|
|
|
const model = type === HoldingTypes.Type.Asset
|
|
|
|
? assetsModel : collectiblesModel
|
|
|
|
|
|
|
|
return CommunityPermissionsHelpers.getTokenIconByKey(model, key)
|
|
|
|
}
|
|
|
|
|
2023-02-17 13:36:58 +00:00
|
|
|
expression: {
|
|
|
|
_assetsChanges.revision
|
|
|
|
_collectiblesChanges.revision
|
2023-02-28 12:44:46 +00:00
|
|
|
return getIcon(model.type, model.key)
|
2023-02-17 13:36:58 +00:00
|
|
|
}
|
2023-02-13 10:40:13 +00:00
|
|
|
},
|
2023-03-27 11:51:58 +00:00
|
|
|
ExpressionRole {
|
|
|
|
name: "isIcon"
|
|
|
|
|
|
|
|
function isIconType(type) {
|
|
|
|
return type === HoldingTypes.Type.Ens
|
|
|
|
}
|
|
|
|
|
|
|
|
expression: {
|
|
|
|
_assetsChanges.revision
|
|
|
|
_collectiblesChanges.revision
|
|
|
|
return isIconType(model.type)
|
|
|
|
}
|
|
|
|
},
|
2023-02-13 10:40:13 +00:00
|
|
|
ExpressionRole {
|
|
|
|
name: "operator"
|
|
|
|
|
|
|
|
// Direct call for singleton enum is not handled properly by SortFilterProxyModel.
|
|
|
|
readonly property int none: OperatorsUtils.Operators.None
|
|
|
|
|
|
|
|
expression: none
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|