2024-06-07 12:27:56 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
import QtQml 2.15
|
|
|
|
|
|
|
|
import StatusQ 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1 as StatusQUtils
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
import shared.controls 1.0
|
|
|
|
|
|
|
|
/**
|
|
|
|
Expected model structure:
|
|
|
|
name [string] - account name e.g. "Piggy Bank"
|
|
|
|
address [string] - wallet account address e.g. "0x1234567890"
|
|
|
|
colorizedChainPrefixes [string] - chain prefixes with rich text colors e.g. "<font color=\"red\">eth:</font><font color=\"blue\">oeth:</font><font color=\"green\">arb:</font>"
|
|
|
|
emoji [string] - emoji for account e.g. "🐷"
|
|
|
|
colorId [string] - color id for account e.g. "1"
|
|
|
|
currencyBalance [var] - fiat currency balance
|
|
|
|
amount [number] - amount of currency e.g. 1234
|
|
|
|
symbol [string] - currency symbol e.g. "USD"
|
2024-06-25 11:10:46 +00:00
|
|
|
displayDecimals [number] - optional number of decimals to display
|
2024-06-07 12:27:56 +00:00
|
|
|
stripTrailingZeroes [bool] - strip trailing zeroes
|
|
|
|
walletType [string] - wallet type e.g. Constants.watchWalletType. See `Constants` for possible values
|
|
|
|
migratedToKeycard [bool] - whether account is migrated to keycard
|
|
|
|
accountBalance [var] - account balance for a specific network
|
|
|
|
formattedBalance [string] - formatted balance e.g. "1234.56B"
|
|
|
|
balance [string] - balance e.g. "123456000000"
|
|
|
|
iconUrl [string] - icon url e.g. "network/Network=Hermez"
|
|
|
|
chainColor [string] - chain color e.g. "#FF0000"
|
|
|
|
**/
|
|
|
|
|
|
|
|
StatusComboBox {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
// input property for programatic selection
|
|
|
|
property string selectedAddress: ""
|
|
|
|
// output property for selected account
|
|
|
|
readonly property alias currentAccount: selectedEntry.item
|
2024-06-25 11:10:46 +00:00
|
|
|
readonly property string currentAccountAddress: d.currentAccountSelection
|
2024-06-07 12:27:56 +00:00
|
|
|
|
|
|
|
// styling options
|
|
|
|
type: StatusComboBox.Type.Secondary
|
|
|
|
size: StatusComboBox.Size.Small
|
|
|
|
|
2024-06-29 20:24:05 +00:00
|
|
|
currentIndex: 0
|
2024-06-07 12:27:56 +00:00
|
|
|
|
|
|
|
objectName: "accountSelector"
|
|
|
|
popupContentItemObjectName: "accountSelectorList"
|
|
|
|
|
|
|
|
control.popup.width: 430
|
|
|
|
|
|
|
|
control.valueRole: "address"
|
|
|
|
control.textRole: "name"
|
|
|
|
implicitHeight: control.implicitHeight
|
|
|
|
implicitWidth: control.implicitWidth
|
|
|
|
|
|
|
|
contentItem: RowLayout {
|
|
|
|
id: contentItemRow
|
|
|
|
|
|
|
|
spacing: 4
|
|
|
|
|
|
|
|
StatusSmartIdenticon {
|
|
|
|
id: assetContent
|
|
|
|
objectName: "assetContent"
|
|
|
|
asset.emoji: currentAccount.emoji ?? ""
|
|
|
|
asset.color: currentAccount.color ?? Theme.palette.baseColor1
|
|
|
|
asset.width: 24
|
|
|
|
asset.height: asset.width
|
|
|
|
asset.isLetterIdenticon: !!currentAccount.emoji
|
|
|
|
asset.bgColor: Theme.palette.primaryColor3
|
|
|
|
visible: !!currentAccount.emoji
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
id: textContent
|
|
|
|
objectName: "textContent"
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
text: currentAccount.name ?? ""
|
|
|
|
horizontalAlignment: Text.AlignLeft
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
elide: Text.ElideRight
|
|
|
|
font.pixelSize: 13
|
|
|
|
color: Theme.palette.directColor1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delegate: WalletAccountListItem {
|
|
|
|
id: delegateItem
|
|
|
|
|
|
|
|
required property var model
|
|
|
|
|
2024-06-25 11:10:46 +00:00
|
|
|
tagsScrollBarVisible: false
|
|
|
|
|
2024-06-07 12:27:56 +00:00
|
|
|
width: ListView.view.width
|
|
|
|
name: model.name
|
|
|
|
address: model.address
|
|
|
|
chainShortNames: model.colorizedChainPrefixes ?? ""
|
|
|
|
emoji: model.emoji
|
|
|
|
walletColor: Utils.getColorForId(model.colorId)
|
|
|
|
currencyBalance: model.currencyBalance
|
|
|
|
walletType: model.walletType
|
|
|
|
migratedToKeycard: model.migratedToKeycard ?? false
|
|
|
|
accountBalance: model.accountBalance ?? null
|
|
|
|
color: sensor.containsMouse || highlighted ?
|
|
|
|
Theme.palette.baseColor2 :
|
|
|
|
!!currentAccount && currentAccount.name === model.name ? Theme.palette.statusListItem.highlightColor : "transparent"
|
|
|
|
onClicked: {
|
|
|
|
d.currentAccountSelection = model.address
|
|
|
|
control.popup.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ModelEntry {
|
|
|
|
id: selectedEntry
|
|
|
|
sourceModel: root.model ?? null
|
|
|
|
key: "address"
|
2024-06-25 11:10:46 +00:00
|
|
|
value: d.currentAccountSelection
|
2024-07-17 07:53:04 +00:00
|
|
|
onAvailableChanged: {
|
|
|
|
if (!available) {
|
|
|
|
d.resetSelection()
|
|
|
|
}
|
|
|
|
}
|
2024-06-07 12:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
2024-06-29 20:24:05 +00:00
|
|
|
property string currentAccountSelection: root.selectedAddress || root.currentValue
|
2024-06-07 12:27:56 +00:00
|
|
|
|
|
|
|
Binding on currentAccountSelection {
|
2024-06-29 20:24:05 +00:00
|
|
|
value: root.selectedAddress || root.currentValue
|
2024-06-07 12:27:56 +00:00
|
|
|
}
|
2024-07-17 07:53:04 +00:00
|
|
|
|
|
|
|
function resetSelection() {
|
|
|
|
currentAccountSelection = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
if (!selectedEntry.available)
|
|
|
|
d.resetSelection()
|
2024-06-07 12:27:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|