2020-08-06 07:25:53 +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
|
|
|
|
property var accounts
|
|
|
|
property var contacts
|
|
|
|
property int inputWidth: 272
|
|
|
|
property int sourceSelectWidth: 136
|
2020-08-12 03:40:25 +00:00
|
|
|
property alias label: txtLabel.text
|
|
|
|
// If supplied, additional info will be displayed top-right in danger colour (red)
|
|
|
|
property alias additionalInfo: txtAddlInfo.text
|
|
|
|
property var selectedRecipient: { }
|
|
|
|
property bool readOnly: false
|
|
|
|
height: (readOnly ? inpReadOnly.height : inpAddress.height) + txtLabel.height
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Invalid ethereum address"
|
|
|
|
readonly property string addressValidationError: qsTrId("invalid-ethereum-address")
|
2020-08-06 07:25:53 +00:00
|
|
|
|
2020-08-13 08:24:51 +00:00
|
|
|
enum Type {
|
|
|
|
Address,
|
|
|
|
Contact,
|
|
|
|
Account
|
|
|
|
}
|
|
|
|
|
2020-08-06 07:25:53 +00:00
|
|
|
function validate() {
|
2020-08-12 03:40:25 +00:00
|
|
|
let isValid = true
|
|
|
|
if (readOnly) {
|
|
|
|
isValid = Utils.isValidAddress(selectedRecipient.address)
|
|
|
|
if (!isValid) {
|
|
|
|
inpReadOnly.validationError = addressValidationError
|
|
|
|
}
|
|
|
|
} else if (selAddressSource.selectedSource === "Address") {
|
|
|
|
isValid = inpAddress.validate()
|
2020-08-06 07:25:53 +00:00
|
|
|
} else if (selAddressSource.selectedSource === "Contact") {
|
2020-08-12 03:40:25 +00:00
|
|
|
isValid = selContact.validate()
|
2020-08-06 07:25:53 +00:00
|
|
|
}
|
2020-08-12 03:40:25 +00:00
|
|
|
return isValid
|
2020-08-06 07:25:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: txtLabel
|
|
|
|
visible: label !== ""
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Recipient"
|
|
|
|
text: qsTrId("recipient")
|
2020-08-06 07:25:53 +00:00
|
|
|
font.pixelSize: 13
|
2020-08-12 03:40:25 +00:00
|
|
|
font.family: Style.current.fontRegular.name
|
|
|
|
font.weight: Font.Medium
|
2020-08-06 07:25:53 +00:00
|
|
|
color: Style.current.textColor
|
|
|
|
height: 18
|
|
|
|
}
|
|
|
|
|
2020-08-12 03:40:25 +00:00
|
|
|
Text {
|
|
|
|
id: txtAddlInfo
|
|
|
|
visible: text !== ""
|
|
|
|
text: ""
|
|
|
|
font.pixelSize: 13
|
|
|
|
font.family: Style.current.fontRegular.name
|
|
|
|
font.weight: Font.Medium
|
|
|
|
color: Style.current.danger
|
|
|
|
height: 18
|
|
|
|
anchors.right: parent.right
|
|
|
|
}
|
|
|
|
|
2020-08-06 07:25:53 +00:00
|
|
|
RowLayout {
|
|
|
|
anchors.top: txtLabel.bottom
|
|
|
|
anchors.topMargin: 7
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
spacing: 8
|
|
|
|
|
2020-08-12 03:40:25 +00:00
|
|
|
Input {
|
|
|
|
id: inpReadOnly
|
|
|
|
visible: root.readOnly
|
|
|
|
Layout.preferredWidth: selAddressSource.visible ? root.inputWidth : parent.width
|
|
|
|
Layout.alignment: Qt.AlignTop
|
|
|
|
Layout.fillWidth: true
|
|
|
|
anchors.left: undefined
|
|
|
|
anchors.right: undefined
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "No recipient selected"
|
|
|
|
text: (root.selectedRecipient && root.selectedRecipient.name) ? root.selectedRecipient.name : qsTrId("no-recipient-selected")
|
2020-08-12 03:40:25 +00:00
|
|
|
textField.leftPadding: 14
|
|
|
|
textField.topPadding: 18
|
|
|
|
textField.bottomPadding: 18
|
|
|
|
textField.verticalAlignment: TextField.AlignVCenter
|
|
|
|
textField.font.pixelSize: 15
|
|
|
|
textField.color: Style.current.secondaryText
|
|
|
|
textField.readOnly: true
|
|
|
|
validationErrorAlignment: TextEdit.AlignRight
|
|
|
|
validationErrorTopMargin: 8
|
|
|
|
customHeight: 56
|
|
|
|
}
|
|
|
|
|
2020-08-06 07:25:53 +00:00
|
|
|
AddressInput {
|
|
|
|
id: inpAddress
|
|
|
|
width: root.inputWidth
|
|
|
|
label: ""
|
2020-08-12 03:40:25 +00:00
|
|
|
visible: !root.readOnly
|
|
|
|
Layout.preferredWidth: selAddressSource.visible ? root.inputWidth : parent.width
|
2020-08-06 07:25:53 +00:00
|
|
|
Layout.alignment: Qt.AlignTop
|
|
|
|
Layout.fillWidth: true
|
2020-08-12 03:40:25 +00:00
|
|
|
validationError: root.addressValidationError
|
2020-08-06 07:25:53 +00:00
|
|
|
onSelectedAddressChanged: {
|
2020-08-12 03:40:25 +00:00
|
|
|
if (root.readOnly) {
|
|
|
|
return
|
|
|
|
}
|
2020-08-13 08:24:51 +00:00
|
|
|
root.selectedRecipient = { address: selectedAddress, type: RecipientSelector.Type.Address }
|
2020-08-06 07:25:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ContactSelector {
|
|
|
|
id: selContact
|
|
|
|
contacts: root.contacts
|
|
|
|
visible: false
|
|
|
|
width: root.inputWidth
|
|
|
|
dropdownWidth: parent.width
|
2020-08-12 03:40:25 +00:00
|
|
|
Layout.preferredWidth: selAddressSource.visible ? root.inputWidth : parent.width
|
2020-08-06 07:25:53 +00:00
|
|
|
Layout.alignment: Qt.AlignTop
|
|
|
|
Layout.fillWidth: true
|
|
|
|
onSelectedContactChanged: {
|
2020-08-12 03:40:25 +00:00
|
|
|
if (root.readOnly) {
|
|
|
|
return
|
|
|
|
}
|
2020-08-06 07:25:53 +00:00
|
|
|
if(selectedContact && selectedContact.address) {
|
2020-08-13 08:24:51 +00:00
|
|
|
const { address, name, alias, isContact, identicon, ensVerified } = selectedContact
|
|
|
|
root.selectedRecipient = { address, name, alias, isContact, identicon, ensVerified, type: RecipientSelector.Type.Contact }
|
2020-08-06 07:25:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AccountSelector {
|
|
|
|
id: selAccount
|
|
|
|
accounts: root.accounts
|
|
|
|
visible: false
|
|
|
|
width: root.inputWidth
|
|
|
|
dropdownWidth: parent.width
|
|
|
|
label: ""
|
2020-08-12 03:40:25 +00:00
|
|
|
Layout.preferredWidth: selAddressSource.visible ? root.inputWidth : parent.width
|
2020-08-06 07:25:53 +00:00
|
|
|
Layout.alignment: Qt.AlignTop
|
|
|
|
Layout.fillWidth: true
|
|
|
|
onSelectedAccountChanged: {
|
2020-08-12 03:40:25 +00:00
|
|
|
if (root.readOnly) {
|
|
|
|
return
|
|
|
|
}
|
2020-08-13 08:24:51 +00:00
|
|
|
const { address, name, iconColor, assets, fiatBalance } = selectedAccount
|
|
|
|
root.selectedRecipient = { address, name, iconColor, assets, fiatBalance, type: RecipientSelector.Type.Account }
|
2020-08-06 07:25:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
AddressSourceSelector {
|
|
|
|
id: selAddressSource
|
2020-08-12 03:40:25 +00:00
|
|
|
visible: !root.readOnly
|
2020-08-06 07:25:53 +00:00
|
|
|
sources: ["Address", "Contact", "My account"]
|
|
|
|
width: sourceSelectWidth
|
|
|
|
Layout.preferredWidth: root.sourceSelectWidth
|
|
|
|
Layout.alignment: Qt.AlignTop
|
|
|
|
|
|
|
|
onSelectedSourceChanged: {
|
2020-08-12 03:40:25 +00:00
|
|
|
if (root.readOnly) {
|
|
|
|
return
|
|
|
|
}
|
2020-08-13 08:24:51 +00:00
|
|
|
let address, name
|
2020-08-06 07:25:53 +00:00
|
|
|
switch (selectedSource) {
|
|
|
|
case "Address":
|
|
|
|
inpAddress.visible = true
|
|
|
|
selContact.visible = selAccount.visible = false
|
|
|
|
root.height = Qt.binding(function() { return inpAddress.height + txtLabel.height })
|
2020-08-13 08:24:51 +00:00
|
|
|
root.selectedRecipient = { address: inpAddress.selectedAddress, type: RecipientSelector.Type.Address }
|
2020-08-06 07:25:53 +00:00
|
|
|
break;
|
|
|
|
case "Contact":
|
|
|
|
selContact.visible = true
|
|
|
|
inpAddress.visible = selAccount.visible = false
|
|
|
|
root.height = Qt.binding(function() { return selContact.height + txtLabel.height })
|
2020-08-13 08:24:51 +00:00
|
|
|
let { alias, isContact, identicon, ensVerified } = selContact.selectedContact
|
|
|
|
address = selContact.selectedContact.address
|
|
|
|
name = selContact.selectedContact.name
|
|
|
|
root.selectedRecipient = { address, name, alias, isContact, identicon, ensVerified, type: RecipientSelector.Type.Contact }
|
2020-08-06 07:25:53 +00:00
|
|
|
break;
|
|
|
|
case "My account":
|
|
|
|
selAccount.visible = true
|
|
|
|
inpAddress.visible = selContact.visible = false
|
|
|
|
root.height = Qt.binding(function() { return selAccount.height + txtLabel.height })
|
2020-08-13 08:24:51 +00:00
|
|
|
const { iconColor, assets, fiatBalance } = selAccount.selectedAccount
|
|
|
|
address = selAccount.selectedAccount.address
|
|
|
|
name = selAccount.selectedAccount.name
|
|
|
|
root.selectedRecipient = { address, name, iconColor, assets, fiatBalance, type: RecipientSelector.Type.Account }
|
2020-08-06 07:25:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*##^##
|
|
|
|
Designer {
|
|
|
|
D{i:0;autoSize:true;height:480;width:640}
|
|
|
|
}
|
|
|
|
##^##*/
|