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

81 lines
1.9 KiB
QML
Raw Normal View History

import QtQuick 2.15
import QtQuick.Controls 2.15
import StatusQ.Controls 0.1
import StatusQ.Core.Utils 0.1
import AppLayouts.Wallet.panels 1.0
import utils 1.0
Control {
id: root
/** Expected model structure: see SearchableAssetsPanel::model **/
2024-09-10 12:56:19 +00:00
property alias model: searchableAssetsPanel.model
property alias nonInteractiveKey: searchableAssetsPanel.nonInteractiveKey
2024-09-10 12:56:19 +00:00
property alias sectionProperty: searchableAssetsPanel.sectionProperty
2024-09-10 12:56:19 +00:00
readonly property bool isSelected: button.selected
2024-09-10 12:56:19 +00:00
signal selected(string key)
2024-09-10 12:56:19 +00:00
function setCustom(name: string, icon: url, key: string) {
button.name = name
button.icon = icon
button.selected = true
2024-09-10 12:56:19 +00:00
searchableAssetsPanel.highlightedKey = key ?? ""
}
function reset() {
button.selected = false
searchableAssetsPanel.highlightedKey = ""
}
contentItem: TokenSelectorButton {
2024-09-10 12:56:19 +00:00
id: button
forceHovered: dropdown.opened
text: qsTr("Select asset")
onClicked: dropdown.opened ? dropdown.close() : dropdown.open()
}
StatusDropdown {
id: dropdown
y: root.height + 4
x: root.width - width
width: 448
2024-09-10 12:56:19 +00:00
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
padding: 0
contentItem: SearchableAssetsPanel {
id: searchableAssetsPanel
objectName: "searchableAssetsPanel"
function setCurrentAndClose(name, icon) {
2024-09-10 12:56:19 +00:00
button.name = name
button.icon = icon
button.selected = true
dropdown.close()
}
onSelected: {
2024-09-10 12:56:19 +00:00
const entry = ModelUtils.getByKey(root.model, "tokensKey", key)
highlightedKey = key
setCurrentAndClose(entry.symbol, entry.iconSource)
2024-09-10 12:56:19 +00:00
root.selected(key)
}
}
onClosed: searchableAssetsPanel.clearSearch()
}
}