2022-08-30 16:27:00 +00:00
|
|
|
import QtQuick 2.14
|
2022-06-09 15:27:14 +00:00
|
|
|
import QtQuick.Layouts 1.14
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1 as SQ
|
|
|
|
|
|
|
|
StatusDropdown {
|
|
|
|
id: root
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
property var store
|
|
|
|
|
|
|
|
property var itemKey
|
|
|
|
property real tokenAmount: 0
|
2022-06-09 15:27:14 +00:00
|
|
|
property string tokenName: d.defaultTokenNameText
|
|
|
|
property url tokenImage: ""
|
2022-08-23 08:46:37 +00:00
|
|
|
property real collectibleAmount: 1
|
|
|
|
property string collectibleName: d.defaultCollectibleNameText
|
2022-08-30 16:27:00 +00:00
|
|
|
property bool collectiblesSpecificAmount: false
|
|
|
|
|
2022-08-31 12:35:28 +00:00
|
|
|
property int ensType: EnsPanel.EnsType.Any
|
|
|
|
property string ensDomainName: ""
|
|
|
|
property bool ensDomainNameValid: false
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
property url collectibleImage: ""
|
2022-06-09 15:27:14 +00:00
|
|
|
property int operator: SQ.Utils.Operators.None
|
|
|
|
property bool withOperatorSelector: true
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
signal addItem(var itemKey, string itemText, url itemImage, int operator)
|
2022-06-09 15:27:14 +00:00
|
|
|
|
|
|
|
function reset() {
|
2022-08-23 08:46:37 +00:00
|
|
|
d.currentTabIndex = 0
|
|
|
|
root.itemKey = undefined
|
|
|
|
root.tokenAmount = 0
|
2022-06-09 15:27:14 +00:00
|
|
|
root.tokenName = d.defaultTokenNameText
|
|
|
|
root.tokenImage = ""
|
2022-08-23 08:46:37 +00:00
|
|
|
root.collectibleAmount = 1
|
|
|
|
root.collectibleName = d.defaultCollectibleNameText
|
|
|
|
root.collectibleImage = ""
|
2022-08-30 16:27:00 +00:00
|
|
|
root.collectiblesSpecificAmount = false
|
2022-08-31 12:35:28 +00:00
|
|
|
root.ensType = EnsPanel.EnsType.Any
|
|
|
|
root.ensDomainName = ""
|
2022-06-09 15:27:14 +00:00
|
|
|
root.operator = SQ.Utils.Operators.None
|
|
|
|
}
|
|
|
|
|
2022-08-30 16:27:00 +00:00
|
|
|
padding: d.padding
|
|
|
|
|
|
|
|
onOpened: d.selectInitState()
|
|
|
|
onClosed: root.reset()
|
|
|
|
onWithOperatorSelectorChanged: d.selectInitState()
|
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
// Internal management properties:
|
|
|
|
readonly property bool tokensReady: root.tokenAmount > 0 && root.tokenName !== d.defaultTokenNameText
|
|
|
|
readonly property bool collectiblesReady: root.collectibleAmount > 0 && root.collectibleName !== d.defaultCollectibleNameText
|
2022-08-31 12:35:28 +00:00
|
|
|
readonly property bool ensReady: root.ensType === EnsPanel.EnsType.Any || root.ensDomainNameValid
|
2022-08-30 16:27:00 +00:00
|
|
|
|
|
|
|
readonly property string operatorsState: "OPERATORS"
|
|
|
|
readonly property string tabsState: "TABS"
|
|
|
|
readonly property string extendedState: "EXTENDED"
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
readonly property string tokensState: "TOKENS"
|
|
|
|
readonly property string collectiblesState: "COLLECTIBLES"
|
|
|
|
readonly property string ensState: "ENS"
|
2022-08-30 16:27:00 +00:00
|
|
|
|
|
|
|
property int extendedDropdownType: ExtendedDropdownContent.Type.Tokens
|
2022-08-23 08:46:37 +00:00
|
|
|
property int currentTabIndex: 0
|
2022-06-09 15:27:14 +00:00
|
|
|
|
|
|
|
// By design values:
|
2022-08-30 16:27:00 +00:00
|
|
|
readonly property int padding: 8
|
|
|
|
readonly property int topPaddingWithBack: 12
|
|
|
|
readonly property int extendedTopPadding: 16
|
|
|
|
|
|
|
|
readonly property int operatorsWidth: 159
|
2022-06-09 15:27:14 +00:00
|
|
|
readonly property int operatorsHeight: 96
|
2022-08-30 16:27:00 +00:00
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
readonly property int defaultWidth: 289
|
2022-08-30 16:27:00 +00:00
|
|
|
readonly property int defaultHeight: 232
|
|
|
|
readonly property int enlargedHeight: 276
|
|
|
|
readonly property int extendedHeight: 417
|
|
|
|
|
|
|
|
readonly property int backButtonExtraLeftMargin: 4
|
2022-06-09 15:27:14 +00:00
|
|
|
|
|
|
|
property string defaultTokenNameText: qsTr("Choose token")
|
2022-08-23 08:46:37 +00:00
|
|
|
property string defaultCollectibleNameText: qsTr("Choose collectible")
|
2022-06-09 15:27:14 +00:00
|
|
|
|
2022-08-30 16:27:00 +00:00
|
|
|
signal addClicked
|
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
function selectInitState() {
|
|
|
|
if(root.withOperatorSelector)
|
2022-08-30 16:27:00 +00:00
|
|
|
content.state = d.operatorsState
|
2022-06-09 15:27:14 +00:00
|
|
|
else
|
2022-08-30 16:27:00 +00:00
|
|
|
content.state = d.tabsState
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-30 16:27:00 +00:00
|
|
|
contentItem: ColumnLayout {
|
|
|
|
id: content
|
|
|
|
|
|
|
|
spacing: 10
|
|
|
|
|
|
|
|
StatusIconTextButton {
|
|
|
|
id: backButton
|
|
|
|
|
|
|
|
Layout.leftMargin: d.backButtonExtraLeftMargin
|
|
|
|
spacing: 0
|
|
|
|
statusIcon: "next"
|
|
|
|
icon.width: 12
|
|
|
|
icon.height: 12
|
|
|
|
iconRotation: 180
|
|
|
|
text: qsTr("Back")
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
|
2022-08-30 16:27:00 +00:00
|
|
|
Loader {
|
|
|
|
id: loader
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
}
|
2022-06-09 15:27:14 +00:00
|
|
|
|
2022-08-30 16:27:00 +00:00
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: d.operatorsState
|
|
|
|
PropertyChanges {target: loader; sourceComponent: operatorsSelectorView}
|
|
|
|
PropertyChanges {target: backButton; visible: false}
|
|
|
|
PropertyChanges {target: root; width: d.operatorsWidth; height: d.operatorsHeight }
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: d.tabsState
|
|
|
|
PropertyChanges {target: loader; sourceComponent: tabsView}
|
|
|
|
PropertyChanges {target: backButton; visible: root.withOperatorSelector}
|
|
|
|
PropertyChanges {
|
|
|
|
target: root; topPadding: root.withOperatorSelector ? d.topPaddingWithBack : d.extendedTopPadding
|
|
|
|
width: d.defaultWidth
|
2022-08-31 12:35:28 +00:00
|
|
|
height: (loader.item.state === d.collectiblesState && root.collectiblesSpecificAmount)
|
|
|
|
|| (loader.item.state === d.ensState && root.ensType === EnsPanel.EnsType.CustomSubdomain) ? d.enlargedHeight : d.defaultHeight
|
2022-08-23 08:46:37 +00:00
|
|
|
}
|
2022-08-30 16:27:00 +00:00
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: d.extendedState
|
|
|
|
PropertyChanges {target: loader; sourceComponent: extendedView}
|
|
|
|
PropertyChanges {target: backButton; visible: true}
|
|
|
|
PropertyChanges {target: root; topPadding: d.topPaddingWithBack; width: d.defaultWidth; height: d.extendedHeight}
|
2022-08-23 08:46:37 +00:00
|
|
|
}
|
2022-08-30 16:27:00 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: operatorsSelectorView
|
|
|
|
|
|
|
|
OperatorsSelector {
|
|
|
|
onOperatorSelected: {
|
|
|
|
root.operator = operator
|
|
|
|
content.state = d.tabsState
|
2022-08-23 08:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
Component {
|
|
|
|
id: tabsView
|
|
|
|
|
2022-08-30 16:27:00 +00:00
|
|
|
HoldingsTabs {
|
|
|
|
id: holdingsTabs
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: d.tokensState
|
2022-08-30 16:27:00 +00:00
|
|
|
PropertyChanges {target: holdingsTabs; sourceComponent: tokensLayout; addButtonEnabled: d.tokensReady}
|
2022-08-23 08:46:37 +00:00
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: d.collectiblesState
|
2022-08-30 16:27:00 +00:00
|
|
|
PropertyChanges {target: holdingsTabs; sourceComponent: collectiblesLayout; addButtonEnabled: d.collectiblesReady}
|
2022-08-23 08:46:37 +00:00
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: d.ensState
|
2022-08-31 12:35:28 +00:00
|
|
|
PropertyChanges {target: holdingsTabs; sourceComponent: ensLayout; addButtonEnabled: d.ensReady}
|
2022-08-23 08:46:37 +00:00
|
|
|
}
|
|
|
|
]
|
2022-08-30 16:27:00 +00:00
|
|
|
|
|
|
|
tabLabels: [qsTr("Token"), qsTr("Collectible"), qsTr("ENS")]
|
|
|
|
state: [d.tokensState, d.collectiblesState, d.ensState][currentIndex]
|
|
|
|
|
|
|
|
currentIndex: d.currentTabIndex
|
|
|
|
onCurrentIndexChanged: d.currentTabIndex = currentIndex
|
|
|
|
|
|
|
|
onAddClicked: d.addClicked()
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: backButton
|
|
|
|
|
|
|
|
function onClicked() {
|
|
|
|
content.state = d.operatorsState
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
2022-08-30 16:27:00 +00:00
|
|
|
id: tokensLayout
|
2022-08-23 08:46:37 +00:00
|
|
|
|
2022-08-30 16:27:00 +00:00
|
|
|
TokensPanel {
|
|
|
|
id: tokensPanel
|
|
|
|
|
|
|
|
tokenName: root.tokenName
|
|
|
|
tokenImage: root.tokenImage
|
|
|
|
amount: root.tokenAmount === 0 ? "" : root.tokenAmount.toString()
|
|
|
|
onAmountChanged: root.tokenAmount = Number(amount)
|
|
|
|
|
|
|
|
onPickerClicked: {
|
|
|
|
d.extendedDropdownType = ExtendedDropdownContent.Type.Tokens
|
|
|
|
content.state = d.extendedState
|
2022-08-23 08:46:37 +00:00
|
|
|
}
|
|
|
|
|
2022-08-30 16:27:00 +00:00
|
|
|
Connections {
|
|
|
|
target: d
|
|
|
|
|
|
|
|
function onAddClicked() {
|
|
|
|
root.addItem(root.itemKey, qsTr("%1 %2").arg(root.tokenAmount.toString()).arg(root.tokenName),
|
|
|
|
root.tokenImage, root.operator)
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-30 16:27:00 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-23 08:46:37 +00:00
|
|
|
|
2022-08-30 16:27:00 +00:00
|
|
|
Component {
|
|
|
|
id: collectiblesLayout
|
|
|
|
|
|
|
|
CollectiblesPanel {
|
|
|
|
collectibleName: root.collectibleName
|
|
|
|
collectibleImage: root.collectibleImage
|
|
|
|
amount: root.collectibleAmount === 0 ? "" : root.collectibleAmount.toString()
|
|
|
|
onAmountChanged: root.collectibleAmount = Number(amount)
|
|
|
|
|
|
|
|
specificAmount: root.collectiblesSpecificAmount
|
|
|
|
onSpecificAmountChanged: root.collectiblesSpecificAmount = specificAmount
|
|
|
|
|
|
|
|
onPickerClicked: {
|
|
|
|
d.extendedDropdownType = ExtendedDropdownContent.Type.Collectibles
|
|
|
|
content.state = d.extendedState
|
2022-08-23 08:46:37 +00:00
|
|
|
}
|
|
|
|
|
2022-08-30 16:27:00 +00:00
|
|
|
Connections {
|
|
|
|
target: d
|
|
|
|
|
|
|
|
function onAddClicked() {
|
|
|
|
root.addItem(root.itemKey, qsTr("%1 %2").arg(root.collectibleAmount.toString()).arg(root.collectibleName),
|
|
|
|
root.tokenImage, root.operator)
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
2022-08-23 08:46:37 +00:00
|
|
|
id: ensLayout
|
2022-08-31 12:35:28 +00:00
|
|
|
|
|
|
|
EnsPanel {
|
|
|
|
ensType: root.ensType
|
|
|
|
onEnsTypeChanged: root.ensType = ensType
|
|
|
|
|
|
|
|
domainName: root.ensDomainName
|
|
|
|
onDomainNameChanged: root.ensDomainName = domainName
|
|
|
|
onDomainNameValidChanged: root.ensDomainNameValid = domainNameValid
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: d
|
|
|
|
|
|
|
|
function onAddClicked() {
|
|
|
|
const icon = "qrc:imports/assets/icons/profile/ensUsernames.svg"
|
|
|
|
|
|
|
|
if (root.ensType === EnsPanel.EnsType.Any) {
|
|
|
|
root.addItem("EnsAny", qsTr("Any ENS username"), icon,
|
|
|
|
root.operator)
|
|
|
|
} else {
|
|
|
|
root.addItem("EnsAny", qsTr(`ENS username on '%1' domain`).arg(root.ensDomainName), icon,
|
|
|
|
root.operator)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-30 16:27:00 +00:00
|
|
|
}
|
2022-06-09 15:27:14 +00:00
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
Component {
|
|
|
|
id: extendedView
|
|
|
|
|
|
|
|
ExtendedDropdownContent {
|
2022-08-30 16:27:00 +00:00
|
|
|
id: extendedDropdown
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
store: root.store
|
2022-08-30 16:27:00 +00:00
|
|
|
type: d.extendedDropdownType
|
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
onItemClicked: {
|
|
|
|
// Go back
|
2022-08-30 16:27:00 +00:00
|
|
|
content.state = d.tabsState
|
2022-06-09 15:27:14 +00:00
|
|
|
|
2022-08-30 16:27:00 +00:00
|
|
|
if(d.extendedDropdownType === ExtendedDropdownContent.Type.Tokens) {
|
2022-08-23 08:46:37 +00:00
|
|
|
// Update new token item info
|
|
|
|
root.tokenName = name
|
|
|
|
root.tokenImage = iconSource
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Update new collectible item info
|
|
|
|
root.collectibleName = name
|
|
|
|
root.collectibleImage = iconSource
|
|
|
|
}
|
2022-08-30 16:27:00 +00:00
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
root.itemKey = key
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
2022-08-30 16:27:00 +00:00
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: backButton
|
|
|
|
|
|
|
|
function onClicked() {
|
|
|
|
if (extendedDropdown.canGoBack)
|
|
|
|
extendedDropdown.goBack()
|
|
|
|
else
|
|
|
|
content.state = d.tabsState
|
|
|
|
}
|
|
|
|
}
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
2022-08-23 08:46:37 +00:00
|
|
|
}
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|