2023-11-22 19:58:02 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
2024-06-14 18:20:07 +00:00
|
|
|
|
|
|
|
import QtQml.Models 2.15
|
2021-10-05 20:50:22 +00:00
|
|
|
|
2023-11-24 12:16:13 +00:00
|
|
|
import StatusQ 0.1
|
2022-07-13 12:29:38 +00:00
|
|
|
import StatusQ.Core 0.1
|
2022-08-24 15:47:26 +00:00
|
|
|
import StatusQ.Core.Theme 0.1
|
2023-11-22 19:58:02 +00:00
|
|
|
import StatusQ.Popups.Dialog 0.1
|
2022-07-13 12:29:38 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
import AppLayouts.Wallet.controls 1.0
|
2022-11-23 17:58:22 +00:00
|
|
|
import shared.controls 1.0
|
2023-11-22 19:58:02 +00:00
|
|
|
import shared.popups 1.0
|
2024-06-14 18:20:07 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
import SortFilterProxyModel 0.2
|
2021-10-05 20:50:22 +00:00
|
|
|
|
2023-12-06 10:54:36 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
Control {
|
2022-08-08 21:12:12 +00:00
|
|
|
id: root
|
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
/**
|
|
|
|
Expected model structure:
|
|
|
|
|
|
|
|
key [string] - unique identifier of a token, e.g "0x3234235"
|
|
|
|
symbol [string] - token's symbol e.g. "ETH" or "SNT"
|
|
|
|
name [string] - token's name e.g. "Ether" or "Dai"
|
|
|
|
icon [url] - token's icon url
|
|
|
|
balance [double] - tokens balance is the commonly used unit, e.g. 1.2 for 1.2 ETH, used
|
|
|
|
for sorting and computing market value
|
|
|
|
balanceText [string] - formatted and localized balance. This is not done internally because
|
|
|
|
it may depend on many external factors
|
|
|
|
error [string] - error message related to balance
|
|
|
|
|
|
|
|
marketDetailsAvailable [bool] - specifies if market datails are available for given token
|
|
|
|
marketDetailsLoading [bool] - specifies if market datails are available for given token
|
|
|
|
marketPrice [double] - specifies market price in currently used currency
|
|
|
|
marketChangePct24hour [double] - percentage price change in last 24 hours, e.g. 0.5 for 0.5% of price change
|
|
|
|
|
|
|
|
communityId [string] - for community assets, unique identifier of a community, e.g. "0x6734235"
|
|
|
|
communityName [string] - for community assets, name of a community e.g. "Crypto Kitties"
|
|
|
|
communityIcon [url] - for community assets, community's icon url
|
2023-11-22 19:58:02 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
position [int] - if custom order available, display position defined by the user via token management
|
|
|
|
canBeHidden [bool] - specifies if given token can be hidden (e.g. ETH should be always visible)
|
|
|
|
**/
|
|
|
|
property var model
|
2022-08-08 21:12:12 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
// enables global loading state useful when real data are not yet available
|
|
|
|
property bool loading
|
2023-11-22 19:58:02 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
// shows/hides list sorter
|
|
|
|
property bool sorterVisible
|
|
|
|
|
|
|
|
// allows/disables choosing custom sort order from a sorter
|
|
|
|
property bool customOrderAvailable
|
|
|
|
|
|
|
|
// switches configuring right click menu
|
|
|
|
property bool sendEnabled: true
|
2024-08-02 09:24:40 +00:00
|
|
|
property bool communitySendEnabled: false
|
2024-06-14 18:20:07 +00:00
|
|
|
property bool swapEnabled: true
|
|
|
|
property bool swapVisible: true
|
2024-08-02 09:24:40 +00:00
|
|
|
property bool communitySwapVisible: false
|
2024-06-14 18:20:07 +00:00
|
|
|
|
|
|
|
property string balanceError
|
|
|
|
|
|
|
|
// global market data error, presented for all tokens expecting market data
|
|
|
|
property string marketDataError
|
|
|
|
|
|
|
|
// formatting function for fiat currency values
|
|
|
|
property var formatFiat: balance => `${balance.toLocaleString(Qt.locale())} XYZ`
|
|
|
|
|
|
|
|
signal sendRequested(string key)
|
|
|
|
signal receiveRequested(string key)
|
|
|
|
signal swapRequested(string key)
|
|
|
|
signal assetClicked(string key)
|
|
|
|
signal communityClicked(string communityKey)
|
|
|
|
signal hideRequested(string key)
|
2024-07-26 14:47:18 +00:00
|
|
|
signal hideCommunityAssetsRequested(string communityKey)
|
2024-06-14 18:20:07 +00:00
|
|
|
signal manageTokensRequested
|
2022-08-08 21:12:12 +00:00
|
|
|
|
2024-09-11 12:00:25 +00:00
|
|
|
function setSortOrder(order) {
|
|
|
|
d.sortOrder = order
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSortOrder() {
|
|
|
|
return d.sortOrder
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSortValue() {
|
|
|
|
return d.sortValue
|
|
|
|
}
|
|
|
|
|
|
|
|
function sortByValue(value) {
|
|
|
|
d.sortValue = value
|
|
|
|
}
|
|
|
|
|
2022-08-08 21:12:12 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
2024-06-14 18:20:07 +00:00
|
|
|
|
2023-11-24 12:16:13 +00:00
|
|
|
readonly property int loadingItemsCount: 25
|
2024-09-11 12:00:25 +00:00
|
|
|
property int sortOrder: Qt.DescendingOrder
|
|
|
|
property int sortValue: -1
|
2024-06-14 18:20:07 +00:00
|
|
|
}
|
2022-03-25 08:46:47 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
SortFilterProxyModel {
|
|
|
|
id: sfpm
|
|
|
|
|
|
|
|
sourceModel: root.model ?? null
|
|
|
|
|
|
|
|
proxyRoles: [
|
|
|
|
// helper role for rendering section delegate
|
|
|
|
FastExpressionRole {
|
|
|
|
name: "isCommunity"
|
|
|
|
expression: !!communityId ? "community" : ""
|
|
|
|
expectedRoles: ["communityId"]
|
|
|
|
},
|
|
|
|
FastExpressionRole {
|
|
|
|
name: "marketBalance"
|
|
|
|
expression: balance * marketPrice
|
|
|
|
expectedRoles: ["balance", "marketPrice"]
|
|
|
|
},
|
|
|
|
FastExpressionRole {
|
|
|
|
name: "change1DayFiat"
|
|
|
|
expression: marketBalance * (1 - (1 / (marketChangePct24hour / 100 + 1)))
|
|
|
|
expectedRoles: ["marketBalance", "marketChangePct24hour"]
|
2024-03-19 23:34:25 +00:00
|
|
|
}
|
2024-06-14 18:20:07 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
sorters: [
|
|
|
|
RoleSorter {
|
|
|
|
roleName: "isCommunity"
|
|
|
|
},
|
|
|
|
RoleSorter {
|
|
|
|
roleName: sortOrderComboBox.currentSortRoleName
|
|
|
|
sortOrder: sortOrderComboBox.currentSortOrder
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2023-12-06 10:54:36 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
contentItem: ColumnLayout {
|
|
|
|
ColumnLayout {
|
|
|
|
Layout.fillHeight: false
|
|
|
|
Layout.preferredHeight: root.sorterVisible ? implicitHeight : 0
|
|
|
|
|
|
|
|
opacity: root.sorterVisible ? 1 : 0
|
|
|
|
spacing: 20
|
|
|
|
visible: opacity > 0
|
|
|
|
|
|
|
|
Behavior on Layout.preferredHeight {
|
|
|
|
NumberAnimation { duration: 200; easing.type: Easing.InOutQuad }
|
2023-11-22 19:58:02 +00:00
|
|
|
}
|
2023-11-24 12:16:13 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
Behavior on opacity {
|
|
|
|
NumberAnimation { duration: 200; easing.type: Easing.InOutQuad }
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusDialogDivider { Layout.fillWidth: true }
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: false
|
|
|
|
|
|
|
|
spacing: Style.current.halfPadding
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
font.pixelSize: Style.current.additionalTextSize
|
|
|
|
text: qsTr("Sort by:")
|
2023-11-24 12:16:13 +00:00
|
|
|
}
|
2024-06-14 18:20:07 +00:00
|
|
|
|
|
|
|
SortOrderComboBox {
|
|
|
|
id: sortOrderComboBox
|
|
|
|
|
|
|
|
objectName: "cmbTokenOrder"
|
|
|
|
hasCustomOrderDefined: root.customOrderAvailable
|
2024-09-11 12:00:25 +00:00
|
|
|
Binding on currentIndex {
|
|
|
|
value: {
|
|
|
|
sortOrderComboBox.count
|
|
|
|
let id = sortOrderComboBox.indexOfValue(d.sortValue)
|
|
|
|
if (id === -1)
|
|
|
|
id = sortOrderComboBox.indexOfValue(SortOrderComboBox.TokenOrderAlpha)
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
when: sortOrderComboBox.count > 0
|
|
|
|
}
|
|
|
|
onCurrentValueChanged: d.sortValue = sortOrderComboBox.currentValue
|
|
|
|
Binding on currentSortOrder {
|
|
|
|
value: d.sortOrder
|
|
|
|
}
|
|
|
|
onCurrentSortOrderChanged: d.sortOrder = sortOrderComboBox.currentSortOrder
|
2024-06-14 18:20:07 +00:00
|
|
|
model: [
|
|
|
|
{ value: SortOrderComboBox.TokenOrderCurrencyBalance,
|
|
|
|
text: qsTr("Asset balance value"), icon: "", sortRoleName: "marketBalance" },
|
|
|
|
{ value: SortOrderComboBox.TokenOrderBalance,
|
|
|
|
text: qsTr("Asset balance"), icon: "", sortRoleName: "balance" },
|
|
|
|
{ value: SortOrderComboBox.TokenOrderCurrencyPrice,
|
|
|
|
text: qsTr("Asset value"), icon: "", sortRoleName: "marketPrice" },
|
|
|
|
{ value: SortOrderComboBox.TokenOrder1DChange,
|
|
|
|
text: qsTr("1d change: balance value"), icon: "", sortRoleName: "change1DayFiat" },
|
|
|
|
{ value: SortOrderComboBox.TokenOrderAlpha,
|
|
|
|
text: qsTr("Asset name"), icon: "", sortRoleName: "name" },
|
|
|
|
{ value: SortOrderComboBox.TokenOrderCustom,
|
|
|
|
text: qsTr("Custom order"), icon: "", sortRoleName: "position" },
|
|
|
|
{ value: SortOrderComboBox.TokenOrderNone,
|
|
|
|
text: "---", icon: "", sortRoleName: "" }, // separator
|
|
|
|
{ value: SortOrderComboBox.TokenOrderCreateCustom,
|
|
|
|
text: hasCustomOrderDefined ? qsTr("Edit custom order →") : qsTr("Create custom order →"),
|
|
|
|
icon: "", sortRoleName: "" }
|
|
|
|
]
|
|
|
|
onCreateOrEditRequested: {
|
|
|
|
root.manageTokensRequested()
|
2023-11-24 12:16:13 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-14 18:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StatusDialogDivider { Layout.fillWidth: true }
|
2023-11-24 12:16:13 +00:00
|
|
|
}
|
2023-11-22 19:58:02 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
DelegateModel {
|
|
|
|
id: regularModel
|
2022-08-24 15:47:26 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
model: sfpm
|
2024-01-24 12:02:03 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
delegate: TokenDelegate {
|
|
|
|
objectName: `AssetView_TokenListItem_${model.symbol}`
|
|
|
|
|
|
|
|
width: ListView.view.width
|
2024-01-24 12:02:03 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
name: model.name
|
|
|
|
icon: model.icon
|
|
|
|
balance: model.balanceText
|
|
|
|
marketBalance: root.formatFiat(model.marketBalance)
|
2023-11-22 19:58:02 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
marketDetailsAvailable: model.marketDetailsAvailable
|
|
|
|
marketDetailsLoading: model.marketDetailsLoading
|
|
|
|
marketCurrencyPrice: root.formatFiat(model.change1DayFiat)
|
|
|
|
marketChangePct24hour: model.marketChangePct24hour
|
2023-11-22 19:58:02 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
communityId: model.communityId
|
|
|
|
communityName: model.communityName ?? ""
|
|
|
|
communityIcon: model.communityIcon ?? ""
|
2023-11-22 19:58:02 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
errorTooltipText_1: model.error
|
|
|
|
errorTooltipText_2: root.marketDataError
|
2023-12-06 10:54:36 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
errorMode: !!root.balanceError
|
|
|
|
errorIcon.tooltip.text: root.balanceError
|
2023-12-06 10:54:36 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
onClicked: {
|
|
|
|
if (mouse.button === Qt.LeftButton)
|
|
|
|
root.assetClicked(model.key)
|
|
|
|
else if (mouse.button === Qt.RightButton)
|
|
|
|
tokenContextMenu.createObject(this, { model }).popup(mouse)
|
2023-12-06 10:54:36 +00:00
|
|
|
}
|
2024-06-14 18:20:07 +00:00
|
|
|
|
|
|
|
onCommunityClicked: root.communityClicked(model.communityId)
|
2023-11-22 19:58:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
DelegateModel {
|
|
|
|
id: loadingModel
|
|
|
|
|
|
|
|
model: d.loadingItemsCount
|
|
|
|
|
|
|
|
delegate: LoadingTokenDelegate {
|
|
|
|
objectName: `AssetView_LoadingTokenDelegate_${model.index}`
|
2023-11-22 19:58:02 +00:00
|
|
|
|
2023-12-18 10:12:57 +00:00
|
|
|
width: ListView.view.width
|
2023-11-24 12:16:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
StatusListView {
|
|
|
|
id: listView
|
2023-12-06 10:54:36 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
objectName: "assetViewStatusListView"
|
2023-11-22 19:58:02 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
2023-12-06 10:54:36 +00:00
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
model: root.loading ? loadingModel : regularModel
|
|
|
|
|
|
|
|
section {
|
|
|
|
property: "isCommunity"
|
|
|
|
delegate: AssetsSectionDelegate {
|
|
|
|
width: parent.width
|
|
|
|
text: qsTr("Community minted")
|
|
|
|
onInfoButtonClicked: communityInfoPopup.createObject(this).open()
|
2023-11-22 19:58:02 +00:00
|
|
|
}
|
2022-08-08 21:12:12 +00:00
|
|
|
}
|
2023-11-22 19:58:02 +00:00
|
|
|
}
|
2023-12-06 10:54:36 +00:00
|
|
|
}
|
2023-11-22 19:58:02 +00:00
|
|
|
|
2023-12-06 10:54:36 +00:00
|
|
|
Component {
|
|
|
|
id: tokenContextMenu
|
2024-06-14 18:20:07 +00:00
|
|
|
|
|
|
|
AssetContextMenu {
|
|
|
|
required property var model
|
|
|
|
|
|
|
|
readonly property string key: model.key
|
|
|
|
readonly property string communityKey: model.communityId
|
|
|
|
|
2024-08-02 09:24:40 +00:00
|
|
|
readonly property bool isCommunity: !!model.isCommunity
|
|
|
|
|
2023-12-06 10:54:36 +00:00
|
|
|
onClosed: destroy()
|
|
|
|
|
2024-06-14 18:20:07 +00:00
|
|
|
sendEnabled: root.sendEnabled
|
2024-08-02 09:24:40 +00:00
|
|
|
&& (!isCommunity || root.communitySendEnabled)
|
2024-06-14 18:20:07 +00:00
|
|
|
swapEnabled: root.swapEnabled
|
2024-08-02 09:24:40 +00:00
|
|
|
swapVisible: root.swapVisible && (!isCommunity || root.communitySwapVisible)
|
2024-06-14 18:20:07 +00:00
|
|
|
hideVisible: model.canBeHidden
|
2024-08-02 09:24:40 +00:00
|
|
|
communityHideVisible: isCommunity
|
2024-06-14 18:20:07 +00:00
|
|
|
|
|
|
|
onSendRequested: root.sendRequested(key)
|
|
|
|
onReceiveRequested: root.receiveRequested(key)
|
|
|
|
onSwapRequested: root.swapRequested(key)
|
|
|
|
|
2024-07-26 14:47:18 +00:00
|
|
|
onHideRequested: root.hideRequested(key)
|
|
|
|
onCommunityHideRequested: root.hideCommunityAssetsRequested(communityKey)
|
2024-06-14 18:20:07 +00:00
|
|
|
|
|
|
|
onManageTokensRequested: root.manageTokensRequested()
|
2023-11-22 19:58:02 +00:00
|
|
|
}
|
2023-12-06 10:54:36 +00:00
|
|
|
}
|
2023-11-22 19:58:02 +00:00
|
|
|
|
2023-12-06 10:54:36 +00:00
|
|
|
Component {
|
2024-06-14 18:20:07 +00:00
|
|
|
id: communityInfoPopup
|
|
|
|
|
|
|
|
CommunityAssetsInfoPopup {
|
|
|
|
destroyOnClose: true
|
|
|
|
}
|
2023-12-06 10:54:36 +00:00
|
|
|
}
|
2021-10-05 20:50:22 +00:00
|
|
|
}
|