2023-02-13 10:40:13 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
2023-06-23 06:17:04 +00:00
|
|
|
import AppLayouts.Communities.helpers 1.0
|
|
|
|
import AppLayouts.Communities.panels 1.0
|
|
|
|
import AppLayouts.Communities.controls 1.0
|
2023-02-13 10:40:13 +00:00
|
|
|
|
2024-02-06 09:22:33 +00:00
|
|
|
import StatusQ 0.1
|
2024-10-15 19:26:12 +00:00
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
2023-02-13 10:40:13 +00:00
|
|
|
|
|
|
|
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: [
|
2024-02-06 09:22:33 +00:00
|
|
|
FastExpressionRole {
|
2023-02-13 10:40:13 +00:00
|
|
|
name: "text"
|
|
|
|
|
2024-04-04 11:06:44 +00:00
|
|
|
function getName(type, item, key) {
|
2023-11-07 22:45:47 +00:00
|
|
|
if (type === Constants.TokenType.ENS)
|
2023-02-13 10:40:13 +00:00
|
|
|
return key
|
2023-08-29 15:28:41 +00:00
|
|
|
return item ? item.symbol || item.shortName || item.name : ""
|
2023-02-13 10:40:13 +00:00
|
|
|
}
|
|
|
|
|
2024-04-04 11:06:44 +00:00
|
|
|
function getDecimals(type, item) {
|
|
|
|
if (type !== Constants.TokenType.ERC20)
|
2024-02-13 10:24:24 +00:00
|
|
|
return 0
|
|
|
|
return item.decimals
|
|
|
|
}
|
|
|
|
|
2024-06-24 14:51:18 +00:00
|
|
|
function getText(type, key, amount, defaultText) {
|
2024-04-04 11:06:44 +00:00
|
|
|
const model = type === Constants.TokenType.ERC20
|
|
|
|
? assetsModel
|
|
|
|
: collectiblesModel
|
|
|
|
|
2024-06-24 14:51:18 +00:00
|
|
|
let item = PermissionsHelpers.getTokenByKey(model, key)
|
|
|
|
let name = getName(type, item, key)
|
2024-04-04 11:06:44 +00:00
|
|
|
const decimals = getDecimals(type, item)
|
2023-02-13 10:40:13 +00:00
|
|
|
|
2024-06-24 14:51:18 +00:00
|
|
|
if (name === "")
|
|
|
|
name = defaultText
|
|
|
|
|
2023-06-26 11:48:45 +00:00
|
|
|
return PermissionsHelpers.setHoldingsTextFormat(
|
2024-02-13 10:24:24 +00:00
|
|
|
type, name, amount, decimals)
|
2023-02-13 10:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2024-06-24 14:51:18 +00:00
|
|
|
return getText(model.type, model.key, model.amount, model.symbol)
|
2023-02-17 13:36:58 +00:00
|
|
|
}
|
2024-06-24 14:51:18 +00:00
|
|
|
expectedRoles: ["type", "key", "amount", "symbol", "shortName"]
|
2023-02-13 10:40:13 +00:00
|
|
|
},
|
2024-02-06 09:22:33 +00:00
|
|
|
FastExpressionRole {
|
2023-02-13 10:40:13 +00:00
|
|
|
name: "imageSource"
|
|
|
|
|
|
|
|
function getIcon(type, key) {
|
2023-11-07 22:45:47 +00:00
|
|
|
if (type === Constants.TokenType.ENS)
|
2024-10-15 19:26:12 +00:00
|
|
|
return Theme.png("tokens/ENS")
|
2023-02-13 10:40:13 +00:00
|
|
|
|
2023-11-07 22:45:47 +00:00
|
|
|
const model = type === Constants.TokenType.ERC20
|
2023-02-13 10:40:13 +00:00
|
|
|
? assetsModel : collectiblesModel
|
|
|
|
|
2023-06-26 11:48:45 +00:00
|
|
|
return PermissionsHelpers.getTokenIconByKey(model, key)
|
2023-02-13 10:40:13 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2024-02-06 09:22:33 +00:00
|
|
|
expectedRoles: ["type", "key"]
|
2023-02-13 10:40:13 +00:00
|
|
|
},
|
2024-02-06 09:22:33 +00:00
|
|
|
FastExpressionRole {
|
2023-02-13 10:40:13 +00:00
|
|
|
name: "operator"
|
|
|
|
|
|
|
|
// Direct call for singleton enum is not handled properly by SortFilterProxyModel.
|
|
|
|
readonly property int none: OperatorsUtils.Operators.None
|
|
|
|
|
|
|
|
expression: none
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|