2023-11-09 11:21:56 +00:00
import QtQuick 2.15
2024-01-16 16:22:05 +00:00
import QtQuick . Layouts 1.15
2023-11-09 11:21:56 +00:00
import QtQuick . Controls 2.15
2024-01-24 16:35:53 +00:00
import StatusQ 0.1
2023-11-09 11:21:56 +00:00
import StatusQ . Core 0.1
import StatusQ . Components 0.1
import StatusQ . Controls 0.1
import StatusQ . Core . Theme 0.1
import utils 1.0
DropArea {
id: root
objectName: "manageTokensDelegate-%1" . arg ( index )
2024-01-19 09:53:32 +00:00
// expected roles: symbol, name, communityId, communityName, communityImage, collectionUid, collectionName, imageUrl
// + enabledNetworkBalance, enabledNetworkCurrencyBalance
2023-11-09 11:21:56 +00:00
property var controller
property int visualIndex: index
property alias dragParent: delegate . dragParent
property alias dragEnabled: delegate . dragEnabled
property alias bgColor: delegate . bgColor
2024-01-16 16:22:05 +00:00
property bool isHidden // inside the "Hidden" section
2023-11-09 11:21:56 +00:00
property int count
property bool isCollectible
readonly property alias title: delegate . title
2024-01-24 16:35:53 +00:00
readonly property var balances: model . balances
2024-01-19 09:53:32 +00:00
readonly property bool isCommunityToken: ! ! model . communityId
2023-11-09 11:21:56 +00:00
readonly property var priv: QtObject {
id: priv
readonly property int iconSize: root . isCollectible ? 44 : 32
readonly property int bgRadius: root . isCollectible ? Style.current.radius : iconSize / 2
}
2024-01-24 16:35:53 +00:00
property var getCurrencyAmount: function ( balance , symbol ) { }
property var getCurrentCurrencyAmount: function ( balance ) { }
2023-11-09 11:21:56 +00:00
ListView.onRemove: SequentialAnimation {
PropertyAction { target: root ; property: "ListView.delayRemove" ; value: true }
NumberAnimation { target: root ; property: "scale" ; to: 0 ; easing.type: Easing . InOutQuad }
PropertyAction { target: root ; property: "ListView.delayRemove" ; value: false }
}
2024-01-19 09:53:32 +00:00
keys: isCommunityToken ? [ "x-status-draggable-community-token-item" ] : [ "x-status-draggable-regular-token-item" ]
2024-01-16 16:22:05 +00:00
width: ListView . view ? ListView.view.width : 0
2023-11-09 11:21:56 +00:00
height: visible ? delegate.height : 0
onEntered: function ( drag ) {
const from = drag . source . visualIndex
const to = delegate . visualIndex
if ( to === from )
return
ListView . view . model . moveItem ( from , to )
drag . accept ( )
}
StatusDraggableListItem {
id: delegate
objectName: "draggableDelegate"
visualIndex: index
Drag.keys: root . keys
Drag.hotSpot.x: root . width / 2
Drag.hotSpot.y: root . height / 2
draggable: true
width: root . width
title: model . name
2024-01-19 09:53:32 +00:00
2024-01-24 16:35:53 +00:00
readonly property var totalBalance: aggregator . value / ( 10 * * model . decimals )
2024-01-19 09:53:32 +00:00
secondaryTitle: root . isCollectible ? ( root . isCommunityToken ? qsTr ( "Community minted" ) : model . collectionName || model . collectionUid ) :
2024-01-24 16:35:53 +00:00
hovered || menuBtn . menuVisible ? "%1 • %2" . arg ( LocaleUtils . currencyAmountToLocaleString ( root . getCurrencyAmount ( totalBalance , model . symbol ) ) )
. arg ( ! model . communityId ? LocaleUtils . currencyAmountToLocaleString ( root . getCurrentCurrencyAmount ( totalBalance * model . marketDetails . currencyPrice . amount ) ) :
LocaleUtils . currencyAmountToLocaleString ( root . getCurrentCurrencyAmount ( 0 ) ) )
: LocaleUtils . currencyAmountToLocaleString ( root . getCurrencyAmount ( totalBalance , model . symbol ) )
2023-11-09 11:21:56 +00:00
bgRadius: priv . bgRadius
hasImage: true
2023-11-17 14:08:43 +00:00
icon.source: root . isCollectible ? model.imageUrl : Constants . tokenIcon ( model . symbol ) // TODO unify via backend model for both assets and collectibles; handle communityPrivilegesLevel
2023-11-09 11:21:56 +00:00
icon.width: priv . iconSize
icon.height: priv . iconSize
spacing: 12
assetBgColor: model . backgroundColor
actions: [
ManageTokensCommunityTag {
2024-01-16 16:22:05 +00:00
Layout.maximumWidth: delegate . width * . 4
2024-01-19 09:53:32 +00:00
visible: ! ! model . communityId
2023-11-09 11:21:56 +00:00
text: model . communityName
2023-11-24 12:16:13 +00:00
asset.name: model && ! ! model . communityImage ? model.communityImage : ""
2023-11-09 11:21:56 +00:00
} ,
ManageTokenMenuButton {
id: menuBtn
objectName: "btnManageTokenMenu-%1" . arg ( currentIndex )
currentIndex: root . visualIndex
count: root . count
inHidden: root . isHidden
2024-01-19 09:53:32 +00:00
groupId: model . communityId || model . collectionUid
isCommunityToken: root . isCommunityToken
2023-11-09 11:21:56 +00:00
isCollectible: root . isCollectible
onMoveRequested: ( from , to ) = > root . ListView . view . model . moveItem ( from , to )
2024-01-16 16:22:05 +00:00
onShowHideRequested: function ( symbol , flag ) {
2024-01-19 09:53:32 +00:00
if ( isCommunityToken )
2024-01-16 16:22:05 +00:00
root . controller . showHideCommunityToken ( symbol , flag )
2024-01-11 13:59:13 +00:00
else
2024-01-16 16:22:05 +00:00
root . controller . showHideRegularToken ( symbol , flag )
2024-01-11 13:59:13 +00:00
root . controller . saveSettings ( )
}
onShowHideGroupRequested: function ( groupId , flag ) {
2024-01-19 09:53:32 +00:00
if ( isCommunityToken )
root . controller . showHideGroup ( groupId , flag )
else
root . controller . showHideCollectionGroup ( groupId , flag )
2024-01-11 13:59:13 +00:00
root . controller . saveSettings ( )
}
2023-11-09 11:21:56 +00:00
}
]
2024-01-24 16:35:53 +00:00
SumAggregator {
id: aggregator
model: root . balances
roleName: "balance"
}
2023-11-09 11:21:56 +00:00
}
}