2020-07-30 05:18:54 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
|
|
|
import QtGraphicalEffects 1.13
|
|
|
|
import "../imports"
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Choose account"
|
|
|
|
property string label: qsTrId("choose-account")
|
2020-08-14 19:19:08 +00:00
|
|
|
property bool showAccountDetails: true
|
2020-07-30 05:18:54 +00:00
|
|
|
property var accounts
|
2020-08-20 04:45:29 +00:00
|
|
|
property var selectedAccount
|
2020-08-06 02:33:30 +00:00
|
|
|
property string currency: "usd"
|
2020-08-14 19:19:08 +00:00
|
|
|
height: select.height +
|
|
|
|
(selectedAccountDetails.visible ? selectedAccountDetails.height : 0)
|
2020-07-30 05:18:54 +00:00
|
|
|
// set to asset symbol to display asset's balance top right
|
|
|
|
// NOTE: if this asset is not selected as a wallet token in the UI, then
|
|
|
|
// nothing will be displayed
|
2020-09-01 03:49:05 +00:00
|
|
|
property string showBalanceForAssetSymbol: ""
|
|
|
|
property var assetFound
|
|
|
|
property double minRequiredAssetBalance: 0
|
2020-08-06 07:25:53 +00:00
|
|
|
property int dropdownWidth: width
|
2020-08-13 08:24:51 +00:00
|
|
|
property alias dropdownAlignment: select.menuAlignment
|
2020-08-20 04:45:29 +00:00
|
|
|
property bool isValid: true
|
|
|
|
property var reset: function() {}
|
|
|
|
|
|
|
|
function resetInternal() {
|
|
|
|
accounts = undefined
|
|
|
|
selectedAccount = undefined
|
2020-09-01 03:49:05 +00:00
|
|
|
showBalanceForAssetSymbol = ""
|
|
|
|
minRequiredAssetBalance = 0
|
|
|
|
assetFound = undefined
|
2020-08-20 04:45:29 +00:00
|
|
|
isValid = true
|
|
|
|
}
|
|
|
|
|
2020-09-01 03:49:05 +00:00
|
|
|
function validate() {
|
|
|
|
if (showBalanceForAssetSymbol == "" || minRequiredAssetBalance == 0 || !assetFound) {
|
|
|
|
return root.isValid
|
|
|
|
}
|
2020-09-10 06:50:38 +00:00
|
|
|
root.isValid = assetFound.value >= minRequiredAssetBalance
|
2020-09-01 03:49:05 +00:00
|
|
|
return root.isValid
|
|
|
|
}
|
|
|
|
|
2020-08-20 04:45:29 +00:00
|
|
|
onSelectedAccountChanged: {
|
|
|
|
if (!selectedAccount) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (selectedAccount.iconColor) {
|
|
|
|
selectedIconImgOverlay.color = selectedAccount.iconColor
|
|
|
|
}
|
|
|
|
if (selectedAccount.name) {
|
|
|
|
selectedTextField.text = selectedAccount.name
|
|
|
|
}
|
|
|
|
if (selectedAccount.address) {
|
|
|
|
textSelectedAddress.text = selectedAccount.address + " • "
|
|
|
|
}
|
|
|
|
if (selectedAccount.fiatBalance) {
|
|
|
|
textSelectedAddressFiatBalance.text = selectedAccount.fiatBalance + " " + currency.toUpperCase()
|
|
|
|
}
|
2020-09-01 03:49:05 +00:00
|
|
|
if (selectedAccount.assets && showBalanceForAssetSymbol) {
|
|
|
|
assetFound = Utils.findAssetBySymbol(selectedAccount.assets, showBalanceForAssetSymbol)
|
|
|
|
if (!assetFound) {
|
|
|
|
console.warn(qsTr("Cannot find asset '%1'. Ensure this asset has been added to the token list.").arg(showBalanceForAssetSymbol))
|
|
|
|
}
|
2020-08-20 04:45:29 +00:00
|
|
|
}
|
2020-09-01 03:49:05 +00:00
|
|
|
validate()
|
2020-08-20 04:45:29 +00:00
|
|
|
}
|
2020-07-30 05:18:54 +00:00
|
|
|
|
2020-09-01 03:49:05 +00:00
|
|
|
onAssetFoundChanged: {
|
|
|
|
if (!assetFound) {
|
|
|
|
return
|
2020-07-30 05:18:54 +00:00
|
|
|
}
|
2020-09-01 03:49:05 +00:00
|
|
|
txtAssetBalance.text = "Balance: " + (parseFloat(assetFound.value) === 0.0 ? "0" : Utils.stripTrailingZeros(assetFound.value)) + " " + assetFound.symbol
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: txtAssetBalance
|
|
|
|
visible: root.assetFound !== undefined
|
|
|
|
anchors.bottom: select.top
|
|
|
|
anchors.bottomMargin: -18
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
|
|
|
color: !root.isValid ? Style.current.danger : Style.current.secondaryText
|
|
|
|
font.pixelSize: 13
|
|
|
|
height: 18
|
2020-07-30 05:18:54 +00:00
|
|
|
}
|
|
|
|
Select {
|
|
|
|
id: select
|
|
|
|
label: root.label
|
|
|
|
model: root.accounts
|
2020-08-06 07:25:53 +00:00
|
|
|
menuAlignment: Select.MenuAlignment.Left
|
2020-07-30 05:18:54 +00:00
|
|
|
menu.delegate: menuItem
|
|
|
|
menu.onOpened: {
|
|
|
|
selectedAccountDetails.visible = false
|
|
|
|
}
|
|
|
|
menu.onClosed: {
|
2020-08-14 19:19:08 +00:00
|
|
|
selectedAccountDetails.visible = root.showAccountDetails
|
2020-07-30 05:18:54 +00:00
|
|
|
}
|
2020-08-06 07:25:53 +00:00
|
|
|
menu.width: dropdownWidth
|
2020-08-03 05:36:54 +00:00
|
|
|
selectedItemView: Item {
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
SVGImage {
|
|
|
|
id: selectedIconImg
|
|
|
|
sourceSize.height: 12
|
|
|
|
sourceSize.width: 12
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
source: "../app/img/walletIcon.svg"
|
|
|
|
}
|
|
|
|
ColorOverlay {
|
2020-08-20 04:45:29 +00:00
|
|
|
id: selectedIconImgOverlay
|
2020-08-03 05:36:54 +00:00
|
|
|
anchors.fill: selectedIconImg
|
|
|
|
source: selectedIconImg
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: selectedTextField
|
2020-08-14 19:19:08 +00:00
|
|
|
elide: Text.ElideRight
|
2020-08-03 05:36:54 +00:00
|
|
|
anchors.left: selectedIconImg.right
|
|
|
|
anchors.leftMargin: 8
|
2020-08-20 04:45:29 +00:00
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: select.selectedItemRightMargin
|
2020-08-03 05:36:54 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
font.pixelSize: 15
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
height: 22
|
|
|
|
}
|
|
|
|
}
|
2020-07-30 05:18:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Row {
|
|
|
|
id: selectedAccountDetails
|
2020-08-14 19:19:08 +00:00
|
|
|
visible: root.showAccountDetails
|
2020-07-30 05:18:54 +00:00
|
|
|
anchors.top: select.bottom
|
|
|
|
anchors.topMargin: 8
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: 2
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: textSelectedAddress
|
|
|
|
font.pixelSize: 12
|
|
|
|
elide: Text.ElideMiddle
|
|
|
|
height: 16
|
2020-08-06 07:25:53 +00:00
|
|
|
width: 90
|
2020-07-30 05:18:54 +00:00
|
|
|
color: Style.current.secondaryText
|
|
|
|
}
|
|
|
|
StyledText {
|
2020-08-20 04:45:29 +00:00
|
|
|
id: textSelectedAddressFiatBalance
|
2020-07-30 05:18:54 +00:00
|
|
|
font.pixelSize: 12
|
|
|
|
height: 16
|
|
|
|
color: Style.current.secondaryText
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: menuItem
|
|
|
|
MenuItem {
|
|
|
|
id: itemContainer
|
2020-09-10 21:48:16 +00:00
|
|
|
visible: walletType !== 'watch'
|
2020-07-30 05:18:54 +00:00
|
|
|
property bool isFirstItem: index === 0
|
|
|
|
property bool isLastItem: index === accounts.rowCount() - 1
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
2020-08-20 04:45:29 +00:00
|
|
|
if (!root.selectedAccount && isFirstItem) {
|
2020-07-30 05:18:54 +00:00
|
|
|
root.selectedAccount = { address, name, iconColor, assets, fiatBalance }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-10 21:48:16 +00:00
|
|
|
height: walletType === 'watch' ? 0 : (accountName.height + 14 + accountAddress.height + 14)
|
2020-07-30 05:18:54 +00:00
|
|
|
SVGImage {
|
|
|
|
id: iconImg
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2020-08-03 05:36:54 +00:00
|
|
|
width: 12
|
|
|
|
height: 12
|
|
|
|
sourceSize.height: height
|
|
|
|
sourceSize.width: width
|
2020-07-30 05:18:54 +00:00
|
|
|
fillMode: Image.PreserveAspectFit
|
2020-08-03 05:36:54 +00:00
|
|
|
source: "../app/img/walletIcon.svg"
|
2020-07-30 05:18:54 +00:00
|
|
|
}
|
|
|
|
ColorOverlay {
|
|
|
|
anchors.fill: iconImg
|
|
|
|
source: iconImg
|
|
|
|
color: iconColor
|
|
|
|
}
|
|
|
|
Column {
|
2020-08-14 19:19:08 +00:00
|
|
|
id: column
|
2020-07-30 05:18:54 +00:00
|
|
|
anchors.left: iconImg.right
|
|
|
|
anchors.leftMargin: 14
|
2020-08-13 08:24:51 +00:00
|
|
|
anchors.right: txtFiatBalance.left
|
|
|
|
anchors.rightMargin: 8
|
2020-07-30 05:18:54 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: accountName
|
|
|
|
text: name
|
2020-08-14 19:19:08 +00:00
|
|
|
elide: Text.ElideRight
|
2020-07-30 05:18:54 +00:00
|
|
|
font.pixelSize: 15
|
2020-08-13 08:24:51 +00:00
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
2020-07-30 05:18:54 +00:00
|
|
|
height: 22
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: accountAddress
|
|
|
|
text: address
|
|
|
|
elide: Text.ElideMiddle
|
|
|
|
width: 80
|
|
|
|
color: Style.current.secondaryText
|
|
|
|
font.pixelSize: 12
|
|
|
|
height: 16
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StyledText {
|
2020-08-13 08:24:51 +00:00
|
|
|
id: txtFiatBalance
|
2020-07-30 05:18:54 +00:00
|
|
|
anchors.right: fiatCurrencySymbol.left
|
|
|
|
anchors.rightMargin: 4
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
font.pixelSize: 15
|
|
|
|
height: 22
|
|
|
|
text: fiatBalance
|
|
|
|
}
|
|
|
|
StyledText {
|
|
|
|
id: fiatCurrencySymbol
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
font.pixelSize: 15
|
|
|
|
height: 22
|
|
|
|
color: Style.current.secondaryText
|
2020-08-06 02:33:30 +00:00
|
|
|
text: root.currency.toUpperCase()
|
2020-07-30 05:18:54 +00:00
|
|
|
}
|
|
|
|
background: Rectangle {
|
|
|
|
color: itemContainer.highlighted ? Style.current.backgroundHover : Style.current.background
|
|
|
|
radius: Style.current.radius
|
|
|
|
|
|
|
|
// cover bottom left/right corners with square corners
|
|
|
|
Rectangle {
|
|
|
|
visible: !isLastItem
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
height: parent.radius
|
|
|
|
color: parent.color
|
|
|
|
}
|
|
|
|
|
|
|
|
// cover top left/right corners with square corners
|
|
|
|
Rectangle {
|
|
|
|
visible: !isFirstItem
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.top: parent.top
|
|
|
|
height: parent.radius
|
|
|
|
color: parent.color
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MouseArea {
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
anchors.fill: itemContainer
|
|
|
|
onClicked: {
|
|
|
|
root.selectedAccount = { address, name, iconColor, assets, fiatBalance }
|
|
|
|
select.menu.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|