status-desktop/ui/app/AppLayouts/Wallet/controls/ManageTokensDelegate.qml

136 lines
5.8 KiB
QML
Raw Normal View History

import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import StatusQ 0.1
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)
// expected roles: symbol, name, communityId, communityName, communityImage, collectionUid, collectionName, imageUrl
// + enabledNetworkBalance, enabledNetworkCurrencyBalance
property var controller
property int visualIndex: index
property alias dragParent: delegate.dragParent
property alias dragEnabled: delegate.dragEnabled
property alias bgColor: delegate.bgColor
property bool isHidden // inside the "Hidden" section
property int count
property bool isCollectible
readonly property alias title: delegate.title
readonly property var balances: model.balances
readonly property bool isCommunityToken: !!model.communityId
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
}
property var getCurrencyAmount: function (balance, symbol) {}
property var getCurrentCurrencyAmount: function(balance){}
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 }
}
keys: isCommunityToken ? ["x-status-draggable-community-token-item"] : ["x-status-draggable-regular-token-item"]
width: ListView.view ? ListView.view.width : 0
height: delegate.height
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
readonly property real totalBalance: aggregator.value/(10 ** model.decimals)
secondaryTitle: root.isCollectible ? (root.isCommunityToken ? qsTr("Community minted") : model.collectionName || model.collectionUid) :
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))
bgRadius: priv.bgRadius
hasImage: true
icon.source: root.isCollectible ? model.imageUrl : Constants.tokenIcon(model.symbol) // TODO unify via backend model for both assets and collectibles; handle communityPrivilegesLevel
icon.width: priv.iconSize
icon.height: priv.iconSize
spacing: 12
assetBgColor: model.backgroundColor
actions: [
ManageTokensCommunityTag {
Layout.maximumWidth: delegate.width *.4
visible: !!model.communityId
2024-02-13 11:12:01 +00:00
communityImage: model.communityImage
communityName: model.communityName
communityId: model.communityId
},
ManageTokenMenuButton {
id: menuBtn
objectName: "btnManageTokenMenu-%1".arg(currentIndex)
currentIndex: root.visualIndex
count: root.count
inHidden: root.isHidden
groupId: isCollection ? model.collectionUid : model.communityId
isCommunityToken: root.isCommunityToken
isCollectible: root.isCollectible
isCollection: isCollectible && !model.isSelfCollection
onMoveRequested: (from, to) => root.ListView.view.model.moveItem(from, to)
onShowHideRequested: function(symbol, flag) {
if (isCommunityToken)
root.controller.showHideCommunityToken(symbol, flag)
else
root.controller.showHideRegularToken(symbol, flag)
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, "")
}
}
onShowHideGroupRequested: function(groupId, flag) {
if (isCommunityToken)
root.controller.showHideGroup(groupId, flag)
else
root.controller.showHideCollectionGroup(groupId, flag)
}
}
]
SumAggregator {
id: aggregator
model: root.balances ?? null
roleName: "balance"
}
}
}