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
2024-01-26 15:39:42 +00:00
height: delegate . height
2023-11-09 11:21:56 +00:00
onEntered: function ( drag ) {
const from = drag . source . visualIndex
const to = delegate . visualIndex
if ( to === from )
return
2024-01-26 15:39:42 +00:00
2023-11-09 11:21:56 +00:00
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-25 18:53:09 +00:00
readonly property real 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
2024-02-13 11:12:01 +00:00
communityImage: model . communityImage
communityName: model . communityName
communityId: model . communityId
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-25 11:40:22 +00:00
groupId: isCollection ? model.collectionUid : model . communityId
2024-01-19 09:53:32 +00:00
isCommunityToken: root . isCommunityToken
2023-11-09 11:21:56 +00:00
isCollectible: root . isCollectible
2024-07-26 14:47:18 +00:00
isCollection: isCollectible && ! model . isSelfCollection && ! isCommunityToken
2023-11-09 11:21:56 +00:00
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-31 18:09:44 +00:00
if ( ! flag ) {
const msg = isCollectible ? qsTr ( "%1 was successfully hidden" ) . arg ( delegate . title )
: qsTr ( "%1 (%2) was successfully hidden" ) . arg ( delegate . title ) . arg ( symbol )
Global . displayToastMessage ( msg , "" , "checkmark-circle" , false , Constants . ephemeralNotificationType . success , "" )
}
2024-01-11 13:59:13 +00:00
}
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
}
2023-11-09 11:21:56 +00:00
}
]
2024-01-24 16:35:53 +00:00
SumAggregator {
id: aggregator
2024-01-25 18:53:09 +00:00
model: root . balances ? ? null
2024-01-24 16:35:53 +00:00
roleName: "balance"
}
2023-11-09 11:21:56 +00:00
}
}