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"
|
2020-09-09 11:04:01 +00:00
|
|
|
import "../shared"
|
2020-08-06 07:25:53 +00:00
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
property string validationError: "Error"
|
2020-09-14 12:12:47 +00:00
|
|
|
//% "ENS Username not found"
|
|
|
|
property string ensAsyncValidationError: qsTrId("ens-username-not-found")
|
2020-08-06 07:25:53 +00:00
|
|
|
property alias label: inpAddress.label
|
2020-10-28 07:44:09 +00:00
|
|
|
property alias text: inpAddress.text
|
2020-08-06 07:25:53 +00:00
|
|
|
property string selectedAddress
|
2020-08-20 04:45:29 +00:00
|
|
|
property var isValid: false
|
2020-10-29 03:07:34 +00:00
|
|
|
property alias isPending: ensResolver.isPending
|
2020-10-28 07:44:09 +00:00
|
|
|
property alias readOnly: inpAddress.readOnly
|
|
|
|
property bool isResolvedAddress: false
|
2020-08-06 07:25:53 +00:00
|
|
|
|
|
|
|
height: inpAddress.height
|
|
|
|
|
2020-10-28 07:44:09 +00:00
|
|
|
onSelectedAddressChanged: validate()
|
2020-10-29 03:07:34 +00:00
|
|
|
onTextChanged: ensResolver.resolveEns(text)
|
2020-10-28 07:44:09 +00:00
|
|
|
|
2020-08-20 04:45:29 +00:00
|
|
|
function resetInternal() {
|
|
|
|
selectedAddress = ""
|
|
|
|
inpAddress.resetInternal()
|
|
|
|
metrics.text = ""
|
|
|
|
isValid = false
|
2020-10-28 07:44:09 +00:00
|
|
|
isPending = false
|
|
|
|
isResolvedAddress = false
|
|
|
|
}
|
|
|
|
|
|
|
|
function validate() {
|
|
|
|
let isValidEns = Utils.isValidEns(text)
|
|
|
|
let isValidAddress = Utils.isValidAddress(selectedAddress)
|
|
|
|
let isValid = (isValidEns && !isResolvedAddress) || isPending || isValidAddress
|
|
|
|
inpAddress.validationError = ""
|
|
|
|
if (!isValid){
|
|
|
|
inpAddress.validationError = isResolvedAddress ? ensAsyncValidationError : validationError
|
|
|
|
}
|
2020-08-20 04:45:29 +00:00
|
|
|
root.isValid = isValid
|
2020-08-06 07:25:53 +00:00
|
|
|
return isValid
|
|
|
|
}
|
|
|
|
|
|
|
|
Input {
|
|
|
|
id: inpAddress
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "eg. 0x1234 or ENS"
|
|
|
|
placeholderText: qsTrId("eg--0x1234-or-ens")
|
2020-08-06 07:25:53 +00:00
|
|
|
customHeight: 56
|
|
|
|
validationErrorAlignment: TextEdit.AlignRight
|
|
|
|
validationErrorTopMargin: 8
|
|
|
|
textField.onFocusChanged: {
|
|
|
|
let isValid = true
|
2020-10-28 07:44:09 +00:00
|
|
|
if (text !== "" && Utils.isValidAddress(metrics.text)) {
|
|
|
|
if (textField.focus) {
|
|
|
|
text = metrics.text
|
|
|
|
} else {
|
|
|
|
text = metrics.elidedText
|
|
|
|
}
|
2020-08-06 07:25:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
textField.rightPadding: 73
|
|
|
|
onTextEdited: {
|
|
|
|
metrics.text = text
|
2020-10-28 07:44:09 +00:00
|
|
|
|
2020-10-29 03:07:34 +00:00
|
|
|
ensResolver.resolveEns(text)
|
2020-10-28 07:44:09 +00:00
|
|
|
root.isResolvedAddress = false
|
|
|
|
root.selectedAddress = text
|
2020-08-06 07:25:53 +00:00
|
|
|
}
|
|
|
|
TextMetrics {
|
|
|
|
id: metrics
|
|
|
|
elideWidth: 97
|
|
|
|
elide: Text.ElideMiddle
|
|
|
|
}
|
|
|
|
TertiaryButton {
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: 8
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: 14
|
2020-10-28 07:44:09 +00:00
|
|
|
visible: !root.readOnly
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Paste"
|
|
|
|
label: qsTrId("paste")
|
2020-08-06 07:25:53 +00:00
|
|
|
onClicked: {
|
|
|
|
if (inpAddress.textField.canPaste) {
|
|
|
|
inpAddress.textField.paste()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-09 11:04:01 +00:00
|
|
|
|
2020-10-29 03:07:34 +00:00
|
|
|
EnsResolver {
|
|
|
|
id: ensResolver
|
2020-09-09 11:04:01 +00:00
|
|
|
anchors.top: inpAddress.bottom
|
|
|
|
anchors.right: inpAddress.right
|
|
|
|
anchors.topMargin: Style.current.halfPadding
|
2020-10-29 03:07:34 +00:00
|
|
|
onResolved: {
|
|
|
|
root.isResolvedAddress = true
|
|
|
|
root.selectedAddress = resolvedAddress
|
|
|
|
}
|
|
|
|
onIsPendingChanged: {
|
|
|
|
if (isPending) {
|
|
|
|
root.selectedAddress = ""
|
|
|
|
}
|
2020-09-09 11:04:01 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-06 07:25:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*##^##
|
|
|
|
Designer {
|
|
|
|
D{i:0;autoSize:true;height:480;width:640}
|
|
|
|
}
|
|
|
|
##^##*/
|