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
|
2021-04-22 04:03:46 +00:00
|
|
|
import QtQml.Models 2.14
|
2020-07-30 05:18:54 +00:00
|
|
|
import "../imports"
|
2021-04-20 16:10:04 +00:00
|
|
|
import "../shared"
|
|
|
|
import "../shared/status"
|
2020-07-30 05:18:54 +00:00
|
|
|
|
|
|
|
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-10-19 19:00:43 +00:00
|
|
|
property alias selectField: select
|
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
|
2020-10-28 07:44:09 +00:00
|
|
|
property bool readOnly: false
|
2020-08-20 04:45:29 +00:00
|
|
|
|
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) {
|
2021-04-13 15:06:15 +00:00
|
|
|
selectedIconImgOverlay.color = Utils.getCurrentThemeAccountColor(selectedAccount.iconColor) || Style.current.accountColors[0]
|
2020-08-20 04:45:29 +00:00
|
|
|
}
|
|
|
|
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) {
|
2020-09-14 12:12:47 +00:00
|
|
|
//% "Cannot find asset '%1'. Ensure this asset has been added to the token list."
|
|
|
|
console.warn(qsTrId("cannot-find-asset---1---ensure-this-asset-has-been-added-to-the-token-list-").arg(showBalanceForAssetSymbol))
|
2020-09-01 03:49:05 +00:00
|
|
|
}
|
2020-08-20 04:45:29 +00:00
|
|
|
}
|
2020-10-16 13:21:57 +00:00
|
|
|
if (!selectedAccount.type) {
|
|
|
|
selectedAccount.type = RecipientSelector.Type.Account
|
|
|
|
}
|
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
|
|
|
}
|
2021-07-16 20:22:50 +00:00
|
|
|
//% "Balance: "
|
|
|
|
txtAssetBalance.text = qsTrId("balance--") + (parseFloat(assetFound.value) === 0.0 ? "0" : Utils.stripTrailingZeros(assetFound.value))
|
2021-04-20 16:10:04 +00:00
|
|
|
txtAssetSymbol.text = " " + assetFound.symbol
|
2020-09-01 03:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: txtAssetBalance
|
|
|
|
visible: root.assetFound !== undefined
|
|
|
|
anchors.bottom: select.top
|
|
|
|
anchors.bottomMargin: -18
|
2021-04-20 16:10:04 +00:00
|
|
|
anchors.right: txtAssetSymbol.left
|
|
|
|
anchors.left: select.left
|
|
|
|
anchors.leftMargin: select.width / 2.5
|
2020-09-01 03:49:05 +00:00
|
|
|
|
|
|
|
color: !root.isValid ? Style.current.danger : Style.current.secondaryText
|
2021-04-20 16:10:04 +00:00
|
|
|
elide: Text.ElideRight
|
2020-09-01 03:49:05 +00:00
|
|
|
font.pixelSize: 13
|
2021-04-20 16:10:04 +00:00
|
|
|
horizontalAlignment: Text.AlignRight
|
2020-09-01 03:49:05 +00:00
|
|
|
height: 18
|
2021-04-20 16:10:04 +00:00
|
|
|
|
|
|
|
StatusToolTip {
|
|
|
|
enabled: txtAssetBalance.truncated
|
|
|
|
id: assetTooltip
|
|
|
|
text: txtAssetBalance.text
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
enabled: txtAssetBalance.truncated
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: enabled
|
|
|
|
onEntered: assetTooltip.visible = true
|
|
|
|
onExited: assetTooltip.visible = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
StyledText {
|
|
|
|
id: txtAssetSymbol
|
|
|
|
visible: txtAssetBalance.visible
|
|
|
|
anchors.top: txtAssetBalance.top
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
|
|
|
color: txtAssetBalance.color
|
|
|
|
font.pixelSize: 13
|
|
|
|
height: txtAssetBalance.height
|
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
|
2021-04-22 04:03:46 +00:00
|
|
|
visible: walletType !== Constants.watchWalletType
|
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 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-22 04:03:46 +00:00
|
|
|
height: walletType === Constants.watchWalletType ? 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
|
2021-04-13 15:06:15 +00:00
|
|
|
color: Utils.getCurrentThemeAccountColor(iconColor) || Style.current.accountColors[0]
|
2020-07-30 05:18:54 +00:00
|
|
|
}
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|