2022-07-21 08:40:49 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
|
|
|
|
2022-08-18 20:49:50 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
2022-07-21 08:40:49 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Components 0.1
|
2022-08-18 20:49:50 +00:00
|
|
|
import StatusQ.Core.Backpressure 1.0
|
|
|
|
|
|
|
|
import shared.controls 1.0
|
2022-07-21 08:40:49 +00:00
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
2022-08-03 12:15:13 +00:00
|
|
|
|
2022-07-21 08:40:49 +00:00
|
|
|
property var assets
|
|
|
|
property var selectedAsset
|
2022-08-03 12:15:13 +00:00
|
|
|
property string defaultToken: ""
|
|
|
|
property string userSelectedToken: ""
|
2022-07-21 08:40:49 +00:00
|
|
|
property var tokenAssetSourceFn: function (symbol) {
|
|
|
|
return ""
|
|
|
|
}
|
2022-08-29 16:28:54 +00:00
|
|
|
property var searchTokenSymbolByAddressFn: function (address) {
|
2022-08-18 20:49:50 +00:00
|
|
|
return ""
|
|
|
|
}
|
2022-08-03 12:15:13 +00:00
|
|
|
|
2022-07-21 08:40:49 +00:00
|
|
|
// Define this in the usage to get balance in currency selected by user
|
|
|
|
property var getCurrencyBalanceString: function (currencyBalance) { return "" }
|
2022-11-23 17:58:22 +00:00
|
|
|
property string placeholderText
|
2022-07-21 08:40:49 +00:00
|
|
|
|
|
|
|
function resetInternal() {
|
|
|
|
assets = null
|
|
|
|
selectedAsset = null
|
|
|
|
}
|
|
|
|
|
2022-11-23 17:58:22 +00:00
|
|
|
implicitWidth: comboBox.width
|
2022-08-03 12:15:13 +00:00
|
|
|
implicitHeight: comboBox.implicitHeight
|
|
|
|
|
2022-07-21 08:40:49 +00:00
|
|
|
onSelectedAssetChanged: {
|
|
|
|
if (selectedAsset && selectedAsset.symbol) {
|
2022-08-03 12:15:13 +00:00
|
|
|
d.iconSource = tokenAssetSourceFn(selectedAsset.symbol.toUpperCase())
|
|
|
|
d.text = selectedAsset.symbol.toUpperCase()
|
2022-07-21 08:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-03 12:15:13 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
property string iconSource: ""
|
|
|
|
property string text: ""
|
2022-08-18 20:49:50 +00:00
|
|
|
property string searchString
|
|
|
|
|
|
|
|
readonly property var updateSearchText: Backpressure.debounce(root, 1000, function(inputText) {
|
|
|
|
d.searchString = inputText
|
|
|
|
})
|
2022-08-03 12:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StatusComboBox {
|
|
|
|
id: comboBox
|
2022-08-09 13:52:17 +00:00
|
|
|
objectName: "assetSelectorButton"
|
2022-11-23 17:58:22 +00:00
|
|
|
width: control.width
|
2022-08-03 12:15:13 +00:00
|
|
|
height: parent.height
|
|
|
|
|
|
|
|
control.padding: 4
|
|
|
|
control.popup.width: 342
|
2022-08-03 13:41:24 +00:00
|
|
|
control.popup.height: 416
|
2022-08-03 12:15:13 +00:00
|
|
|
control.popup.x: width - control.popup.width
|
2022-08-09 13:52:17 +00:00
|
|
|
|
|
|
|
popupContentItemObjectName: "assetSelectorList"
|
2022-08-03 12:15:13 +00:00
|
|
|
|
2022-08-18 20:49:50 +00:00
|
|
|
model : SortFilterProxyModel {
|
|
|
|
sourceModel: root.assets
|
|
|
|
filters: [
|
|
|
|
ExpressionFilter {
|
|
|
|
expression: {
|
2022-08-29 16:28:54 +00:00
|
|
|
var tokenSymbolByAddress = searchTokenSymbolByAddressFn(d.searchString)
|
2022-12-06 09:49:57 +00:00
|
|
|
return visibleForNetwork && (
|
2022-11-03 14:11:13 +00:00
|
|
|
symbol.startsWith(d.searchString.toUpperCase()) || name.toUpperCase().startsWith(d.searchString.toUpperCase()) || (tokenSymbolByAddress!=="" && symbol.startsWith(tokenSymbolByAddress))
|
|
|
|
)
|
2022-08-18 20:49:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2022-08-03 12:15:13 +00:00
|
|
|
|
|
|
|
control.background: Rectangle {
|
2022-08-03 13:41:24 +00:00
|
|
|
color: "transparent"
|
|
|
|
border.width: 1
|
|
|
|
border.color: comboBox.control.hovered ? Theme.palette.primaryColor2 : Theme.palette.directColor8
|
|
|
|
radius: 16
|
2022-11-23 17:58:22 +00:00
|
|
|
width: rowLayout.width
|
|
|
|
implicitHeight: 48
|
2022-08-03 12:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
contentItem: RowLayout {
|
2022-11-23 17:58:22 +00:00
|
|
|
id: rowLayout
|
2022-08-03 13:41:24 +00:00
|
|
|
spacing: 8
|
|
|
|
StatusBaseText {
|
|
|
|
Layout.leftMargin: 8
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
font.pixelSize: 15
|
|
|
|
elide: Text.ElideRight
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
2022-11-23 17:58:22 +00:00
|
|
|
color: !!root.selectedAsset ? Theme.palette.directColor1: Theme.palette.baseColor1
|
2022-08-03 13:41:24 +00:00
|
|
|
font.weight: Font.Medium
|
2022-11-23 17:58:22 +00:00
|
|
|
text: !!root.selectedAsset ? d.text : placeholderText
|
2022-08-03 13:41:24 +00:00
|
|
|
}
|
2022-08-03 12:15:13 +00:00
|
|
|
StatusRoundedImage {
|
2022-08-03 13:41:24 +00:00
|
|
|
Layout.preferredWidth: 40
|
|
|
|
Layout.preferredHeight: 40
|
2022-08-03 12:15:13 +00:00
|
|
|
Layout.alignment: Qt.AlignVCenter
|
2022-11-23 17:58:22 +00:00
|
|
|
visible: !!d.iconSource
|
2022-08-03 12:15:13 +00:00
|
|
|
image.source: d.iconSource
|
|
|
|
image.onStatusChanged: {
|
|
|
|
if (image.status === Image.Error) {
|
|
|
|
image.source = defaultToken
|
2022-07-21 08:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-23 17:58:22 +00:00
|
|
|
Item {
|
|
|
|
width: 8
|
|
|
|
height: 0
|
|
|
|
}
|
2022-07-21 08:40:49 +00:00
|
|
|
}
|
|
|
|
|
2022-08-03 13:41:24 +00:00
|
|
|
control.indicator: null
|
|
|
|
|
2022-08-03 12:15:13 +00:00
|
|
|
delegate: StatusItemDelegate {
|
|
|
|
width: comboBox.control.popup.width
|
|
|
|
highlighted: index === comboBox.control.highlightedIndex
|
|
|
|
padding: 16
|
2022-08-18 17:51:18 +00:00
|
|
|
objectName: "AssetSelector_ItemDelegate_" + symbol
|
2022-08-03 12:15:13 +00:00
|
|
|
onClicked: {
|
|
|
|
// WARNING: Wrong ComboBox value processing. Check `StatusAccountSelector` for more info.
|
|
|
|
root.userSelectedToken = symbol
|
2022-10-17 10:17:25 +00:00
|
|
|
root.selectedAsset = {name: name, symbol: symbol, totalBalance: totalBalance, totalCurrencyBalance: totalCurrencyBalance, balances: balances, decimals: decimals}
|
2022-08-03 12:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// WARNING: Wrong ComboBox value processing. Check `StatusAccountSelector` for more info.
|
|
|
|
Component.onCompleted: {
|
2022-11-23 17:58:22 +00:00
|
|
|
if (symbol === userSelectedToken)
|
2022-10-17 10:17:25 +00:00
|
|
|
root.selectedAsset = { name: name, symbol: symbol, totalBalance: totalBalance, totalCurrencyBalance: totalCurrencyBalance, balances: balances, decimals: decimals}
|
2022-08-03 12:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
contentItem: RowLayout {
|
|
|
|
spacing: 0
|
|
|
|
|
2022-07-21 08:40:49 +00:00
|
|
|
StatusRoundedImage {
|
|
|
|
image.source: root.tokenAssetSourceFn(symbol.toUpperCase())
|
|
|
|
image.onStatusChanged: {
|
2022-08-03 12:15:13 +00:00
|
|
|
if (image.status === Image.Error) {
|
|
|
|
image.source = defaultToken
|
2022-07-21 08:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-03 12:15:13 +00:00
|
|
|
ColumnLayout {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.leftMargin: 12
|
|
|
|
spacing: 0
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
text: symbol.toUpperCase()
|
|
|
|
font.pixelSize: 15
|
|
|
|
color: Theme.palette.directColor1
|
|
|
|
}
|
|
|
|
StatusBaseText {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
horizontalAlignment: Text.AlignRight
|
|
|
|
font.pixelSize: 15
|
|
|
|
text: parseFloat(totalBalance).toLocaleCurrencyString(Qt.locale(), symbol)
|
|
|
|
}
|
2022-07-21 08:40:49 +00:00
|
|
|
}
|
2022-08-03 12:15:13 +00:00
|
|
|
RowLayout {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
StatusBaseText {
|
|
|
|
Layout.fillWidth: true
|
2022-08-03 13:41:24 +00:00
|
|
|
elide: Text.ElideRight
|
2022-08-03 12:15:13 +00:00
|
|
|
text: name
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
font.pixelSize: 15
|
|
|
|
}
|
|
|
|
StatusBaseText {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
horizontalAlignment: Text.AlignRight
|
|
|
|
font.pixelSize: 15
|
|
|
|
text: getCurrencyBalanceString(totalCurrencyBalance)
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
}
|
2022-07-21 08:40:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-18 20:49:50 +00:00
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
control.currentIndex = -1
|
|
|
|
control.popup.contentItem.header = searchBox
|
|
|
|
}
|
|
|
|
|
|
|
|
control.popup.onOpened: {
|
|
|
|
control.currentIndex = -1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: searchBox
|
|
|
|
StatusInput {
|
|
|
|
width: parent.width
|
|
|
|
input.showBackground: false
|
|
|
|
placeholderText: qsTr("Search for token or enter token address")
|
|
|
|
onTextChanged: Qt.callLater(d.updateSearchText, text)
|
|
|
|
input.clearable: true
|
|
|
|
leftPadding: 0
|
|
|
|
rightPadding: 0
|
|
|
|
input.rightComponent: StatusIcon {
|
|
|
|
width: 24
|
|
|
|
height: 24
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
icon: "search"
|
|
|
|
}
|
|
|
|
Rectangle {
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
height: 1
|
|
|
|
width: parent.width
|
|
|
|
color: Theme.palette.baseColor2
|
|
|
|
}
|
|
|
|
}
|
2022-07-21 08:40:49 +00:00
|
|
|
}
|
|
|
|
}
|