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
|
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
StatusDropdown {
|
|
|
|
id: root
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
property var store
|
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
property string tokenKey: ""
|
|
|
|
property string collectibleKey: ""
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
property real tokenAmount: 0
|
|
|
|
property real collectibleAmount: 1
|
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: ""
|
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
signal addToken(string key, real amount, int operator)
|
|
|
|
signal addCollectible(string key, real amount, int operator)
|
|
|
|
signal addEns(bool any, string customDomain, int operator)
|
2022-06-09 15:27:14 +00:00
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
signal updateToken(string key, real amount)
|
|
|
|
signal updateCollectible(string key, real amount)
|
|
|
|
signal updateEns(bool any, string customDomain)
|
|
|
|
|
|
|
|
signal removeClicked
|
2022-06-09 15:27:14 +00:00
|
|
|
|
|
|
|
function reset() {
|
2022-09-07 09:40:25 +00:00
|
|
|
d.currentHoldingType = HoldingTypes.Type.Token
|
|
|
|
d.operator = SQ.Utils.Operators.None
|
|
|
|
|
|
|
|
root.tokenKey = ""
|
|
|
|
root.collectibleKey = ""
|
2022-08-23 08:46:37 +00:00
|
|
|
root.tokenAmount = 0
|
|
|
|
root.collectibleAmount = 1
|
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-09-07 09:40:25 +00:00
|
|
|
|
|
|
|
statesStack.clear()
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
width: d.defaultWidth
|
2022-08-30 16:27:00 +00:00
|
|
|
padding: d.padding
|
|
|
|
|
|
|
|
onClosed: root.reset()
|
2022-09-07 09:40:25 +00:00
|
|
|
|
|
|
|
enum FlowType {
|
|
|
|
Add, AddWithOperators, Update
|
|
|
|
}
|
|
|
|
|
|
|
|
function openFlow(flowType) {
|
|
|
|
switch (flowType) {
|
|
|
|
case HoldingsDropdown.FlowType.AddWithOperators:
|
|
|
|
statesStack.push(d.operatorsState)
|
|
|
|
break
|
|
|
|
case HoldingsDropdown.FlowType.Add:
|
|
|
|
statesStack.push(d.addState)
|
|
|
|
break
|
|
|
|
case HoldingsDropdown.FlowType.Update:
|
|
|
|
statesStack.push(d.updateState)
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
console.warn("Unknown flow type.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
open()
|
|
|
|
}
|
|
|
|
|
|
|
|
function setActiveTab(holdingType) {
|
|
|
|
d.currentHoldingType = holdingType
|
|
|
|
}
|
2022-08-30 16:27:00 +00:00
|
|
|
|
2022-06-09 15:27:14 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
// Internal management properties and signals:
|
|
|
|
readonly property bool tokensReady: root.tokenAmount > 0 && root.tokenKey
|
|
|
|
readonly property bool collectiblesReady: root.collectibleAmount > 0 && root.collectibleKey
|
|
|
|
readonly property bool ensReady: root.ensType === EnsPanel.EnsType.Any || d.ensDomainNameValid
|
2022-08-30 16:27:00 +00:00
|
|
|
|
|
|
|
readonly property string operatorsState: "OPERATORS"
|
2022-09-07 09:40:25 +00:00
|
|
|
readonly property string addState: "ADD"
|
|
|
|
readonly property string updateState: "UPDATE"
|
2022-08-30 16:27:00 +00:00
|
|
|
readonly property string extendedState: "EXTENDED"
|
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
property int holdingsTabMode: HoldingsTabs.Mode.Add
|
2022-08-30 16:27:00 +00:00
|
|
|
property int extendedDropdownType: ExtendedDropdownContent.Type.Tokens
|
2022-09-07 09:40:25 +00:00
|
|
|
|
|
|
|
property int currentHoldingType: HoldingTypes.Type.Token
|
|
|
|
|
|
|
|
property int operator: SQ.Utils.Operators.None
|
|
|
|
property bool ensDomainNameValid: false
|
|
|
|
|
|
|
|
signal addClicked
|
|
|
|
signal updateClicked
|
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 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-09-07 09:40:25 +00:00
|
|
|
readonly property int extendedContentHeight: 380
|
2022-08-30 16:27:00 +00:00
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
readonly property int tabsAddModeBaseHeight: 232 - padding * 2
|
|
|
|
readonly property int tabsAddModeExtendedHeight: 277 - padding * 2
|
2022-06-09 15:27:14 +00:00
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
readonly property int tabsUpdateModeBaseHeight: 284 - padding * 2
|
|
|
|
readonly property int tabsUpdateModeExtendedHeight: tabsUpdateModeBaseHeight
|
|
|
|
+ (tabsAddModeExtendedHeight - tabsAddModeBaseHeight)
|
2022-06-09 15:27:14 +00:00
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
readonly property int backButtonWidth: 56
|
|
|
|
readonly property int backButtonHeight: 24
|
|
|
|
readonly property int backButtonToContentSpace: 8
|
|
|
|
|
|
|
|
readonly property string defaultTokenNameText: qsTr("Choose token")
|
|
|
|
readonly property string defaultCollectibleNameText: qsTr("Choose collectible")
|
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: statesStack
|
|
|
|
|
|
|
|
property alias currentState: content.state
|
|
|
|
property int size: 0
|
|
|
|
property var states: []
|
|
|
|
|
|
|
|
function push(state) {
|
|
|
|
states.push(state)
|
|
|
|
currentState = state
|
|
|
|
size++
|
|
|
|
}
|
2022-08-30 16:27:00 +00:00
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
function pop() {
|
|
|
|
states.pop()
|
|
|
|
currentState = states.length ? states[states.length - 1] : ""
|
|
|
|
size--
|
|
|
|
}
|
|
|
|
|
|
|
|
function clear() {
|
|
|
|
currentState = ""
|
|
|
|
size = 0
|
|
|
|
states = []
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-30 16:27:00 +00:00
|
|
|
contentItem: ColumnLayout {
|
|
|
|
id: content
|
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
spacing: d.backButtonToContentSpace
|
2022-08-30 16:27:00 +00:00
|
|
|
|
|
|
|
StatusIconTextButton {
|
|
|
|
id: backButton
|
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
Layout.preferredWidth: d.backButtonWidth
|
|
|
|
Layout.preferredHeight: d.backButtonHeight
|
|
|
|
|
|
|
|
visible: statesStack.size > 1
|
|
|
|
|
2022-08-30 16:27:00 +00:00
|
|
|
spacing: 0
|
2022-09-07 09:40:25 +00:00
|
|
|
leftPadding: 4
|
2022-08-30 16:27:00 +00:00
|
|
|
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: root; width: d.operatorsWidth; height: d.operatorsHeight }
|
|
|
|
},
|
|
|
|
State {
|
2022-09-07 09:40:25 +00:00
|
|
|
name: d.addState
|
2022-08-30 16:27:00 +00:00
|
|
|
PropertyChanges {target: loader; sourceComponent: tabsView}
|
2022-09-07 09:40:25 +00:00
|
|
|
PropertyChanges {target: root; height: undefined} // use implicit height
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: d.updateState
|
|
|
|
extend: d.addState
|
|
|
|
PropertyChanges {target: d; holdingsTabMode: HoldingsTabs.Mode.Update}
|
2022-08-30 16:27:00 +00:00
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: d.extendedState
|
|
|
|
PropertyChanges {target: loader; sourceComponent: extendedView}
|
2022-09-07 09:40:25 +00:00
|
|
|
PropertyChanges {target: root; height: d.extendedContentHeight}
|
2022-08-23 08:46:37 +00:00
|
|
|
}
|
2022-08-30 16:27:00 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: operatorsSelectorView
|
|
|
|
|
|
|
|
OperatorsSelector {
|
|
|
|
onOperatorSelected: {
|
2022-09-07 09:40:25 +00:00
|
|
|
d.operator = operator
|
|
|
|
statesStack.push(d.addState)
|
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-09-07 09:40:25 +00:00
|
|
|
readonly property var holdingTypes: [
|
|
|
|
HoldingTypes.Type.Token, HoldingTypes.Type.Collectible, HoldingTypes.Type.Ens
|
|
|
|
]
|
|
|
|
readonly property var labels: [qsTr("Token"), qsTr("Collectible"), qsTr("ENS")]
|
|
|
|
|
|
|
|
readonly property bool extendedHeight:
|
|
|
|
d.currentHoldingType === HoldingTypes.Type.Collectible && collectiblesSpecificAmount ||
|
|
|
|
d.currentHoldingType === HoldingTypes.Type.Ens && root.ensType === EnsPanel.EnsType.CustomSubdomain
|
|
|
|
|
|
|
|
implicitHeight: extendedHeight
|
|
|
|
? (mode === HoldingsTabs.Mode.Add ? d.tabsAddModeExtendedHeight : d.tabsUpdateModeExtendedHeight)
|
|
|
|
: (mode === HoldingsTabs.Mode.Add ? d.tabsAddModeBaseHeight : d.tabsUpdateModeBaseHeight)
|
|
|
|
|
2022-08-23 08:46:37 +00:00
|
|
|
states: [
|
|
|
|
State {
|
2022-09-07 09:40:25 +00:00
|
|
|
name: HoldingTypes.Type.Token
|
|
|
|
PropertyChanges {target: holdingsTabs; sourceComponent: tokensLayout; addOrUpdateButtonEnabled: d.tokensReady}
|
2022-08-23 08:46:37 +00:00
|
|
|
},
|
|
|
|
State {
|
2022-09-07 09:40:25 +00:00
|
|
|
name: HoldingTypes.Type.Collectible
|
|
|
|
PropertyChanges {target: holdingsTabs; sourceComponent: collectiblesLayout; addOrUpdateButtonEnabled: d.collectiblesReady}
|
2022-08-23 08:46:37 +00:00
|
|
|
},
|
|
|
|
State {
|
2022-09-07 09:40:25 +00:00
|
|
|
name: HoldingTypes.Type.Ens
|
|
|
|
PropertyChanges {target: holdingsTabs; sourceComponent: ensLayout; addOrUpdateButtonEnabled: d.ensReady}
|
2022-08-23 08:46:37 +00:00
|
|
|
}
|
|
|
|
]
|
2022-08-30 16:27:00 +00:00
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
tabLabels: labels
|
|
|
|
state: d.currentHoldingType
|
|
|
|
mode: d.holdingsTabMode
|
2022-08-30 16:27:00 +00:00
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
currentIndex: holdingTypes.indexOf(d.currentHoldingType)
|
|
|
|
onCurrentIndexChanged: d.currentHoldingType = holdingTypes[currentIndex]
|
2022-08-30 16:27:00 +00:00
|
|
|
|
|
|
|
onAddClicked: d.addClicked()
|
2022-09-07 09:40:25 +00:00
|
|
|
onUpdateClicked: d.updateClicked()
|
|
|
|
onRemoveClicked: root.removeClicked()
|
2022-08-30 16:27:00 +00:00
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: backButton
|
|
|
|
|
|
|
|
function onClicked() {
|
2022-09-07 09:40:25 +00:00
|
|
|
statesStack.pop()
|
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
|
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
tokenName: d.defaultTokenNameText
|
2022-08-30 16:27:00 +00:00
|
|
|
amount: root.tokenAmount === 0 ? "" : root.tokenAmount.toString()
|
|
|
|
onAmountChanged: root.tokenAmount = Number(amount)
|
|
|
|
|
|
|
|
onPickerClicked: {
|
|
|
|
d.extendedDropdownType = ExtendedDropdownContent.Type.Tokens
|
2022-09-07 09:40:25 +00:00
|
|
|
statesStack.push(d.extendedState)
|
2022-08-23 08:46:37 +00:00
|
|
|
}
|
|
|
|
|
2022-08-30 16:27:00 +00:00
|
|
|
Connections {
|
|
|
|
target: d
|
|
|
|
|
|
|
|
function onAddClicked() {
|
2022-09-07 09:40:25 +00:00
|
|
|
root.addToken(root.tokenKey, root.tokenAmount, d.operator)
|
|
|
|
}
|
|
|
|
|
|
|
|
function onUpdateClicked() {
|
|
|
|
root.updateToken(root.tokenKey, root.tokenAmount)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
readonly property string tokenKey: root.tokenKey
|
|
|
|
|
|
|
|
onTokenKeyChanged: {
|
|
|
|
const modelItem = store.getTokenByKey(tokenKey)
|
|
|
|
|
|
|
|
if (modelItem) {
|
|
|
|
tokensPanel.tokenName = modelItem.name
|
|
|
|
tokensPanel.tokenImage = modelItem.iconSource
|
|
|
|
} else {
|
|
|
|
tokensPanel.tokenName = d.defaultTokenNameText
|
|
|
|
tokensPanel.tokenImage = ""
|
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 {
|
2022-09-07 09:40:25 +00:00
|
|
|
id: collectiblesPanel
|
|
|
|
|
|
|
|
collectibleName: d.defaultCollectibleNameText
|
|
|
|
|
2022-08-30 16:27:00 +00:00
|
|
|
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
|
2022-09-07 09:40:25 +00:00
|
|
|
statesStack.push(d.extendedState)
|
2022-08-23 08:46:37 +00:00
|
|
|
}
|
|
|
|
|
2022-08-30 16:27:00 +00:00
|
|
|
Connections {
|
|
|
|
target: d
|
|
|
|
|
|
|
|
function onAddClicked() {
|
2022-09-07 09:40:25 +00:00
|
|
|
root.addCollectible(root.collectibleKey, root.collectibleAmount, d.operator)
|
|
|
|
}
|
|
|
|
|
|
|
|
function onUpdateClicked() {
|
|
|
|
root.updateCollectible(root.collectibleKey, root.collectibleAmount)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
readonly property string collectibleKey: root.collectibleKey
|
|
|
|
|
|
|
|
onCollectibleKeyChanged: {
|
|
|
|
const modelItem = store.getCollectibleByKey(collectibleKey)
|
|
|
|
|
|
|
|
if (modelItem) {
|
|
|
|
collectiblesPanel.collectibleName = modelItem.name
|
|
|
|
collectiblesPanel.collectibleImage = modelItem.iconSource
|
|
|
|
} else {
|
|
|
|
collectiblesPanel.collectibleName = d.defaultCollectibleNameText
|
|
|
|
collectiblesPanel.collectibleImage = ""
|
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
|
2022-09-07 09:40:25 +00:00
|
|
|
onDomainNameValidChanged: d.ensDomainNameValid = domainNameValid
|
2022-08-31 12:35:28 +00:00
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: d
|
|
|
|
|
|
|
|
function onAddClicked() {
|
2022-09-07 09:40:25 +00:00
|
|
|
root.addEns(root.ensType === EnsPanel.EnsType.Any, root.ensDomainName, d.operator)
|
|
|
|
}
|
|
|
|
|
|
|
|
function onUpdateClicked() {
|
|
|
|
root.updateEns(root.ensType === EnsPanel.EnsType.Any, root.ensDomainName)
|
2022-08-31 12:35:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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: {
|
2022-09-07 09:40:25 +00:00
|
|
|
statesStack.pop()
|
2022-08-30 16:27:00 +00:00
|
|
|
|
2022-09-07 09:40:25 +00:00
|
|
|
if(d.extendedDropdownType === ExtendedDropdownContent.Type.Tokens)
|
|
|
|
root.tokenKey = key
|
|
|
|
else
|
|
|
|
root.collectibleKey = 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
|
2022-09-07 09:40:25 +00:00
|
|
|
statesStack.pop()
|
2022-08-30 16:27:00 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|
2022-08-23 08:46:37 +00:00
|
|
|
}
|
2022-06-09 15:27:14 +00:00
|
|
|
}
|